A version bump's push started docker.yml's test, then auto-release started docker.yml again for the tag, which tests the same code before it publishes: the push skips its test while the version is not tagged. The deploy re-ran the weekly-puzzle tests even when main's weekly files are the tag's own, which CI had just tested: it now runs them only for files that differ (a newer or refitted week) or an untested tag.
161 lines
7.7 KiB
YAML
161 lines
7.7 KiB
YAML
name: Release to GitHub Pages
|
|
|
|
# The live site at https://seriesoftub.es only ever serves a published release.
|
|
# 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,
|
|
# publishes the release and starts this workflow from the tag. Publishing a
|
|
# 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:
|
|
release:
|
|
# "released" also fires when a pre-release is promoted to a full release.
|
|
types: [released]
|
|
workflow_dispatch:
|
|
inputs:
|
|
tag:
|
|
description: Existing release tag to redeploy (e.g. v1.0.0)
|
|
required: true
|
|
allow_older:
|
|
description: Allow deploying a version older than what is live (rollback)
|
|
type: boolean
|
|
default: false
|
|
weekly:
|
|
description: Only the weekly puzzles changed (weekly-puzzle.yml); the release itself was tested when it shipped
|
|
type: boolean
|
|
default: false
|
|
tested:
|
|
description: The tag's tests already passed (auto-release.yml tests it before tagging)
|
|
type: boolean
|
|
default: false
|
|
|
|
# Least privilege: only the deploy job can write to Pages.
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: pages
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
# The release's tests, split over several runners like every push (ci.yml). Skipped when auto-release.yml has just
|
|
# run them on this tag, and for a weekly redeploy (the build step below tests the weekly files against the tag).
|
|
tests:
|
|
if: ${{ (github.event_name == 'workflow_dispatch' || !github.event.release.prerelease) && !inputs.weekly && !inputs.tested }}
|
|
uses: ./.github/workflows/ci.yml
|
|
with:
|
|
ref: ${{ github.event.release.tag_name || inputs.tag }}
|
|
|
|
build:
|
|
needs: tests
|
|
# Pre-releases are for testing and never go live.
|
|
if: ${{ always() && (github.event_name == 'workflow_dispatch' || !github.event.release.prerelease) && (needs.tests.result == 'success' || needs.tests.result == 'skipped') }}
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
TAG: ${{ github.event.release.tag_name || inputs.tag }}
|
|
ALLOW_OLDER: ${{ inputs.allow_older || false }}
|
|
GH_TOKEN: ${{ github.token }}
|
|
steps:
|
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
ref: ${{ env.TAG }}
|
|
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
|
with:
|
|
node-version: 24
|
|
cache: npm
|
|
- name: Tag must match package.json version
|
|
run: |
|
|
set -euo pipefail
|
|
want="v$(node -p "require('./package.json').version")"
|
|
if [ "$TAG" != "$want" ]; then
|
|
echo "::error::Release tag $TAG does not match package.json version ($want)"
|
|
exit 1
|
|
fi
|
|
- name: Never deploy pre-releases or roll the live site back by accident
|
|
run: |
|
|
set -euo pipefail
|
|
if [ "$(gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json isPrerelease -q .isPrerelease)" = "true" ]; then
|
|
echo "::error::$TAG is a pre-release; pre-releases never deploy"; exit 1
|
|
fi
|
|
live=$(curl -sSf https://seriesoftub.es/version.json 2>/dev/null | jq -r .version || echo "0.0.0")
|
|
new="${TAG#v}"
|
|
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
|
|
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 and scenarios from main
|
|
run: |
|
|
set -euo pipefail
|
|
git fetch --no-tags --depth=1 origin main
|
|
for d in site/puzzles/weekly site/scenarios/weekly site/architect/weekly; do
|
|
if git cat-file -e "FETCH_HEAD:$d" 2>/dev/null; then
|
|
rm -rf "$d"
|
|
git checkout FETCH_HEAD -- "$d"
|
|
echo "$d: $(ls "$d" | grep -c '^[0-9].*\.json$')"
|
|
fi
|
|
done
|
|
- run: npm ci
|
|
# This release's prices may no longer fit a week already published: --check regenerates every week not over
|
|
# yet whose budget no longer verifies (deterministically, so main's next weekly run commits the same files),
|
|
# and fails the deploy only if that fails. Before the tests, which check the weeks too.
|
|
- name: Fit the weekly puzzles to this release
|
|
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
|
|
if [ -f scripts/weekly-scenario.js ]; then node scripts/weekly-scenario.js --check; fi
|
|
if [ -f scripts/weekly-architect.js ]; then node scripts/weekly-architect.js --check; fi
|
|
# The weekly files come from main, not the tag. When they (after fitting) are the tag's own, CI already tested
|
|
# them with it; otherwise (a newer week, a refitted one) they are tested against this release here.
|
|
- name: Are the weekly files the tag's own?
|
|
id: weekly
|
|
run: |
|
|
if [ -z "$(git status --porcelain -- site/puzzles/weekly site/scenarios/weekly site/architect/weekly)" ]; then
|
|
echo "Same weekly files as the tag: tested with it already."; echo "same=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
git status --short -- site/puzzles/weekly site/scenarios/weekly site/architect/weekly; echo "same=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
- name: Test the weekly puzzles against this release
|
|
if: ${{ hashFiles('scripts/weekly-puzzle.js') != '' && (steps.weekly.outputs.same != 'true' || !(inputs.tested || needs.tests.result == 'success')) }}
|
|
run: npm test -- tests/weekly-puzzle.test.js tests/puzzles.test.js $(ls tests/weekly-scenario.test.js tests/weekly-architect.test.js 2>/dev/null)
|
|
- name: Build site
|
|
run: VERSION="${TAG#v}" REQUIRE_NOTES=1 npm run build
|
|
- uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
|
|
with:
|
|
path: ./_site
|
|
|
|
deploy:
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
pages: write
|
|
id-token: write
|
|
environment:
|
|
name: github-pages
|
|
url: ${{ steps.deployment.outputs.page_url }}
|
|
steps:
|
|
- id: deployment
|
|
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1
|
|
# the site is live.
|
|
indexnow:
|
|
needs: deploy
|
|
if: ${{ !inputs.weekly }}
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
# IndexNow keys are public by design (also served at /<key>.txt).
|
|
HOST: seriesoftub.es
|
|
KEY: d000727792a2ac2fdaa24ec953ed6d2b
|
|
steps:
|
|
- name: Submit sitemap URLs to IndexNow
|
|
run: |
|
|
set -euo pipefail
|
|
urls=$(curl -sSf "https://$HOST/sitemap.xml" | grep -oP '(?<=<loc>)[^<]+' | grep -v '\.png$' | jq -R . | jq -s .)
|
|
payload=$(jq -n --arg host "$HOST" --arg key "$KEY" \
|
|
--arg keyLocation "https://$HOST/$KEY.txt" --argjson urlList "$urls" \
|
|
'{host: $host, key: $key, keyLocation: $keyLocation, urlList: $urlList}')
|
|
code=$(curl -sS -X POST "https://api.indexnow.org/indexnow" \
|
|
-H "Content-Type: application/json; charset=utf-8" --data "$payload" \
|
|
-o /tmp/indexnow.txt -w '%{http_code}')
|
|
echo "IndexNow responded HTTP $code"; cat /tmp/indexnow.txt || true
|
|
if [ "$code" -ge 400 ]; then echo "::warning::IndexNow submission failed ($code)"; fi
|