From 55bf41cc080e9256c51e19d8bbbc6827bfe393d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 5 Dec 2026 14:13:32 +0100 Subject: [PATCH 1/5] ci(release): give release paths a code owner and push version bumps with a deploy key --- .github/CODEOWNERS | 6 ++ .github/workflows/release.yml | 100 ++++++++++++++++++++++++++++++---- docs/agents/pull-requests.md | 11 ++++ 3 files changed, 107 insertions(+), 10 deletions(-) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000000..3d10f73bed3 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,6 @@ +# Release and signing paths need the release owner's review. The branch ruleset on main and 0.22 +# requires code-owner review and no other approvals, so other changes merge as before. +# Jobs that hold release secrets run only these paths. See docs/agents/pull-requests.md. +/.github/ @thymikee +/scripts/release-* @thymikee +/scripts/*android-helper* @thymikee diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 91d202235cd..6fc901882bd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -330,40 +330,120 @@ jobs: DEPLOY_HOOK: ${{ secrets.VERCEL_SITE_DEPLOY_HOOK }} run: curl -fsS -X POST "$DEPLOY_HOOK" > /dev/null - mark-released: - name: Move main past ${{ needs.plan.outputs.version }} + prepare-next-version: + name: Prepare the version after ${{ needs.plan.outputs.version }} needs: [plan, publish] if: needs.plan.outputs.mode == 'stable' runs-on: blacksmith-4vcpu-ubuntu-2404 timeout-minutes: 10 permissions: - contents: write + contents: read + outputs: + artifact_id: ${{ steps.upload.outputs.artifact-id }} + next: ${{ steps.advance.outputs.next }} steps: - name: Checkout main uses: useblacksmith/checkout@2b9fe87d796feea153b455ec2f3125b471a7b0e7 # v1.8.2 with: ref: main + persist-credentials: false - name: Setup toolchain uses: ./.github/actions/setup-node-pnpm - # main must never carry a published version. Retried because merges can - # land on main while the release runs. + - name: Compute the next development version + id: advance + env: + VERSION: ${{ needs.plan.outputs.version }} + run: | + set -euo pipefail + next="$(node scripts/release-version.mjs advance "$VERSION")" + printf 'next=%s\n' "$next" >> "$GITHUB_OUTPUT" + git diff -U0 --no-color --no-ext-diff > "$RUNNER_TEMP/next-version.patch" + + - name: Upload the version patch + id: upload + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: next-version-${{ needs.plan.outputs.version }} + path: ${{ runner.temp }}/next-version.patch + retention-days: 1 + + # main must never carry a published version. The ruleset on main lets only admins and deploy + # keys push without a PR. The push key is a deploy key that only the `release` environment holds, + # so this job runs no repository code: it applies the patch only after it proves that the patch + # changes version strings and nothing else. + mark-released: + name: Move main past ${{ needs.plan.outputs.version }} + needs: [plan, prepare-next-version] + runs-on: ubuntu-latest + timeout-minutes: 10 + environment: release + permissions: + contents: read + steps: + - name: Checkout main + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + ref: main + ssh-key: ${{ secrets.RELEASE_PUSH_DEPLOY_KEY }} + + - name: Require the patch artifact ID + env: + ARTIFACT_ID: ${{ needs.prepare-next-version.outputs.artifact_id }} + run: '[[ "$ARTIFACT_ID" =~ ^[0-9]+$ ]]' + + - name: Download the version patch + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 + with: + artifact-ids: ${{ needs.prepare-next-version.outputs.artifact_id }} + path: ${{ runner.temp }}/next-version + + - name: Require a patch that changes only version strings + env: + NEXT: ${{ needs.prepare-next-version.outputs.next }} + PATCH_FILE: ${{ runner.temp }}/next-version/next-version.patch + run: | + set -euo pipefail + [[ "$NEXT" =~ ^[0-9]+\.[0-9]+\.[0-9]+-dev$ ]] || { echo "Unexpected next version: $NEXT"; exit 1; } + awk -v next_version="$NEXT" ' + function fail(why) { print "Rejected version patch line " NR ": " why > "/dev/stderr"; bad = 1; exit 1 } + function allowed(file) { return file ~ /^(package\.json|server\.json|packages\/[a-z0-9-]+\/package\.json)$/ } + /^diff --git / { + file = substr($4, 3) + if (NF != 4 || $3 != "a/" file || !allowed(file)) fail("unexpected file") + next + } + /^index [0-9a-f]+\.\.[0-9a-f]+ 100644$/ { next } + /^--- a\// { if ($0 != "--- a/" file) fail("unexpected file"); next } + /^\+\+\+ b\// { if ($0 != "+++ b/" file) fail("unexpected file"); next } + /^@@ -[0-9]+(,1)? \+[0-9]+(,1)? @@/ { next } + /^-[ \t]*"version": "[^"]+",?$/ { next } + /^\+[ \t]*"version": "[^"]+",?$/ { + if (index($0, "\"version\": \"" next_version "\"") == 0) fail("unexpected version") + next + } + { fail("unexpected content") } + ' "$PATCH_FILE" + - name: Commit the next development version env: VERSION: ${{ needs.plan.outputs.version }} + NEXT: ${{ needs.prepare-next-version.outputs.next }} + PATCH_FILE: ${{ runner.temp }}/next-version/next-version.patch run: | set -euo pipefail + if [ ! -s "$PATCH_FILE" ]; then + echo "main already builds towards $NEXT." + exit 0 + fi git config user.name 'github-actions[bot]' git config user.email '41898282+github-actions[bot]@users.noreply.github.com' + # Retried because merges can land on main while the release runs. for attempt in 1 2 3; do git fetch origin main git reset --hard origin/main - next="$(node scripts/release-version.mjs advance "$VERSION")" - if git diff --quiet; then - echo "main already builds towards $next." - exit 0 - fi + git apply --unidiff-zero "$PATCH_FILE" git add -u git commit -m "chore: mark $VERSION as released" if git push origin HEAD:main; then diff --git a/docs/agents/pull-requests.md b/docs/agents/pull-requests.md index b45736e0f5c..41489a14273 100644 --- a/docs/agents/pull-requests.md +++ b/docs/agents/pull-requests.md @@ -64,3 +64,14 @@ Update the body after each push. Open as draft only when requested or incomplete - `## Validation`: the tested SHA and receipt, command results, CI obligations, and unresolved risks. Use evidence accessible remotely. For docs-only changes, explain why runtime tests do not apply. + +## Release and signing changes + +`.github/CODEOWNERS` names the release owner for release and signing paths. +The branch ruleset on `main` and `0.22` requires the code owner's review for a PR that changes these paths. +A PR that changes no owned path needs no approval. +The release owner cannot approve a PR that they opened. +If the release owner opens such a PR, the release owner merges it with the admin bypass. +Use the admin bypass only for a reviewed release or signing change. Record the reason in the PR. +A job that holds a release secret runs only owned paths. +Do not add an unowned script, a dependency install, or a planned-source build to such a job. From 494dd6757302d3581dcd5b2cda8a3918507f9e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 5 Dec 2026 14:15:57 +0100 Subject: [PATCH 2/5] test(release): pin the release push key to its code-free job --- test/ci/release-workflow.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/ci/release-workflow.test.ts b/test/ci/release-workflow.test.ts index d8e78c3efd9..b9cbd663634 100644 --- a/test/ci/release-workflow.test.ts +++ b/test/ci/release-workflow.test.ts @@ -66,6 +66,7 @@ test('the publisher authenticates through OIDC alone', () => { expect(withSecrets).toEqual([ ['build', ['ANDROID_HELPER_KEYSTORE_BASE64', 'ANDROID_HELPER_KEYSTORE_PASSWORD']], ['redeploy-site', ['VERCEL_SITE_DEPLOY_HOOK']], + ['mark-released', ['RELEASE_PUSH_DEPLOY_KEY']], ]); const setupNode = workflow.jobs.publish?.steps?.find((step) => step.uses?.startsWith('actions/setup-node@'), @@ -103,6 +104,18 @@ test('the Android signing rehearsal validates version changes without release cr expect(rehearsal.jobs['package-helpers']?.needs).toEqual(['compile-helpers', 'sign-helpers']); }); +// The deploy key bypasses the branch ruleset on main, so its job runs no repository code: it +// checks out main, validates the patch from the unprivileged job, and pushes. +test('the release push key reaches only a job that runs no repository code', () => { + const job = workflow.jobs['mark-released']; + expect(job?.environment).toBe('release'); + expect(job?.needs).toEqual(['plan', 'prepare-next-version']); + const steps = job?.steps ?? []; + expect(steps.filter((step) => step.uses?.startsWith('./'))).toEqual([]); + expect(JSON.stringify(steps)).not.toMatch(/pnpm|scripts\//); + expect(secretsOf(workflow.jobs['prepare-next-version'] ?? {})).toEqual([]); +}); + test('release publication follows the build directly', () => { expect(workflow.jobs.build?.needs).toBe('plan'); expect(workflow.jobs.publish?.needs).toEqual(['plan', 'build']); From 813f53a706eac64cd7e50e03a47fd04cafb1e4ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 5 Dec 2026 14:23:47 +0100 Subject: [PATCH 3/5] ci(release): download the version patch to its expected path --- .github/workflows/release.yml | 1 + test/ci/release-workflow.test.ts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6fc901882bd..0b0e61792cd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -398,6 +398,7 @@ jobs: with: artifact-ids: ${{ needs.prepare-next-version.outputs.artifact_id }} path: ${{ runner.temp }}/next-version + merge-multiple: true - name: Require a patch that changes only version strings env: diff --git a/test/ci/release-workflow.test.ts b/test/ci/release-workflow.test.ts index b9cbd663634..369aed807f1 100644 --- a/test/ci/release-workflow.test.ts +++ b/test/ci/release-workflow.test.ts @@ -113,6 +113,9 @@ test('the release push key reaches only a job that runs no repository code', () const steps = job?.steps ?? []; expect(steps.filter((step) => step.uses?.startsWith('./'))).toEqual([]); expect(JSON.stringify(steps)).not.toMatch(/pnpm|scripts\//); + // An ID download without merge-multiple nests the file under the artifact name. + const download = steps.find((step) => step.uses?.startsWith('actions/download-artifact@')); + expect(download?.with?.['merge-multiple']).toBe(true); expect(secretsOf(workflow.jobs['prepare-next-version'] ?? {})).toEqual([]); }); From e2a43b905ebc729510ad39ce80789be70dd381b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 5 Dec 2026 15:18:22 +0100 Subject: [PATCH 4/5] ci(release): tolerate a moved main, keep the patch for approvals, and trim guidance --- .github/CODEOWNERS | 3 ++- .github/workflows/release.yml | 18 +++++++++++++++--- docs/agents/pull-requests.md | 10 ++-------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 3d10f73bed3..eefb2f75e16 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,6 +1,7 @@ # Release and signing paths need the release owner's review. The branch ruleset on main and 0.22 # requires code-owner review and no other approvals, so other changes merge as before. -# Jobs that hold release secrets run only these paths. See docs/agents/pull-requests.md. +# Target: jobs that hold release secrets run only these paths. Until the Android helper signing +# split lands, the Build job in release.yml is the known exception. See docs/agents/pull-requests.md. /.github/ @thymikee /scripts/release-* @thymikee /scripts/*android-helper* @thymikee diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0b0e61792cd..b436bacfa3d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -367,7 +367,8 @@ jobs: with: name: next-version-${{ needs.plan.outputs.version }} path: ${{ runner.temp }}/next-version.patch - retention-days: 1 + # The push job may wait for an environment approval or a rerun. + retention-days: 30 # main must never carry a published version. The ruleset on main lets only admins and deploy # keys push without a PR. The push key is a deploy key that only the `release` environment holds, @@ -444,9 +445,20 @@ jobs: for attempt in 1 2 3; do git fetch origin main git reset --hard origin/main - git apply --unidiff-zero "$PATCH_FILE" + if ! git apply --unidiff-zero "$PATCH_FILE"; then + # Another release or a manual commit can move main first. + current="$(sed -n 's/^ "version": "\(.*\)",$/\1/p' package.json)" + if [ "$current" != "$VERSION-dev" ]; then + echo "main already moved past $VERSION to $current." + exit 0 + fi + echo "The version patch does not apply to main at $current." + exit 1 + fi git add -u - git commit -m "chore: mark $VERSION as released" + # A deploy-key push starts workflows. The release planner treats version-only commits + # as having no CI run, so the bump skips CI. + git commit -m "chore: mark $VERSION as released [skip ci]" if git push origin HEAD:main; then exit 0 fi diff --git a/docs/agents/pull-requests.md b/docs/agents/pull-requests.md index 41489a14273..a9a9482fde0 100644 --- a/docs/agents/pull-requests.md +++ b/docs/agents/pull-requests.md @@ -67,11 +67,5 @@ Update the body after each push. Open as draft only when requested or incomplete ## Release and signing changes -`.github/CODEOWNERS` names the release owner for release and signing paths. -The branch ruleset on `main` and `0.22` requires the code owner's review for a PR that changes these paths. -A PR that changes no owned path needs no approval. -The release owner cannot approve a PR that they opened. -If the release owner opens such a PR, the release owner merges it with the admin bypass. -Use the admin bypass only for a reviewed release or signing change. Record the reason in the PR. -A job that holds a release secret runs only owned paths. -Do not add an unowned script, a dependency install, or a planned-source build to such a job. +A job that holds a release secret runs only paths that `.github/CODEOWNERS` owns. +The release owner merges their own owned-path PR with the admin bypass and records the reason. From 18b31232ddef461290348c3d72d1bbf418ff2eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 5 Dec 2026 15:29:46 +0100 Subject: [PATCH 5/5] ci(release): read main's version as JSON before skipping the bump --- .github/workflows/release.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b436bacfa3d..d4f2d515adc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -447,8 +447,8 @@ jobs: git reset --hard origin/main if ! git apply --unidiff-zero "$PATCH_FILE"; then # Another release or a manual commit can move main first. - current="$(sed -n 's/^ "version": "\(.*\)",$/\1/p' package.json)" - if [ "$current" != "$VERSION-dev" ]; then + current="$(node -e 'process.stdout.write(JSON.parse(require("fs").readFileSync("package.json", "utf8")).version ?? "")')" + if [ -n "$current" ] && [ "$current" != "$VERSION-dev" ]; then echo "main already moved past $VERSION to $current." exit 0 fi @@ -456,8 +456,8 @@ jobs: exit 1 fi git add -u - # A deploy-key push starts workflows. The release planner treats version-only commits - # as having no CI run, so the bump skips CI. + # A deploy-key push starts workflows. Without a CI run, the release planner reads a + # version-only head's CI from its parent, as it did for GITHUB_TOKEN pushes. git commit -m "chore: mark $VERSION as released [skip ci]" if git push origin HEAD:main; then exit 0