Skip to content

feat: move pull-album-info to repo root #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 12 additions & 36 deletions .github/workflows/create_album_post.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]

- 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 }}
Expand All @@ -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'
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ _cache/
dist-newstyle/

.env
fillin-release-dates/
Binary file removed dist-newstyle/cache/config
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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), (^?))
Expand Down Expand Up @@ -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
Expand All @@ -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 <artist_name> <album_name> <branch_name>"
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ executable pull-album-info
lens-aeson,
lens,
ginger,
text,
filepath
text

-- Directories containing source files.
hs-source-dirs: app
Expand Down
5 changes: 4 additions & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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: {}
Expand Down
7 changes: 7 additions & 0 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down