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 fb5a47a..0000000 Binary files a/dist-newstyle/cache/config and /dev/null differ diff --git a/.github/scripts/pull_album_info/.gitignore b/scripts/pull_album_info/.gitignore similarity index 100% rename from .github/scripts/pull_album_info/.gitignore rename to scripts/pull_album_info/.gitignore diff --git a/.github/scripts/pull_album_info/app/Main.hs b/scripts/pull_album_info/app/Main.hs similarity index 92% rename from .github/scripts/pull_album_info/app/Main.hs rename to scripts/pull_album_info/app/Main.hs index 42690da..1bdec46 100644 --- a/.github/scripts/pull_album_info/app/Main.hs +++ b/scripts/pull_album_info/app/Main.hs @@ -9,8 +9,7 @@ module Main where -- Standard library imports import Control.Exception (SomeException, try) -import System.Environment (getArgs, getProgName, lookupEnv) -import System.FilePath (takeDirectory) +import System.Environment (getArgs, lookupEnv) -- Third-party library imports import Control.Lens (Identity (runIdentity), (^?)) @@ -146,15 +145,16 @@ getTemplate :: String -> 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