diff --git a/.github/workflows/scheduled-advanced.yml b/.github/workflows/scheduled-advanced.yml index b3b0132..a60abe6 100644 --- a/.github/workflows/scheduled-advanced.yml +++ b/.github/workflows/scheduled-advanced.yml @@ -1,6 +1,7 @@ name: Seasonal scheduled post on: + workflow_dispatch: schedule: - cron: "00 02 20 Mar,Jun,Sep,Dec *" @@ -11,30 +12,47 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Setpost title and date + - name: Set post title and dates run: | MONTH=$(date +%m) YEAR=$(date +%Y) + + declare -A SEASONS=( + ["03"]="Winter" + ["06"]="Spring" + ["09"]="Summer" + ["12"]="Fall" + ) + + set_env_vars() { + local season=$1 + local start_date=$2 + local end_date=$3 + local post_title="" + + if [ "$season" = "Winter" ]; then + post_title="$(($YEAR - 1))/${YEAR} ${season}" + else + post_title="${YEAR} ${season}" + fi + + echo "POST_TITLE=${post_title}" >> $GITHUB_ENV + echo "START_DATE=${start_date}" >> $GITHUB_ENV + echo "END_DATE=${end_date}" >> $GITHUB_ENV + } + case $MONTH in - 03) - echo "POST_TITLE=$(($YEAR - 1))/${YEAR} Winter" >> $GITHUB_ENV - echo "START_DATE=$(($YEAR - 1))-12-20" >> $GITHUB_ENV - echo "END_DATE=${YEAR}-03-20" >> $GITHUB_ENV + "03") + set_env_vars ${SEASONS[$MONTH]} "$(($YEAR - 1))-12-21" "${YEAR}-03-20" ;; - 06) - echo "POST_TITLE=${YEAR} Spring" >> $GITHUB_ENV - echo "START_DATE=${YEAR}-03-20" >> $GITHUB_ENV - echo "END_DATE=${YEAR}-06-20" >> $GITHUB_ENV + "06") + set_env_vars ${SEASONS[$MONTH]} "${YEAR}-03-21" "${YEAR}-06-20" ;; - 09) - echo "POST_TITLE=${YEAR} Summer" >> $GITHUB_ENV - echo "START_DATE=${YEAR}-06-20" >> $GITHUB_ENV - echo "END_DATE=${YEAR}-09-20" >> $GITHUB_ENV + "09") + set_env_vars ${SEASONS[$MONTH]} "${YEAR}-06-21" "${YEAR}-09-20" ;; - 12) - echo "POST_TITLE=${YEAR} Fall" >> $GITHUB_ENV - echo "START_DATE=${YEAR}-09-20" >> $GITHUB_ENV - echo "END_DATE=${YEAR}-12-20" >> $GITHUB_ENV + "12") + set_env_vars ${SEASONS[$MONTH]} "${YEAR}-09-21" "${YEAR}-12-20" ;; esac - name: Write scheduled post diff --git a/README.md b/README.md index b1bcdf4..f607738 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Scheduled post action -A GitHub action that creates a scheduled post from data files generated by [read-action](https://github.com/katydecorah/read-action), [bookmark-action](https://github.com/katydecorah/bookmark-action), and [spotify-to-yaml-action](https://github.com/katydecorah/spotify-to-yaml-action). +A GitHub action that creates a scheduled post from data files generated by [read-action](https://github.com/library-pals/read-action), [bookmark-action](https://github.com/library-pals/bookmark-action), and [spotify-to-yaml-action](https://github.com/library-pals/spotify-to-yaml-action). -If you're including playlist data generated by the spotify-to-yaml-action, you'll want to make sure it's schedule to run before this action. +If you're including playlist data generated by the spotify-to-yaml-action, make sure it's schedule to run before this action. @@ -30,7 +30,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Write scheduled post - uses: katydecorah/seasonal-post-action@v0.0.0 + uses: library-pals/scheduled-post-action@v0.0.0 with: github-username: katydecorah github-repository: archive @@ -55,8 +55,9 @@ jobs: name: Seasonal scheduled post on: + workflow_dispatch: schedule: - - cron: "00 02 20 Mar,Jun,Sep,Dec *" + - cron: "0 1 20 Mar,Jun,Sep,Dec *" jobs: scheduled-post: @@ -65,34 +66,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Setpost title and date - run: | - MONTH=$(date +%m) - YEAR=$(date +%Y) - case $MONTH in - 03) - echo "POST_TITLE=$(($YEAR - 1))/${YEAR} Winter" >> $GITHUB_ENV - echo "START_DATE=$(($YEAR - 1))-12-20" >> $GITHUB_ENV - echo "END_DATE=${YEAR}-03-20" >> $GITHUB_ENV - ;; - 06) - echo "POST_TITLE=${YEAR} Spring" >> $GITHUB_ENV - echo "START_DATE=${YEAR}-03-20" >> $GITHUB_ENV - echo "END_DATE=${YEAR}-06-20" >> $GITHUB_ENV - ;; - 09) - echo "POST_TITLE=${YEAR} Summer" >> $GITHUB_ENV - echo "START_DATE=${YEAR}-06-20" >> $GITHUB_ENV - echo "END_DATE=${YEAR}-09-20" >> $GITHUB_ENV - ;; - 12) - echo "POST_TITLE=${YEAR} Fall" >> $GITHUB_ENV - echo "START_DATE=${YEAR}-09-20" >> $GITHUB_ENV - echo "END_DATE=${YEAR}-12-20" >> $GITHUB_ENV - ;; - esac + - name: Set post title and dates + uses: library-pals/scheduled-post-action@v0.0.0.github/workflows/set-seasonal-dates.js - name: Write scheduled post - uses: katydecorah/seasonal-post-action@v0.0.0 + uses: ./ with: github-username: katydecorah github-repository: archive @@ -144,7 +121,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Write scheduled post - uses: katydecorah/seasonal-post-action@v0.0.0 + uses: library-pals/scheduled-post-action@v0.0.0 with: github-username: katydecorah github-repository: archive @@ -181,4 +158,10 @@ jobs: - `source-playlist`: Define the file path for the playlist data generated by [spotify-to-yaml-action](https://github.com/katydecorah/spotify-to-yaml-action). If you do not have playlists, set this value to `false`. Default: `_data/playlists.yml`. - `book-tags`: Allow specific tags to be passed through. Separate each tag with a comma. + +- `start-date`: The start date for the post. The format is `YYYY-MM-DD`. This can be set as an action input or workflow input. + +- `end-date`: The end date for the post. The format is `YYYY-MM-DD`. This can be set as an action input or workflow input. + +- `post-title`: The title of the post. This can be set as an action input or workflow input. diff --git a/action.yml b/action.yml index 007cf54..a2edaa6 100644 --- a/action.yml +++ b/action.yml @@ -35,3 +35,12 @@ inputs: book-tags: description: "Allow specific tags to be passed through. Separate each tag with a comma." + + start-date: + description: "The start date for the post. The format is `YYYY-MM-DD`. This can be set as an action input or workflow input." + + end-date: + description: "The end date for the post. The format is `YYYY-MM-DD`. This can be set as an action input or workflow input." + + post-title: + description: "The title of the post. This can be set as an action input or workflow input." diff --git a/dist/index.js b/dist/index.js index ce507fe..5a8f6d1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -51008,7 +51008,9 @@ function action() { return action_awaiter(this, void 0, void 0, function* () { try { const payload = github.context.payload.inputs; - const { "post-title": title, "start-date": startDate, "end-date": endDate, } = payload; + const title = (payload === null || payload === void 0 ? void 0 : payload["post-title"]) || (0,core.getInput)("post-title"); + const startDate = (payload === null || payload === void 0 ? void 0 : payload["start-date"]) || (0,core.getInput)("start-date"); + const endDate = (payload === null || payload === void 0 ? void 0 : payload["end-date"]) || (0,core.getInput)("end-date"); validateInputs(title, startDate, endDate); const slugifyTitle = title.toLowerCase().replace(/\s/g, "-"); const image = `${slugifyTitle}.png`; diff --git a/src/__tests__/__snapshots__/action.test.ts.snap b/src/__tests__/__snapshots__/action.test.ts.snap index 6d72754..41dbf8c 100644 --- a/src/__tests__/__snapshots__/action.test.ts.snap +++ b/src/__tests__/__snapshots__/action.test.ts.snap @@ -249,6 +249,255 @@ The books I read, playlist I made, and bookmarks I saved during 2021 Summer. ] `; +exports[`action works, action inputs 1`] = ` +[ + "notes/_posts/2021-09-20-2021-summer.md", + "--- +title: 2021 Summer +image: 2021-summer.png +books: + - title: How to Talk So Little Kids Will Listen + authors: Joanna Faber, Julie King + url: >- + https://books.google.com/books/about/How_to_Talk_So_Little_Kids_Will_Listen.html?hl=&id=6WfUDQAAQBAJ + isbn: '9781501131653' + - title: Between the World and Me + authors: Ta-Nehisi Coates + url: https://play.google.com/store/books/details?id=TV05BgAAQBAJ + isbn: '9780679645986' + tags: + - recommend + - title: The Power of Ritual + authors: Casper ter Kuile + url: https://play.google.com/store/books/details?id=il6xDwAAQBAJ + isbn: '9780062882066' + - title: Tell the Machine Goodnight + authors: Katie Williams + url: >- + https://books.google.com/books/about/Tell_the_Machine_Goodnight.html?hl=&id=Tq6ZDwAAQBAJ + isbn: '9780525533139' + tags: + - recommend + - title: Yearbook + authors: Seth Rogen + url: https://books.google.com/books/about/Yearbook.html?hl=&id=t-0qwwEACAAJ + isbn: '9780751575774' + - title: All Adults Here + authors: Emma Straub + url: >- + https://books.google.com/books/about/All_Adults_Here.html?hl=&id=SQcmEAAAQBAJ + isbn: '9781594634703' + - title: The Wedding Date + authors: Jasmine Guillory + url: >- + https://books.google.com/books/about/The_Wedding_Date.html?hl=&id=ugGWDwAAQBAJ + isbn: '9780593098394' + - title: The Lamplighters + authors: Emma Stonex + url: https://play.google.com/store/books/details?id=FE32DwAAQBAJ + isbn: '9781984882165' + - title: Crying in H Mart + authors: Michelle Zauner + url: https://play.google.com/store/books/details?id=kRjzDwAAQBAJ + isbn: '9780525657750' + tags: + - recommend + - title: A Thousand Ships + authors: Natalie Haynes + url: https://play.google.com/store/books/details?id=mrHmDwAAQBAJ + isbn: '9780063065413' + tags: + - recommend + - title: The Divines + authors: Ellie Eaton + url: https://play.google.com/store/books/details?id=U2XbDwAAQBAJ + isbn: '9780063012219' + - title: Conversations with Friends + authors: Sally Rooney + url: >- + https://books.google.com/books/about/Conversations_with_Friends.html?hl=&id=4ZQnDwAAQBAJ + isbn: '9780451499059' + - title: 'The Five Wounds: A Novel' + authors: Kirstin Valdez Quade + url: https://play.google.com/store/books/details?id=QjXtDwAAQBAJ + isbn: '9780393242843' + tags: + - recommend + - title: The Secret Lives of Church Ladies + authors: Deesha Philyaw + url: >- + https://books.google.com/books/about/The_Secret_Lives_of_Church_Ladies.html?hl=&id=RalczQEACAAJ + isbn: '9781949199734' + tags: + - recommend + - title: Mexican Gothic + authors: Silvia Moreno-Garcia + url: https://play.google.com/store/books/details?id=ksKyDwAAQBAJ + isbn: '9780525620792' + tags: + - recommend + - title: Exciting Times + authors: Naoise Dolan + url: https://play.google.com/store/books/details?id=aa6sDwAAQBAJ + isbn: '9780062968777' + - title: The Argonauts + authors: Maggie Nelson + url: https://play.google.com/store/books/details?id=F4QkBQAAQBAJ + isbn: '9781555973407' + +bookmarks: + - title: Quinoa Salad With Chicken, Almonds and Avocado Recipe + site: NYT Cooking + url: >- + https://cooking.nytimes.com/recipes/1019495-quinoa-salad-with-chicken-almonds-and-avocado + - title: Mahi ba Somagh (Sumac Roasted Fish) Recipe + site: NYT Cooking + url: >- + https://cooking.nytimes.com/recipes/1022268-mahi-ba-somagh-sumac-roasted-fish + - title: Rice Krispies Treats With Chocolate and Pretzels Recipe + site: NYT Cooking + url: >- + https://cooking.nytimes.com/recipes/1019978-rice-krispies-treats-with-chocolate-and-pretzels + - title: Grilled Za’atar Chicken With Garlic Yogurt and Cilantro Recipe + site: NYT Cooking + url: >- + https://cooking.nytimes.com/recipes/1022300-grilled-zaatar-chicken-with-garlic-yogurt-and-cilantro + - title: Crispy Baked Fish With Tartar Sauce Recipe + site: NYT Cooking + url: >- + https://cooking.nytimes.com/recipes/1022325-crispy-baked-fish-with-tartar-sauce + - title: Kimchi Tuna Salad Recipe + site: NYT Cooking + url: https://cooking.nytimes.com/recipes/1022166-kimchi-tuna-salad + - title: No-Bake Chocolate Mousse Bars Recipe + site: NYT Cooking + url: https://cooking.nytimes.com/recipes/1019316-no-bake-chocolate-mousse-bars + - title: Grilled Chicken With Parsley-Olive Sauce Recipe + site: NYT Cooking + url: >- + https://cooking.nytimes.com/recipes/1022335-grilled-chicken-with-parsley-olive-sauce + - title: Cherry-Almond Granola Crisp Recipe + site: NYT Cooking + url: https://cooking.nytimes.com/recipes/1021317-cherry-almond-granola-crisp + - title: Grilled Baby Back Ribs Recipe + site: NYT Cooking + url: https://cooking.nytimes.com/recipes/1017535-grilled-baby-back-ribs + - title: Todd Richards’s Fried Catfish With Hot Sauce Recipe + site: NYT Cooking + url: >- + https://cooking.nytimes.com/recipes/1019524-todd-richardss-fried-catfish-with-hot-sauce + - title: Affogato Recipe + site: NYT Cooking + url: https://cooking.nytimes.com/recipes/1022454-affogato + - title: Sweet or Salty Lemonade Recipe + site: NYT Cooking + url: https://cooking.nytimes.com/recipes/8703-sweet-or-salty-lemonade + - title: Plum and Raspberry Cornmeal Crisp Recipe + site: NYT Cooking + url: >- + https://cooking.nytimes.com/recipes/1022304-plum-and-raspberry-cornmeal-crisp + - title: Coffee-Praline Crunch Ice Cream Cake Recipe + site: NYT Cooking + url: >- + https://cooking.nytimes.com/recipes/1022469-coffee-praline-crunch-ice-cream-cake + - title: Everything-Bagel Smoked Salmon Dip Recipe + site: NYT Cooking + url: >- + https://cooking.nytimes.com/recipes/1022447-everything-bagel-smoked-salmon-dip + +playlist: 2021 Summer +spotify: https://open.spotify.com/playlist/5CWFqwcSoRK7AFfWH4nJyL +tracks: + - track: Kill Me + artist: Indigo De Souza + album: Kill Me + - track: In Your Eyes (Reflection) + artist: Anjimile, Jay Som + album: Reunion + - track: Floating + artist: Lealani + album: Fantastic Planet + - track: Creature of Mine + artist: Billie Marten + album: Flora Fauna + - track: Take Care of Yourself + artist: The Childlike Empress + album: Take Care of Yourself + - track: Turned Out I Was Everyone + artist: SASAMI + album: SASAMI + - track: Schatze + artist: Ohtis, Stef Chura + album: Schatze b/w Failure + - track: Lake Song + artist: Deeper + album: Auto-Pain + - track: Lavender + artist: Biig Piig + album: Lavender + - track: Holy Holy - Demo + artist: Wye Oak + album: Holy Holy (Demo) + +--- + +The books I read, playlist I made, and bookmarks I saved during 2021 Summer. + +## Books + +- [How to Talk So Little Kids Will Listen](https://books.google.com/books/about/How_to_Talk_So_Little_Kids_Will_Listen.html?hl=&id=6WfUDQAAQBAJ) - Joanna Faber, Julie King +- [Between the World and Me](https://play.google.com/store/books/details?id=TV05BgAAQBAJ) - Ta-Nehisi Coates (recommend) +- [The Power of Ritual](https://play.google.com/store/books/details?id=il6xDwAAQBAJ) - Casper ter Kuile +- [Tell the Machine Goodnight](https://books.google.com/books/about/Tell_the_Machine_Goodnight.html?hl=&id=Tq6ZDwAAQBAJ) - Katie Williams (recommend) +- [Yearbook](https://books.google.com/books/about/Yearbook.html?hl=&id=t-0qwwEACAAJ) - Seth Rogen +- [All Adults Here](https://books.google.com/books/about/All_Adults_Here.html?hl=&id=SQcmEAAAQBAJ) - Emma Straub +- [The Wedding Date](https://books.google.com/books/about/The_Wedding_Date.html?hl=&id=ugGWDwAAQBAJ) - Jasmine Guillory +- [The Lamplighters](https://play.google.com/store/books/details?id=FE32DwAAQBAJ) - Emma Stonex +- [Crying in H Mart](https://play.google.com/store/books/details?id=kRjzDwAAQBAJ) - Michelle Zauner (recommend) +- [A Thousand Ships](https://play.google.com/store/books/details?id=mrHmDwAAQBAJ) - Natalie Haynes (recommend) +- [The Divines](https://play.google.com/store/books/details?id=U2XbDwAAQBAJ) - Ellie Eaton +- [Conversations with Friends](https://books.google.com/books/about/Conversations_with_Friends.html?hl=&id=4ZQnDwAAQBAJ) - Sally Rooney +- [The Five Wounds: A Novel](https://play.google.com/store/books/details?id=QjXtDwAAQBAJ) - Kirstin Valdez Quade (recommend) +- [The Secret Lives of Church Ladies](https://books.google.com/books/about/The_Secret_Lives_of_Church_Ladies.html?hl=&id=RalczQEACAAJ) - Deesha Philyaw (recommend) +- [Mexican Gothic](https://play.google.com/store/books/details?id=ksKyDwAAQBAJ) - Silvia Moreno-Garcia (recommend) +- [Exciting Times](https://play.google.com/store/books/details?id=aa6sDwAAQBAJ) - Naoise Dolan +- [The Argonauts](https://play.google.com/store/books/details?id=F4QkBQAAQBAJ) - Maggie Nelson + +## Playlist + +- Kill Me - Indigo De Souza +- In Your Eyes (Reflection) - Anjimile, Jay Som +- Floating - Lealani +- Creature of Mine - Billie Marten +- Take Care of Yourself - The Childlike Empress +- Turned Out I Was Everyone - SASAMI +- Schatze - Ohtis, Stef Chura +- Lake Song - Deeper +- Lavender - Biig Piig +- Holy Holy - Demo - Wye Oak + +## Bookmarks + +- [Quinoa Salad With Chicken, Almonds and Avocado Recipe](https://cooking.nytimes.com/recipes/1019495-quinoa-salad-with-chicken-almonds-and-avocado) - NYT Cooking +- [Mahi ba Somagh (Sumac Roasted Fish) Recipe](https://cooking.nytimes.com/recipes/1022268-mahi-ba-somagh-sumac-roasted-fish) - NYT Cooking +- [Rice Krispies Treats With Chocolate and Pretzels Recipe](https://cooking.nytimes.com/recipes/1019978-rice-krispies-treats-with-chocolate-and-pretzels) - NYT Cooking +- [Grilled Za’atar Chicken With Garlic Yogurt and Cilantro Recipe](https://cooking.nytimes.com/recipes/1022300-grilled-zaatar-chicken-with-garlic-yogurt-and-cilantro) - NYT Cooking +- [Crispy Baked Fish With Tartar Sauce Recipe](https://cooking.nytimes.com/recipes/1022325-crispy-baked-fish-with-tartar-sauce) - NYT Cooking +- [Kimchi Tuna Salad Recipe](https://cooking.nytimes.com/recipes/1022166-kimchi-tuna-salad) - NYT Cooking +- [No-Bake Chocolate Mousse Bars Recipe](https://cooking.nytimes.com/recipes/1019316-no-bake-chocolate-mousse-bars) - NYT Cooking +- [Grilled Chicken With Parsley-Olive Sauce Recipe](https://cooking.nytimes.com/recipes/1022335-grilled-chicken-with-parsley-olive-sauce) - NYT Cooking +- [Cherry-Almond Granola Crisp Recipe](https://cooking.nytimes.com/recipes/1021317-cherry-almond-granola-crisp) - NYT Cooking +- [Grilled Baby Back Ribs Recipe](https://cooking.nytimes.com/recipes/1017535-grilled-baby-back-ribs) - NYT Cooking +- [Todd Richards’s Fried Catfish With Hot Sauce Recipe](https://cooking.nytimes.com/recipes/1019524-todd-richardss-fried-catfish-with-hot-sauce) - NYT Cooking +- [Affogato Recipe](https://cooking.nytimes.com/recipes/1022454-affogato) - NYT Cooking +- [Sweet or Salty Lemonade Recipe](https://cooking.nytimes.com/recipes/8703-sweet-or-salty-lemonade) - NYT Cooking +- [Plum and Raspberry Cornmeal Crisp Recipe](https://cooking.nytimes.com/recipes/1022304-plum-and-raspberry-cornmeal-crisp) - NYT Cooking +- [Coffee-Praline Crunch Ice Cream Cake Recipe](https://cooking.nytimes.com/recipes/1022469-coffee-praline-crunch-ice-cream-cake) - NYT Cooking +- [Everything-Bagel Smoked Salmon Dip Recipe](https://cooking.nytimes.com/recipes/1022447-everything-bagel-smoked-salmon-dip) - NYT Cooking +", +] +`; + exports[`action works, custom template 1`] = ` [ "notes/_posts/2021-09-20-2021-summer.md", diff --git a/src/__tests__/action.test.ts b/src/__tests__/action.test.ts index d0b5370..3b6a9e3 100644 --- a/src/__tests__/action.test.ts +++ b/src/__tests__/action.test.ts @@ -12,18 +12,19 @@ import * as github from "@actions/github"; jest.mock("@actions/core"); -const defaultInputs = { - "github-username": "katydecorah", - "github-repository": "archive", - "posts-directory": "notes/_posts/", - "post-template": "", - "source-books": "books|_data/read.json", - "source-bookmarks": "bookmarks|_data/bookmarks.json", - "source-playlist": "_data/playlists.yml", - "book-tags": "recommend, skip", -}; +let defaultInputs; beforeEach(() => { + defaultInputs = { + "github-username": "katydecorah", + "github-repository": "archive", + "posts-directory": "notes/_posts/", + "post-template": "", + "source-books": "books|_data/read.json", + "source-bookmarks": "bookmarks|_data/bookmarks.json", + "source-playlist": "_data/playlists.yml", + "book-tags": "recommend, skip", + }; Object.defineProperty(github, "context", { value: { payload: { @@ -35,6 +36,7 @@ beforeEach(() => { }, }, }); + jest .spyOn(core, "getInput") .mockImplementation((name) => defaultInputs[name] || undefined); @@ -183,6 +185,43 @@ describe("action", () => { expect(setFailed).not.toHaveBeenCalled(); expect(writeSpy.mock.calls[0]).toMatchSnapshot(); }); + + test("works, action inputs", async () => { + Object.defineProperty(github, "context", { + value: { + payload: {}, + }, + }); + + defaultInputs["post-title"] = "2021 Summer"; + defaultInputs["start-date"] = "2021-06-21"; + defaultInputs["end-date"] = "2021-09-20"; + const warningSpy = jest.spyOn(core, "warning").mockImplementation(); + + const getJsonFileSpy = jest + .spyOn(GetJsonFile, "getJsonFile") + .mockReturnValueOnce(books) + .mockReturnValueOnce(recipes); + const getDataFileSpy = jest + .spyOn(GetDataFile, "getDataFile") + .mockReturnValueOnce(playlists); + const formatBooksSpy = jest.spyOn(Format, "formatBooks"); + const formatBookmarksSpy = jest.spyOn(Format, "formatBookmarks"); + const formatPlaylistsSpy = jest.spyOn(Format, "formatPlaylist"); + const writeSpy = jest.spyOn(promises, "writeFile").mockImplementation(); + await action(); + + expect(warningSpy).not.toHaveBeenCalled(); + expect(getJsonFileSpy).toHaveBeenNthCalledWith(1, "_data/read.json"); + expect(getJsonFileSpy).toHaveNthReturnedWith(1, books); + expect(getJsonFileSpy).toHaveBeenNthCalledWith(2, "_data/bookmarks.json"); + expect(getDataFileSpy).toHaveBeenNthCalledWith(1, "_data/playlists.yml"); + expect(setFailed).not.toHaveBeenCalled(); + expect(formatBooksSpy).toHaveBeenCalled(); + expect(formatBookmarksSpy).toHaveBeenCalled(); + expect(formatPlaylistsSpy).toHaveBeenCalled(); + expect(writeSpy.mock.calls[0]).toMatchSnapshot(); + }); }); describe("validateInputs", () => { diff --git a/src/action.ts b/src/action.ts index 125d8c7..fc27c6b 100644 --- a/src/action.ts +++ b/src/action.ts @@ -10,11 +10,10 @@ import * as github from "@actions/github"; export async function action() { try { const payload = github.context.payload.inputs; - const { - "post-title": title, - "start-date": startDate, - "end-date": endDate, - } = payload; + + const title = payload?.["post-title"] || getInput("post-title"); + const startDate = payload?.["start-date"] || getInput("start-date"); + const endDate = payload?.["end-date"] || getInput("end-date"); validateInputs(title, startDate, endDate);