Skip to content

Update feeds

Update feeds #9123

Workflow file for this run

name: Update feeds
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
workflow_run:
workflows: ["build-app"] # Run after build-app workflow
types:
- completed
branches: [main]
workflow_dispatch:
inputs:
usePrerelease:
description: 'Use pre-release versions'
required: false
type: boolean
default: false
push:
paths:
- "**/generate-feed.yml"
- "**/podcasts.json"
- "site/**"
schedule:
- cron: "0 * * * *"
jobs:
load-podcasts:
name: Load Podcasts
runs-on: ubuntu-24.04
outputs:
podcasts: ${{ steps.load_data.outputs.podcasts }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Load Podcasts Data
id: load_data
run: |
echo "podcasts=$(jq -c . < podcasts.json)" >> $GITHUB_OUTPUT
- name: Download podcast icons
run: |
mkdir -p site/icons
jq -c '.podcasts[]' podcasts.json | while read -r podcast; do
slug=$(echo $podcast | jq -r '.slug')
image=$(echo $podcast | jq -r '.image')
ext=$(echo "$image" | grep -oP '\.(?:png|jpg|jpeg|gif|webp)$' || echo '.jpg')
echo "Downloading icon for $slug from $image"
curl -L "$image" -o "site/icons/$slug$ext"
done
- name: Upload template artifact
uses: actions/upload-artifact@v4
with:
name: site
path: site
retention-days: 1
update-feed:
name: "Update ${{ matrix.podcasts.slug }} feed"
needs: load-podcasts
env:
usePrerelease: ${{ inputs.usePrerelease || false }}
strategy:
fail-fast: true
matrix: ${{ fromJson(needs.load-podcasts.outputs.podcasts) }}
runs-on: ubuntu-24.04
steps:
- name: Get latest release
id: get_latest_release
uses: actions/cache@v4
with:
path: ommer.jar
key: ${{ runner.os }}-ommer-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-ommer-
- name: Download JAR if not cached
if: steps.get_latest_release.outputs.cache-hit != 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
RELEASE_URL=$(gh api "repos/$GITHUB_REPOSITORY/releases" \
--jq "[.[] | select(.prerelease == $usePrerelease)][0].assets[0].browser_download_url")
echo "Downloading from: $RELEASE_URL"
curl -L $RELEASE_URL -o ommer.jar
- uses: actions/setup-java@v4
with:
distribution: temurin
java-package: jre
java-version: 21
- name: Get host URL
id: get_host_url
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
SITE_URL=$(gh api "repos/${GITHUB_REPOSITORY}/pages" --jq '.html_url')
echo "host_url=$SITE_URL" >> $GITHUB_OUTPUT
- name: Execute parser for ${{ matrix.podcasts.slug }} feed
uses: corrupt952/actions-retry-command@v1.0.7
with:
command: java -Xmx2048m -XX:+UseParallelGC -jar ./ommer.jar --slug ${{ matrix.podcasts.slug }} --urn ${{ matrix.podcasts.urn }} --imageUrl ${{ matrix.podcasts.image }} --apiKey ${{ secrets.API_KEY }} --baseUrl ${{ steps.get_host_url.outputs.host_url }}
working_directory: ./
max_attempts: 3
retry_interval: 10
- name: Upload feed artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.podcasts.slug }}
path: output/${{ matrix.podcasts.slug }}.xml
retention-days: 1
if-no-files-found: error
check-deployment:
name: "Check if deployment is needed"
needs: [update-feed]
runs-on: ubuntu-24.04
outputs:
needs_deploy: ${{ steps.deployment_check.outputs.needs_deploy }}
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: _site
merge-multiple: true
- name: Move feeds to correct location
run: |
mkdir -p _site/feeds
mv _site/*.xml _site/feeds/
- name: Check for deployment changes
id: deployment_check
env:
GH_TOKEN: ${{ github.token }}
run: |
SITE_URL=$(gh api "repos/${GITHUB_REPOSITORY}/pages" --jq '.html_url')
NEEDS_DEPLOY=false
# Check each feed for changes
for feed in _site/feeds/*.xml; do
filename=$(basename "$feed")
# Get current hash
CURRENT_HASH=$(sha256sum "$feed" | cut -d ' ' -f1)
# Try to get deployed file hash
DEPLOYED_HASH=$(curl -sL --max-time 10 "${SITE_URL}feeds/$filename" | sha256sum | cut -d ' ' -f1 || echo "none")
echo "Checking $filename"
echo "Current hash: $CURRENT_HASH"
echo "Deployed hash: $DEPLOYED_HASH"
if [ "$CURRENT_HASH" != "$DEPLOYED_HASH" ]; then
echo "Changes detected in $filename"
NEEDS_DEPLOY=true
break
fi
done
if [ "$NEEDS_DEPLOY" = "false" ]; then
# Check if number of files changed
LIVE_COUNT=$(curl -sL --max-time 10 $SITE_URL | grep -o "class='feed-link'" | wc -l || echo "0")
CURRENT_COUNT=$(find "_site/feeds" -name "*.xml" 2>/dev/null | wc -l)
if [ "$CURRENT_COUNT" != "$LIVE_COUNT" ]; then
echo "Number of XML files changed (current: $CURRENT_COUNT, live: $LIVE_COUNT)"
NEEDS_DEPLOY=true
fi
fi
echo "needs_deploy=$NEEDS_DEPLOY" >> $GITHUB_OUTPUT
publish-feed:
name: "Publish feeds"
needs: [check-deployment]
if: |
needs.check-deployment.outputs.needs_deploy == 'true'
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
permissions:
pages: write
id-token: write
runs-on: ubuntu-24.04
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: _site
merge-multiple: true
- name: Move feeds to correct location
run: |
mkdir -p _site/feeds
mv _site/*.xml _site/feeds/
- name: Generate index.html
run: |
# Get current timestamp in ISO 8601 format
current_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
# Generate feeds HTML
feeds_html=""
for feed in _site/feeds/*.xml; do
filename=$(basename "$feed" .xml)
formatted_title=$(echo "$filename" | sed 's/-/ /g')
# Look for local icon file with any supported extension
icon_path=""
for ext in jpg jpeg png gif webp; do
if [ -f "_site/icons/$filename.$ext" ]; then
icon_path="icons/$filename.$ext"
break
fi
done
if [ -n "$icon_path" ]; then
feeds_html+="<li><a class='feed-link' href='feeds/$filename.xml'><img class='feed-icon' src='$icon_path' loading='lazy' alt='$formatted_title'><span class='feed-title'>$formatted_title</span></a></li>"
else
feeds_html+="<li><a class='feed-link' href='feeds/$filename.xml'><div class='feed-icon'></div><span class='feed-title'>$formatted_title</span></a></li>"
fi
done
# Insert deployment timestamp meta tag after opening head tag
sed -i '/<head>/a \ <meta name="deployment-time" content="'"$current_time"'">' _site/index.html
# Replace entire section between markers with generated feeds
sed -i "/<!-- BEGIN_FEEDS -->/,/<!-- END_FEEDS -->/c\ <!-- BEGIN_FEEDS -->\n $feeds_html\n <!-- END_FEEDS -->" _site/index.html
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4