Skip to content

Update Last.fm Data #2819

Update Last.fm Data

Update Last.fm Data #2819

Workflow file for this run

name: Update Last.fm Data
on:
schedule:
- cron: "0 * * * *" # hourly
workflow_dispatch:
permissions:
contents: write
actions: write
jobs:
lastfm:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch Last.fm index
id: lastfm-index
run: |
curl -sf "https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=moglenstar&api_key=6bcfcb1e0c192d84adf10cf95b0589e3&limit=1&format=json" -o /tmp/lastfm-index.json
echo "hash=$(sha256sum /tmp/lastfm-index.json | cut -d' ' -f1)" >> $GITHUB_OUTPUT
- name: Restore Last.fm cache
id: lastfm-cache
uses: actions/cache@v4
with:
path: _data/now/lastfm.json
key: lastfm-${{ steps.lastfm-index.outputs.hash }}
- name: Set up Node.js
if: steps.lastfm-cache.outputs.cache-hit != 'true'
uses: actions/setup-node@v4
with:
node-version: 20
- name: Fetch Last.fm data
if: steps.lastfm-cache.outputs.cache-hit != 'true'
env:
LASTFM_USERNAME: moglenstar
LASTFM_API_KEY: 6bcfcb1e0c192d84adf10cf95b0589e3
run: node .github/lastfm.js
- name: Commit changes
id: commit
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git add _data/now/lastfm.json
if git diff --staged --quiet; then
echo "changed=false" >> $GITHUB_OUTPUT
else
if [ "$(git log -1 --pretty=%s)" = "Update data" ]; then
git commit --amend --no-edit
git push --force-with-lease
else
git commit -m "Update data"
git push
fi
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Trigger Jekyll build
if: steps.commit.outputs.changed == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: gh workflow run jekyll.yml