Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +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.
# 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
Comment thread
thymikee marked this conversation as resolved.
Resolved
/scripts/release-* @thymikee
Comment thread
thymikee marked this conversation as resolved.
Resolved
/scripts/*android-helper* @thymikee
Comment thread
thymikee marked this conversation as resolved.
Resolved
Comment thread
thymikee marked this conversation as resolved.
Resolved
113 changes: 103 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -330,42 +330,135 @@ 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
# 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,
# 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
merge-multiple: true

- 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; }
Comment thread
thymikee marked this conversation as resolved.
Resolved
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)$/ }
Comment thread
thymikee marked this conversation as resolved.
Resolved
/^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
if ! git apply --unidiff-zero "$PATCH_FILE"; then
# Another release or a manual commit can move main first.
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
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. 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
Comment thread
thymikee marked this conversation as resolved.
Resolved
exit 0
fi
Expand Down
5 changes: 5 additions & 0 deletions docs/agents/pull-requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ 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

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.
16 changes: 16 additions & 0 deletions test/ci/release-workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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@'),
Expand Down Expand Up @@ -103,6 +104,21 @@ 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\//);
// 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([]);
});

test('release publication follows the build directly', () => {
expect(workflow.jobs.build?.needs).toBe('plan');
expect(workflow.jobs.publish?.needs).toEqual(['plan', 'build']);
Expand Down
Loading