name: Sync upstream mirrors# Mirrors swisskyrepo's PayloadsAllTheThings and InternalAllTheThings into the# site and pushes straight to main. No review gate: the build and the test suite# are what stand between upstream and the live site, so a sync that breaks# either one fails here and never lands. The build itself refuses imported# content that carries a script (scripts/csp-hashes.mjs) and the importers# refuse symbolic links (scripts/safe_source.py).on:
schedule:
- cron: '176***'# daily 06:17 UTCworkflow_dispatch:
# Nothing is granted at the top level; each job asks for what it needs.permissions: {}
concurrency:
group: sync-mirrorscancel-in-progress: false# Two jobs, split on purpose.## `convert` is the one that touches third-party input: it clones both# upstreams, runs the importers over them and builds the site from the result.# It gets a read-only token that is not left on disk, so nothing it reads or# runs can push, and a file copied out of the runner by a hostile upstream# (the importers refuse symbolic links for exactly that reason) would find no# credential to copy.## `publish` holds the write token and runs none of that. It receives the sync# commits as a git bundle, checks that they change the mirror trees and# nothing else, and pushes.jobs:
convert:
runs-on: ubuntu-latestpermissions:
contents: readoutputs:
changed: ${{ steps.sync.outputs.changed }}steps:
- name: Checkout siteuses: actions/checkout@v4with:
persist-credentials: false - name: Setup Nodeuses: actions/setup-node@v4with:
node-version: 22cache: npm# Everything the sync does lives in the script, so running it locally# and running it here are the same thing. It clones both upstreams,# regenerates the mirrors, refuses to go on if anything fails# `npm run build` or `node --test`, and commits one commit per upstream# for whichever trees actually moved. The commits stay local to this job. - name: Sync, validate and commitid: syncrun: scripts/sync-mirrors.sh --commit - name: Bundle the sync commitsif: steps.sync.outputs.changed == 'true'run: git bundle create "$RUNNER_TEMP/sync.bundle" "${GITHUB_SHA}..HEAD" - name: Hand the bundle to the publish jobif: steps.sync.outputs.changed == 'true'uses: actions/upload-artifact@v4with:
name: sync-bundlepath: ${{ runner.temp }}/sync.bundleif-no-files-found: errorretention-days: 1publish:
needs: convertif: needs.convert.outputs.changed == 'true'runs-on: ubuntu-latestpermissions:
contents: writesteps:
- name: Checkout siteuses: actions/checkout@v4with:
# The commit the bundle was built on, with full history so the push# can rebase if main moved while the build was running.ref: ${{ github.sha }}fetch-depth: 0 - name: Fetch the bundleuses: actions/download-artifact@v4with:
name: sync-bundlepath: ${{ runner.temp }} - name: Check and pushrun: |
set -euo pipefailbase=$(git rev-parse HEAD)git bundle verify "$RUNNER_TEMP/sync.bundle"git fetch --no-tags "$RUNNER_TEMP/sync.bundle" HEADgit merge-base --is-ancestor "$base" FETCH_HEAD# The sync may change the mirrors and nothing else. Anything outside# them (a workflow, a script, a page template) is not a sync.outside=$(git diff --name-only "$base" FETCH_HEAD -- . \':(exclude)src/content/payloads' \':(exclude)src/content/internal' \':(exclude)vendor/PayloadsAllTheThings' \':(exclude)payloads-manifest.json' \':(exclude)internal-manifest.json')if [ -n "$outside" ]; thenecho 'The sync commits touch files outside the mirrors; refusing to push:' >&2echo "$outside" >&2exit 1figit config user.name 'github-actions[bot]'git config user.email '41898282+github-actions[bot]@users.noreply.github.com'git merge --ff-only FETCH_HEAD# Retry once through a rebase in case main moved while the build was running.git push origin HEAD:main || {git fetch origin maingit rebase origin/maingit push origin HEAD:main}# No deploy step: Cloudflare Workers is the only host and it deploys# manually via `npm run deploy:workers`. A sync lands commits on main and# nothing more, so synced content goes live at the next manual deploy.