Skip to content

Commit

Permalink
Remove seasonal code, this can be done in a workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
katydecorah committed Jun 6, 2024
1 parent 6eab472 commit 6f230bf
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 196 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/spotify-seasonal.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Save seasonal or any playlist
name: Export playlists on a schedule

on:
# Run every three months on the 20th to get the seasonal playlist
Expand All @@ -21,10 +21,31 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set playlist name
run: |
MONTH=$(date +%m)
YEAR=$(date +%Y)
case $MONTH in
03)
echo "PLAYLIST_NAME=${YEAR}/$(($YEAR + 1)) Winter" >> $GITHUB_ENV
;;
06)
echo "PLAYLIST_NAME=${YEAR} Spring" >> $GITHUB_ENV
;;
09)
echo "PLAYLIST_NAME=${YEAR} Summer" >> $GITHUB_ENV
;;
12)
echo "PLAYLIST_NAME=${YEAR} Fall" >> $GITHUB_ENV
;;
esac
- name: Save the playlist
uses: ./
with:
spotify-username: "katydecorah"
# If the playlist name is provided, use it
# The workflow_dispatch input playlist-name takes precedence
playlist-name: ${{ env.PLAYLIST_NAME }}
env:
SpotifyClientID: ${{ secrets.SpotifyClientID }}
SpotifyClientSecret: ${{ secrets.SpotifyClientSecret}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/spotify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
playlist-name:
description: Your Spotify playlist name that you want to export. Required for non-seasonal playlist export.
description: Your Spotify playlist name that you want to export.
required: true
type: string

Expand Down
19 changes: 1 addition & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
# spotify-to-yaml-action

Export a Spotify playlist to Yaml.

This workflow can:

- Export your public Spotify playlist.
- [Example workflow](#set-up-the-workflow)
- Automatically export last season's playlists.
- [Seasonal set up](#seasonal-set-up)
- [Example seasonal workflow](#additional-example-workflows)
Export a Spotify playlist to YAML.

## Set up

Expand All @@ -17,15 +9,6 @@ To connect your Spotify account to this workflow, set the following [secrets to
- `SpotifyClientID`
- `SpotifyClientSecret`

## Seasonal set up

To take part in season playlist export, you will need to name your Spotify playlists with the following pattern: `YYYY {season}`. If you use different names for the seasons, you can use the `season-names` [action input](#action-options) to reflect that. Examples:

- `2021 Fall`
- `2021/2022 Winter`
- `2022 Spring`
- `2022 Summer`

<!-- START GENERATED DOCUMENTATION -->

## Set up the workflow
Expand Down
4 changes: 1 addition & 3 deletions src/__test__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { action } from "..";
import * as UpdateMain from "../write-file";
import * as core from "@actions/core";
import * as ListPlaylists from "../list-playlists";
import * as LearnPlaylistName from "../learn-playlist-name";
import { promises } from "fs";

jest.mock("@actions/core");
Expand Down Expand Up @@ -47,9 +46,9 @@ describe("action", () => {

test("works", async () => {
const mockDate = new Date(2021, 11);
defaultInputs["playlist-name"] = "2021 Fall";
jest.spyOn(global, "Date").mockImplementation(() => mockDate);

const learnPlaylistNameSpy = jest.spyOn(LearnPlaylistName, "default");
const listPlaylistsSpy = jest.spyOn(ListPlaylists, "default");
const updateMainSpy = jest.spyOn(UpdateMain, "default");
jest.spyOn(promises, "readFile").mockResolvedValue(`
Expand All @@ -59,7 +58,6 @@ describe("action", () => {
const exportVariableSpy = jest.spyOn(core, "exportVariable");

await action();
expect(learnPlaylistNameSpy).toHaveReturnedWith("2021 Fall");
const results = listPlaylistsSpy.mock.results[0].value;
await expect(results).resolves.toMatchSnapshot();
expect(exportVariableSpy).toHaveBeenNthCalledWith(
Expand Down
83 changes: 0 additions & 83 deletions src/__test__/learn-playlist-name.test.ts

This file was deleted.

13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import updateMain from "./write-file";
import { setFailed, exportVariable, getInput } from "@actions/core";
import learnPlaylistName from "./learn-playlist-name";
import listPlaylists from "./list-playlists";
import * as github from "@actions/github";

export type Playlist = {
name: string;
Expand All @@ -22,10 +22,17 @@ export type WorkflowPayload = {
export async function action() {
try {
const filename = getInput("filename");
const playlistName = learnPlaylistName();
const playlistName =
github?.context?.payload?.inputs?.payload?.["playlist-name"] ||
getInput("playlist-name");

if (!playlistName) {
throw new Error("Playlist name is required");
}

const playlist = await listPlaylists(playlistName);

// export image variable to be downloaded latter
// export image variable to be downloaded later
exportVariable("playlist", playlistName);
exportVariable("PlaylistImageOutput", `${playlist.formatted_name}.png`);
exportVariable("PlaylistImage", playlist.image);
Expand Down
87 changes: 0 additions & 87 deletions src/learn-playlist-name.ts

This file was deleted.

0 comments on commit 6f230bf

Please sign in to comment.