Weekly puzzle workflow: Sunday 03:37 UTC, commit the data to main, redeploy the live release with it through release.yml; releases ship every weekly from main
This commit is contained in:
parent
372893ec75
commit
2ac9143db9
2 changed files with 107 additions and 1 deletions
28
.github/workflows/release.yml
vendored
28
.github/workflows/release.yml
vendored
|
|
@ -4,7 +4,8 @@ name: Release to GitHub Pages
|
||||||
# Pushes to main run CI but never deploy. To ship: bump "version" in
|
# Pushes to main run CI but never deploy. To ship: bump "version" in
|
||||||
# package.json and date its CHANGELOG section; auto-release.yml then tags,
|
# package.json and date its CHANGELOG section; auto-release.yml then tags,
|
||||||
# publishes the release and starts this workflow from the tag. Publishing a
|
# publishes the release and starts this workflow from the tag. Publishing a
|
||||||
# release by hand works too.
|
# release by hand works too. Every Sunday weekly-puzzle.yml redeploys the live
|
||||||
|
# release from its tag with the new weekly puzzle added (input weekly).
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
# "released" also fires when a pre-release is promoted to a full release.
|
# "released" also fires when a pre-release is promoted to a full release.
|
||||||
|
|
@ -18,6 +19,10 @@ on:
|
||||||
description: Allow deploying a version older than what is live (rollback)
|
description: Allow deploying a version older than what is live (rollback)
|
||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: false
|
||||||
|
weekly:
|
||||||
|
description: Only the weekly puzzles changed (weekly-puzzle.yml); the release itself was tested when it shipped
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
|
|
||||||
# Least privilege: only the deploy job can write to Pages.
|
# Least privilege: only the deploy job can write to Pages.
|
||||||
permissions:
|
permissions:
|
||||||
|
|
@ -63,8 +68,28 @@ jobs:
|
||||||
if [ "$ALLOW_OLDER" != "true" ] && [ "$(printf '%s\n%s\n' "$live" "$new" | sort -V | tail -n1)" != "$new" ]; then
|
if [ "$ALLOW_OLDER" != "true" ] && [ "$(printf '%s\n%s\n' "$live" "$new" | sort -V | tail -n1)" != "$new" ]; then
|
||||||
echo "::error::$new is older than the live $live. Re-run with allow_older to roll back on purpose."; exit 1
|
echo "::error::$new is older than the live $live. Re-run with allow_older to roll back on purpose."; exit 1
|
||||||
fi
|
fi
|
||||||
|
# Weekly puzzles are published on main between releases (weekly-puzzle.yml). Every deploy ships all of them,
|
||||||
|
# so neither a release nor a weekly redeploy ever drops a week that is already out.
|
||||||
|
- name: Weekly puzzles from main
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
git fetch --no-tags --depth=1 origin main
|
||||||
|
if git cat-file -e FETCH_HEAD:site/puzzles/weekly 2>/dev/null; then
|
||||||
|
rm -rf site/puzzles/weekly
|
||||||
|
git checkout FETCH_HEAD -- site/puzzles/weekly
|
||||||
|
echo "Weekly puzzles: $(ls site/puzzles/weekly | grep -c '^[0-9].*\.json$')"
|
||||||
|
fi
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm test
|
- run: npm test
|
||||||
|
if: ${{ !inputs.weekly }}
|
||||||
|
- name: Check the weekly puzzles against this release
|
||||||
|
if: ${{ inputs.weekly }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
# A release from before the weekly puzzles ships the files without reading them: nothing to check.
|
||||||
|
if [ ! -f scripts/weekly-puzzle.js ]; then echo "This release does not read weekly puzzles yet."; exit 0; fi
|
||||||
|
node scripts/weekly-puzzle.js --check
|
||||||
|
npm test -- tests/weekly-puzzle.test.js tests/puzzles.test.js
|
||||||
- name: Build site
|
- name: Build site
|
||||||
run: VERSION="${TAG#v}" REQUIRE_NOTES=1 npm run build
|
run: VERSION="${TAG#v}" REQUIRE_NOTES=1 npm run build
|
||||||
- uses: actions/upload-pages-artifact@v5
|
- uses: actions/upload-pages-artifact@v5
|
||||||
|
|
@ -88,6 +113,7 @@ jobs:
|
||||||
# the site is live.
|
# the site is live.
|
||||||
indexnow:
|
indexnow:
|
||||||
needs: deploy
|
needs: deploy
|
||||||
|
if: ${{ !inputs.weekly }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
# IndexNow keys are public by design (also served at /<key>.txt).
|
# IndexNow keys are public by design (also served at /<key>.txt).
|
||||||
|
|
|
||||||
80
.github/workflows/weekly-puzzle.yml
vendored
Normal file
80
.github/workflows/weekly-puzzle.yml
vendored
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
name: Weekly puzzle
|
||||||
|
|
||||||
|
# Every Sunday morning: make this week's puzzle (scripts/weekly-puzzle.js), commit it to main as a data-only
|
||||||
|
# change, and redeploy the live release with it. Puzzle weeks start Sunday 06:00 Berlin time; 03:37 UTC is
|
||||||
|
# 04:37 in winter and 05:37 in summer, so the file is live before the week starts either way.
|
||||||
|
#
|
||||||
|
# No version bump, so no release: auto-release.yml only runs when package.json changes (and pushes made with
|
||||||
|
# the workflow token start no workflows at all). The deploy itself is release.yml, still the only workflow
|
||||||
|
# that can write to Pages, started from the live release's tag with weekly=true: it rebuilds exactly that
|
||||||
|
# release with every weekly puzzle from main added, in the same "pages" concurrency group as any release.
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '37 3 * * 0'
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
key:
|
||||||
|
description: Week to make, e.g. 2026-W45 (default the week starting this Sunday)
|
||||||
|
required: false
|
||||||
|
deploy:
|
||||||
|
description: Redeploy the live release with it
|
||||||
|
type: boolean
|
||||||
|
default: true
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write # commit the puzzle to main
|
||||||
|
actions: write # start release.yml
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: weekly-puzzle
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
puzzle:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 30
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
KEY: ${{ inputs.key }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v7
|
||||||
|
with:
|
||||||
|
ref: main
|
||||||
|
- uses: actions/setup-node@v7
|
||||||
|
with:
|
||||||
|
node-version: 24
|
||||||
|
cache: npm
|
||||||
|
- run: npm ci
|
||||||
|
- name: Make the puzzle
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
if [ -n "$KEY" ]; then
|
||||||
|
[[ "$KEY" =~ ^[0-9]{4}-W[0-9]{2}$ ]] || { echo "::error::$KEY is not a week key"; exit 1; }
|
||||||
|
node scripts/weekly-puzzle.js --key "$KEY"
|
||||||
|
else
|
||||||
|
node scripts/weekly-puzzle.js
|
||||||
|
fi
|
||||||
|
- name: Check every weekly puzzle
|
||||||
|
run: node scripts/weekly-puzzle.js --check && npm test -- tests/weekly-puzzle.test.js tests/puzzles.test.js
|
||||||
|
- name: Commit it to main
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
git add site/puzzles/weekly
|
||||||
|
# Data only: anything else changed means something is wrong.
|
||||||
|
if git status --porcelain | grep -v ' site/puzzles/weekly/' | grep -q .; then git status --porcelain; echo "::error::unexpected changes"; exit 1; fi
|
||||||
|
if git diff --cached --quiet; then echo "Nothing new to commit."; exit 0; fi
|
||||||
|
git -c user.name="github-actions[bot]" -c user.email="41898282+github-actions[bot]@users.noreply.github.com" \
|
||||||
|
commit -m "Weekly puzzle $(git diff --cached --name-only | grep -o '[0-9]\{4\}-W[0-9]\{2\}' | sort -u | paste -sd ' ')"
|
||||||
|
git push origin HEAD:main
|
||||||
|
- name: Redeploy the live release with it
|
||||||
|
if: github.event_name == 'schedule' || inputs.deploy
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
tag=$(gh release list --repo "$GITHUB_REPOSITORY" --exclude-pre-releases --exclude-drafts --limit 1 --json tagName -q '.[0].tagName')
|
||||||
|
[ -n "$tag" ] || { echo "::error::no release to redeploy"; exit 1; }
|
||||||
|
# Releases from before the weekly puzzles cannot take them (and their game would not read them).
|
||||||
|
if ! git fetch --no-tags --depth=1 origin "refs/tags/$tag" || ! git show FETCH_HEAD:.github/workflows/release.yml | grep -q '^ weekly:'; then
|
||||||
|
echo "::notice::$tag predates weekly puzzles; the puzzle is on main and ships with the next release."; exit 0
|
||||||
|
fi
|
||||||
|
gh workflow run release.yml --repo "$GITHUB_REPOSITORY" --ref "$tag" -f tag="$tag" -f weekly=true
|
||||||
|
echo "Redeploying $tag with the weekly puzzles."
|
||||||
Loading…
Add table
Add a link
Reference in a new issue