From bda66b12c37c6f9991c753daa578cc91cfff3e6c Mon Sep 17 00:00:00 2001 From: Tsung-Ju Lii Date: Tue, 25 Mar 2025 12:05:59 +0800 Subject: [PATCH] feat: move `pull-album-info` to repo root Signed-off-by: Tsung-Ju Lii --- .github/workflows/create_album_post.yaml | 48 +++++------------- .gitignore | 1 - dist-newstyle/cache/config | Bin 3630 -> 0 bytes .../pull_album_info/.gitignore | 0 .../pull_album_info/app/Main.hs | 24 +++++---- .../pull_album_info/app/templates/post.md | 0 .../pull_album_info/hie.yaml | 0 .../pull_album_info/pull-album-info.cabal | 3 +- stack.yaml | 5 +- stack.yaml.lock | 7 +++ 10 files changed, 37 insertions(+), 51 deletions(-) delete mode 100644 dist-newstyle/cache/config rename {.github/scripts => scripts}/pull_album_info/.gitignore (100%) rename {.github/scripts => scripts}/pull_album_info/app/Main.hs (92%) rename {.github/scripts => scripts}/pull_album_info/app/templates/post.md (100%) rename {.github/scripts => scripts}/pull_album_info/hie.yaml (100%) rename {.github/scripts => scripts}/pull_album_info/pull-album-info.cabal (97%) diff --git a/.github/workflows/create_album_post.yaml b/.github/workflows/create_album_post.yaml index 6c2709f..e8bcf5b 100644 --- a/.github/workflows/create_album_post.yaml +++ b/.github/workflows/create_album_post.yaml @@ -21,47 +21,23 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 - - - name: Cache Haskell dependencies - uses: actions/cache@v4 - with: - path: | - ~/.ghcup - ~/.cabal/store - .github/scripts/pull_album_info/dist-newstyle - key: haskell-cache-${{ runner.os }}-${{ hashFiles('.github/scripts/pull_album_info/**') }} - restore-keys: | - haskell-cache-${{ runner.os }}- - - - name: Setup Haskell - uses: haskell-actions/setup@v2.7.10 + + - id: stack + uses: freckle/stack-action@v5 with: - ghc-version: 9.4.8 - - - name: Build - run: | - cd .github/scripts/pull_album_info - - # Build the app - cabal build - - - name: Set branch name - id: set_name - run: | - BRANCH_NAME=$(echo "${{ github.event.inputs.album_title }}-${{ github.event.inputs.artist_name }}" | tr '[:upper:]' '[:lower:]' | tr -cd 'a-z0-9-') - echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT + stack-build-arguments: --fast # No pedantic for now - name: Run + id: run run: | - cd .github/scripts/pull_album_info - - BRANCH_NAME=${{ steps.set_name.outputs.branch_name }} - cabal run pull-album-info "${{ github.event.inputs.artist_name }}" "${{ github.event.inputs.album_title }}" $BRANCH_NAME - mv $BRANCH_NAME ${{ github.workspace }}/drafts/$BRANCH_NAME + BRANCH_NAME=$(echo "${{ github.event.inputs.album_title }}-${{ github.event.inputs.artist_name }}" | tr '[:upper:]' '[:lower:]' | tr -cd 'a-z0-9-') + stack exec pull-album-info "${{ github.event.inputs.artist_name }}" "${{ github.event.inputs.album_title }}" $BRANCH_NAME # Switch to bot account git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' + + echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT env: DISCOG_KEY: ${{ secrets.DISCOG_KEY }} DISCOG_SECRET: ${{ secrets.DISCOG_SECRET }} @@ -71,8 +47,8 @@ jobs: uses: peter-evans/create-pull-request@v7 with: token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ steps.set_name.outputs.branch_name }} + branch: ${{ steps.run.outputs.branch_name }} base: main - title: post/${{ steps.set_name.outputs.branch_name }} - body-path: '${{ github.workspace }}/drafts/${{ steps.set_name.outputs.branch_name }}' + title: post/${{ steps.run.outputs.branch_name }} + body-path: '${{ github.workspace }}/drafts/${{ steps.run.outputs.branch_name }}' labels: 'post' diff --git a/.gitignore b/.gitignore index bcd3d8b..308bc1a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ _cache/ dist-newstyle/ .env -fillin-release-dates/ diff --git a/dist-newstyle/cache/config b/dist-newstyle/cache/config deleted file mode 100644 index fb5a47aeffb203725b624465a8b5e8fc1b920fa7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3630 zcmd5<&x_nt98YFvc6Yk$uC|J8Q7Ix=giZ32yqCmN6~sTllNKrO=ghd-$&ks^wxD89 zf@lvOq)>_{&*DMEgLn|cvw9Fu-mD-L6$?_(mrTByx3jaWE3P_+eBb+iKi|*yN4|N< ztbg{)wO_x#aqGKlkA3y&o%kDT`s=h>^=i{`cP?*@2ZeMvWi)Ns-(KezuHJs7wx7BB z^!Z~S-B|nFdh^HV)Z4vtuU>!uhwhod$EQE+KKa^j7av^$rsv##wjeJRVg z-N{(0NlMdRmJf>lj?>fE33CS70hTHYXOw3zN?tf=#%bDVVmyBoF;p()6*&v?>=6W+ zHT?80_G!~yo(+oJ@7+)Cd;Ryj@txJy&u?W{HXnNG%dc@tTS{CS*r{T(5eDmz^ojG^g0o-5pSl=}|ki`KN){vvI&nF{yX70Mk5#}P-H{OZ9wUOOuk&gI%wN}WAD@nDW13$8bWRUykk%t}EiTVE z-ND}2Ws^ZF^a0bWu#JQ92w4vO?ypk*2zVnGD6AJ(C(RpG7sHM4VlJokgIkF zit4x`STGZhIINx zF?s@k;D3MvKx`LQAe;J^Yt1<&g8*UACmxACUrEXlmKcR1VTq)1prni$QA(-^1pyAD zg!+=iA`YqGgn7V&Buy9%e2#r05a$V^OcOB?kWg|g6B%SzYtURQ!!iWX|6@o^RV9dCuJmwLE8KtrGBcwvEb3@Wc0(daet^~2f zBOXEw`f1SLt}`v?Wp4+-@W6?+jUI|;)2?gcW8fk)eANL0W`fGCwH3<4JGJQ7MciJ1sd zBpKG73%yu*Bn$-SUKHU-NiMMu{aI?ppt+USsYL@nF0x$K!5dLJ1HtCI)dsdRLxl!4 z$V$2JV$3$!wF;K|NyDqg8ZOmxiZIe@+iSq4pSu&VZkI;}Y+5tSRNpoT0QBe5$PU1V ztjS=QTLR%evT5B){Vp#HDBu6hDYVD157QB Template SourcePos getTemplate content = either (error . show) id . runIdentity $ parseGinger nullResolver Nothing content -templatePath :: IO String -templatePath = do - progName <- getProgName - return $ takeDirectory progName ++ "/app/templates/post.md" +templatePath :: String +templatePath = "scripts/pull_album_info/app/templates/post.md" + +getDraftPath :: String -> String +getDraftPath fileName = "drafts/" ++ fileName runGenAlbumPost :: String -> String -> IO String runGenAlbumPost artistName albumName = do release <- getReleaseId artistName albumName >>= getRelease - content <- templatePath >>= readFile + content <- readFile templatePath return $ T.unpack . easyRender release $ getTemplate content -- Main function @@ -165,10 +165,12 @@ main = do [artistName, albumName, branchName] -> do result <- try $ runGenAlbumPost artistName albumName :: IO (Either SomeException String) post <- case result of - Left _ -> do - _ <- putStrLn "Cannot get album info from Discog, falling back to default post template" - templatePath >>= readFile + Left ex -> do + print ex + putStrLn "Cannot get album info from Discog, falling back to default post template" + readFile templatePath Right output -> return output - writeFile branchName post + let targetName = getDraftPath branchName + writeFile targetName post putStrLn "done" _ -> putStrLn "Usage: pull_album_info " diff --git a/.github/scripts/pull_album_info/app/templates/post.md b/scripts/pull_album_info/app/templates/post.md similarity index 100% rename from .github/scripts/pull_album_info/app/templates/post.md rename to scripts/pull_album_info/app/templates/post.md diff --git a/.github/scripts/pull_album_info/hie.yaml b/scripts/pull_album_info/hie.yaml similarity index 100% rename from .github/scripts/pull_album_info/hie.yaml rename to scripts/pull_album_info/hie.yaml diff --git a/.github/scripts/pull_album_info/pull-album-info.cabal b/scripts/pull_album_info/pull-album-info.cabal similarity index 97% rename from .github/scripts/pull_album_info/pull-album-info.cabal rename to scripts/pull_album_info/pull-album-info.cabal index d192d26..618c4c0 100644 --- a/.github/scripts/pull_album_info/pull-album-info.cabal +++ b/scripts/pull_album_info/pull-album-info.cabal @@ -71,8 +71,7 @@ executable pull-album-info lens-aeson, lens, ginger, - text, - filepath + text -- Directories containing source files. hs-source-dirs: app diff --git a/stack.yaml b/stack.yaml index 3729c68..38debc4 100644 --- a/stack.yaml +++ b/stack.yaml @@ -33,7 +33,9 @@ resolver: lts-21.25 # - auto-update # - wai packages: -- . + - . + - scripts/pull_album_info + # Dependency packages to be pulled from upstream that are not in the resolver # using the same syntax as the packages field. # (e.g., acme-missiles-0.3) @@ -44,6 +46,7 @@ extra-deps: - lrucache-1.2.0.1@sha256:18fc3d7052012c7ab3cd395160f34b53c5e1ec5379cc45185baf35b90ffadc2e,1254 - clay-0.15.0 - pandoc-3.0.1 + - ginger-0.10.5.2 # Override default flag values for local packages and extra-deps # flags: {} diff --git a/stack.yaml.lock b/stack.yaml.lock index 133ec19..9088d58 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -32,6 +32,13 @@ packages: size: 141318 original: hackage: pandoc-3.0.1 +- completed: + hackage: ginger-0.10.5.2@sha256:cda9c5a24cd3ea74af730a8ea64b0d8ae90696ea56f14b787cc4d92646f7ddad,3186 + pantry-tree: + sha256: 3c5c7e74779496d7de83bb400b7136656af67e5ccce8547b49055424c541c136 + size: 1430 + original: + hackage: ginger-0.10.5.2 snapshots: - completed: sha256: a81fb3877c4f9031e1325eb3935122e608d80715dc16b586eb11ddbff8671ecd