Skip to content

Update, Build & Deployment #2363

Update, Build & Deployment

Update, Build & Deployment #2363

Workflow file for this run

name: "Update, Build & Deployment"
on:
workflow_dispatch:
push:
branches: ["main"]
paths-ignore:
- ".github/**"
schedule: # times in in UTC
- cron: 30 2 * * TUE,THU # At 02:30 on Tuesday and Thursday
- cron: 15,45 09-21 * JAN-APR,OCT-DEC 0,6 # At minute 15 & 45 past every hour, from 9 AM to 9 PM on Sunday & Saturday, from October through April
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
env:
GITHUB_SUMMARY_FILE: "github_summary.md"
SAMS_FOLDER: "data/sams"
SAMS_MATCHSERIES_JSON: "data/sams/matchSeries.json"
SAMS_CLUB_JSON: "data/sams/club.json"
SAMS_CLUBS_CACHE: "data/sams/allClubs.json"
SAMS_PLAYERS_CACHE: "data/sams/team"
IMAGES_FOLDER: "public/images"
BLOG_FOLDER: "data/posts"
INBOX_FOLDER: "inbox"
SOCIAL_CACHE_MATCHES: "data/social/matchResults.json"
jobs:
# Build jobs
build:
name: "🏗️ SAMS & Build"
runs-on: ubuntu-latest
env:
TZ: Europe/Berlin
outputs:
sams_status: ${{ steps.sams_git.outputs.status }}
sams_social: ${{ steps.sams_git.outputs.social }}
build_status: ${{ steps.next_build.outputs.status }}
blog_check: ${{ steps.blog_check.outputs.status }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }} # latest commit, default is the commit that triggered the workflow
- name: Setup Bun
uses: oven-sh/setup-bun@v1
- name: Restore cache
uses: actions/cache@v4
with:
path: |
.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
- name: Install dependencies
run: bun install
- name: Perform SAMS Update
id: sams_update
if: ${{ github.event_name != 'push' }}
continue-on-error: true
run: bun run sams-update
env:
SAMS_API: ${{ secrets.SAMS_API }}
- name: Commit SAMS Files
id: sams_git
if: steps.sams_update.conclusion == 'success'
continue-on-error: true
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
if [ -z "$(git stage ${{ env.SAMS_MATCHSERIES_JSON }} --dry-run)" ]
then
echo "✅ Match Series up to date."
echo "✅ Match Series up to date." >> $GITHUB_STEP_SUMMARY
else
echo "🏐 Match Series changes detected and staged."
git add ${{ env.SAMS_MATCHSERIES_JSON }} --force || true
git commit -m "automated deployment update" || true
echo "🏐 Match Series changes detected and staged." >> $GITHUB_STEP_SUMMARY
fi
if [ -z "$(git stage ${{ env.SAMS_CLUB_JSON }} --dry-run)" ]
then
echo "✅ Our club data is up to date."
echo "✅ Our club data is up to date." >> $GITHUB_STEP_SUMMARY
else
echo "🏐 Our club data has changed! Pushing to repository."
git add ${{ env.SAMS_CLUB_JSON }}
git commit -m "automated deployment update"
git push origin --all --quiet --force
echo "status=updated" >> $GITHUB_OUTPUT
echo "🏐 Our club data has changed. Pushed to repository." >> $GITHUB_STEP_SUMMARY
fi
if [ -z "$(git stage ${{ env.SAMS_CLUBS_CACHE }} --dry-run)" ]
then
echo "✅ All club data up to date."
echo "✅ All club data up to date." >> $GITHUB_STEP_SUMMARY
else
echo "🏐 Some new club data detected! Pushing to repository."
git add ${{ env.SAMS_CLUBS_CACHE }}
git commit -m "automated deployment update"
git push origin --all --quiet --force
echo "status=updated" >> $GITHUB_OUTPUT
echo "🏐 Some new club data detected and pushed to repository." >> $GITHUB_STEP_SUMMARY
fi
if [ -z "$(git stage ${{ env.SAMS_PLAYERS_CACHE }} --dry-run)" ]
then
echo "✅ All player data up to date."
echo "✅ All player data up to date." >> $GITHUB_STEP_SUMMARY
else
echo "🏐 Some new player data detected! Pushing to repository."
git add ${{ env.SAMS_PLAYERS_CACHE }}
git commit -m "automated deployment update"
git push origin --all --quiet --force
echo "status=updated" >> $GITHUB_OUTPUT
echo "🏐 Some new player data detected and pushed to repository." >> $GITHUB_STEP_SUMMARY
fi
if [ -z "$(git stage ${{ env.SAMS_FOLDER }} --dry-run)" ]
then
echo "✅ SAMS data up to date."
echo "✅ SAMS data up to date." >> $GITHUB_STEP_SUMMARY
else
echo "🏐 SAMS changes detected! Pushing to repository."
git add ${{ env.SAMS_FOLDER }}
git commit -m "automated deployment update"
git push origin --all --quiet --force
echo "status=updated" >> $GITHUB_OUTPUT
echo "🏐 SAMS changes detected and pushed to repository." >> $GITHUB_STEP_SUMMARY
fi
cat ${{ env.GITHUB_SUMMARY_FILE }} >> $GITHUB_STEP_SUMMARY || true
if grep -q '"mastodon": "queued"' ${{ env.SOCIAL_CACHE_MATCHES }} || grep -q '"mastodon": "new"' ${{ env.SOCIAL_CACHE_MATCHES }};
then
echo "social=new" >> $GITHUB_OUTPUT
echo "🕵️ Unpublished Match Result for social detected! Queueing job."
echo "🕵️ Unpublished Match Result for social detected! Queueing job." >> $GITHUB_STEP_SUMMARY
if [ -z "$(git stage ${{ env.SOCIAL_CACHE_MATCHES }} --dry-run)" ]
then
echo "✅ No social cache file changes. Nothing to commit."
echo "✅ No social cache file changes. Nothing to commit." >> $GITHUB_STEP_SUMMARY
else
git add ${{ env.SOCIAL_CACHE_MATCHES }}
git commit -m "automated deployment update"
git push origin --all --quiet --force
echo "🏐 Changes in social cache detected! Pushing to repository."
echo "🏐 Changes in social cache detected! Pushing to repository." >> $GITHUB_STEP_SUMMARY
fi
else
echo "✅ No unpublished Match Result found."
echo "✅ No unpublished Match Result found." >> $GITHUB_STEP_SUMMARY
fi
- name: Process Inbox
id: process_inbox
if: ${{ github.event_name != 'schedule' }}
run: bun run inbox
- name: New Blog Post Check
id: blog_check
if: steps.process_inbox.conclusion == 'success'
continue-on-error: true
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
if [ -z "$(git stage ${{ env.BLOG_FOLDER }} --dry-run)" ]
then
echo "✅ No new blog post found."
echo "✅ No new blog post found." >> $GITHUB_STEP_SUMMARY
else
echo "📑 New Blog post detected! Pushing to repository and cleaning the inbox folder."
git add ${{ env.BLOG_FOLDER }}
git add ${{ env.IMAGES_FOLDER }}
git add ${{ env.INBOX_FOLDER }}
git commit -m "automated deployment update"
git push origin --all --quiet --force
echo "status=new" >> $GITHUB_OUTPUT
echo "📑 New Blog post detected. Sharing on social initiated." >> $GITHUB_STEP_SUMMARY
cat ${{ env.GITHUB_SUMMARY_FILE }} >> $GITHUB_STEP_SUMMARY
fi
- name: Build with Next.js
id: next_build
if: ${{ github.event.schedule != '15,45 09-21 * JAN-APR,OCT-DEC 0,6' || steps.sams_git.outputs.status == 'updated' }}
run: |
echo "status=started" >> $GITHUB_OUTPUT
bun run build
echo "👷 Build complete:" >> $GITHUB_STEP_SUMMARY
du -hsc out | grep -e "total" >> $GITHUB_STEP_SUMMARY
- name: Commit Optimized Images
if: steps.next_build.conclusion == 'success'
continue-on-error: true
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
if [ -z "$(git stage ${{ env.IMAGES_FOLDER }} --force --dry-run)" ]
then
echo "✅ Image optimizations are up to date."
echo "✅ Image optimizations are up to date." >> $GITHUB_STEP_SUMMARY
else
echo "🖼️ New image optimizations! Pushing to repository."
git stage ${{ env.IMAGES_FOLDER }} --force
git commit -m "automated deployment update"
git push origin --all --quiet --force
echo "🖼️ New image optimizations changes detected and pushed to repository." >> $GITHUB_STEP_SUMMARY
fi
- name: Upload artifact
if: steps.next_build.conclusion == 'success'
uses: actions/upload-pages-artifact@v3
with:
path: ./out
# Deployment job
deploy:
name: "🚚 Deployment"
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
if: ${{ needs.build.outputs.build_status == 'started' }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
# Social sharing job
mastodon:
name: "💬 Share to Mastodon"
runs-on: ubuntu-latest
needs: [build, deploy]
if: ${{ needs.build.outputs.build_status == 'started' && (needs.build.outputs.sams_social == 'new' || needs.build.outputs.blog_check == 'new' || github.event_name == 'workflow_dispatch' ) }}
env:
MASTODON_CLIENT_ID: ${{ secrets.MASTODON_CLIENT_ID }}
MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }} # latest commit, default is the commit that triggered the workflow
- name: Setup Bun
uses: oven-sh/setup-bun@v1
- name: Restore cache
uses: actions/cache@v4
with:
path: |
.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
- name: Install dependencies
run: bun install
- name: Match Results
id: match_results
if: ${{ needs.build.outputs.sams_social == 'new' || github.event_name == 'workflow_dispatch' }}
run: bun run sams-new-results
- name: Blog Posts
id: blog_posts
if: ${{ needs.build.outputs.blog_check == 'new' || github.event_name == 'workflow_dispatch' }}
run: bun run blog-new-posts
- name: Commit Changes
id: commit_changes
if: steps.match_results.conclusion == 'success' || steps.blog_posts.conclusion == 'success'
continue-on-error: true
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
if [ -z "$(git stage ${{ env.SOCIAL_CACHE_MATCHES }} --dry-run)" ]
then
echo "✅ Match Results Cache file up to date."
echo "✅ Match Results Cache file up to date." >> $GITHUB_STEP_SUMMARY
else
echo "🏐 Match Results Cache file modified! Pushing to repository."
echo "🏐 Match Results Cache file modified and pushed to repository." >> $GITHUB_STEP_SUMMARY
git add ${{ env.SOCIAL_CACHE_MATCHES }}
git commit -m "automated deployment update"
git push origin --all --quiet --force
fi
if [ -z "$(git stage ${{ env.BLOG_FOLDER }} --dry-run)" ]
then
echo "✅ Blogs posts are up to date."
echo "✅ Blogs posts are up to date." >> $GITHUB_STEP_SUMMARY
else
echo "🏐 Blog posts have been modified! Pushing to repository."
echo "🏐 Blog posts have been modified! Pushing to repository." >> $GITHUB_STEP_SUMMARY
git add ${{ env.BLOG_FOLDER }}
git commit -m "automated deployment update"
git push origin --all --quiet --force
fi
- name: Github Summary
if: steps.commit_changes.conclusion == 'success'
continue-on-error: true
run: cat ${{ env.GITHUB_SUMMARY_FILE }} >> $GITHUB_STEP_SUMMARY | true