Unverified Commit 354b77de authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[cd] Gate release bot credentials behind GitHub environments (#100121)

Moves access to Next.js bot behind GitHub environments to ensure the bot
only runs code that has been reviewed by at least two people with write
access.

New GitHub environments:
- `bot-autonomous`
- `bot-approved` 

## Testing

- Verified all 6 remaining key consumers on canary are covered (`git
grep RELEASE_GITHUB_APP_PRIVATE_KEY` only finds the environment-backed
mint steps).
- After settings land: dispatch canary with `force=false` right after a
release (exits early but exercises env + mint), and dispatch stable with
`dryRun=true` to watch the `bot-approved` approval gate trigger with no
side effects.
- The nightly canary is the real soak test for `bot-autonomous`.

Backports: #100123 (`releases/lts/active`), #100124
(`releases/lts/maintenance`)

---------
Co-authored-by: 's avatarClaude Code <noreply@anthropic.com>
parent 7ece5e6e
......@@ -3,8 +3,7 @@ name: build-and-deploy
on:
push:
branches:
['canary', 'releases/lts/active', 'releases/lts/maintenance', 'next-*-*']
branches: ['canary', 'releases/**']
# Run on release tags so publishing is driven by the tag push rather than
# the release-commit branch push (see the deploy-target step).
tags:
......@@ -71,7 +70,7 @@ jobs:
- name: Determine deploy target
# 'force-preview' performs a full preview build but only if acknowledged i.e. workflow_dispatch
# 'automated-preview' for pushes on branches other than the publishable ones for integration testing.
# 'staging' for canary and the LTS branches since those will eventually be published i.e. become the production build.
# 'staging' for canary and the release branches since those will eventually be published i.e. become the production build.
id: deploy-target
run: |
RELEASE_VERSION="$(node ./scripts/check-is-release.js 2> /dev/null || :)"
......@@ -111,9 +110,7 @@ jobs:
echo "release_environment=$RELEASE_ENVIRONMENT" >> $GITHUB_OUTPUT
fi
elif [[ ''"${GIT_REF}"'' == 'refs/heads/canary' ||
''"${GIT_REF}"'' == 'refs/heads/releases/lts/active' ||
''"${GIT_REF}"'' == 'refs/heads/releases/lts/maintenance' ||
''"${GIT_REF}"'' == refs/heads/next-*-* ]]
''"${GIT_REF}"'' == refs/heads/releases/* ]]
then
echo "value=staging" >> $GITHUB_OUTPUT
elif [ '${{ github.event_name }}' == 'workflow_dispatch' ]
......@@ -675,6 +672,10 @@ jobs:
merge-multiple: true
path: crates/wasm
# Un-drafting the GitHub release must stay authenticated as the bot:
# events caused by GITHUB_TOKEN (github-actions[bot]) do not trigger
# workflow runs, and release-published automations depend on the event.
# The key comes from this job's release-* environment secret.
- name: Create GitHub App token
id: release-app-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
......
......@@ -2,8 +2,7 @@ name: build-and-test
on:
push:
branches:
['canary', 'releases/lts/active', 'releases/lts/maintenance', 'next-*-*']
branches: ['canary', 'releases/**']
pull_request:
types: [opened, synchronize]
......
name: Create Release Branch
on:
workflow_dispatch:
inputs:
branchName:
description: name of the branch to create under releases/ (releases/15-4)
required: true
type: string
tagName:
description: Tag to start the branch from (v15.4.8)
required: true
type: string
permissions: {}
jobs:
create:
runs-on: ubuntu-latest
# Creating a branch from a tag needs no approval: the tag's content is
# already reviewed, and the new branch is protected like any other
# releases/** branch (PR + approval + signed commits). The environment
# restricts deployments to the default branch, so this can only be
# dispatched from canary.
environment: bot-autonomous
steps:
- name: Create GitHub App token
id: release-app-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
client-id: ${{ vars.RELEASE_GITHUB_APP_CLIENT_ID }}
private-key: ${{ secrets.RELEASE_GITHUB_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: next.js
permission-contents: write
- name: Create branch from tag
env:
GH_TOKEN: ${{ steps.release-app-token.outputs.token }}
INPUT_BRANCHNAME: ${{ inputs.branchName }}
INPUT_TAGNAME: ${{ inputs.tagName }}
run: |
set -euo pipefail
# The bot token bypasses the branch-creation ruleset, so the
# releases/ prefix and the release-tag requirement are enforced
# here instead.
case "$INPUT_BRANCHNAME" in
releases/*) ;;
*)
echo "::error::branchName must start with 'releases/' (got '$INPUT_BRANCHNAME')"
exit 1
;;
esac
case "$INPUT_BRANCHNAME" in
*..*)
echo "::error::branchName must not contain '..' (got '$INPUT_BRANCHNAME')"
exit 1
;;
esac
# Complete release-tag format only (SemVer) — rejects path
# characters and traversal like 'v/../../heads/<branch>'.
if ! printf '%s' "$INPUT_TAGNAME" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'; then
echo "::error::tagName must be a release tag like v16.4.0 or v16.5.0-canary.3 (got '$INPUT_TAGNAME')"
exit 1
fi
# Resolve via the tags namespace and require the returned ref to be
# exactly the requested tag (guards against path resolution quirks).
read -r sha type ref < <(gh api "repos/vercel/next.js/git/refs/tags/$INPUT_TAGNAME" --jq '.object.sha + " " + .object.type + " " + .ref')
if [ "$ref" != "refs/tags/$INPUT_TAGNAME" ]; then
echo "::error::tag lookup returned '$ref' instead of 'refs/tags/$INPUT_TAGNAME'"
exit 1
fi
if [ "$type" = "tag" ]; then
# Annotated tag: dereference to the commit.
sha="$(gh api "repos/vercel/next.js/git/tags/$sha" --jq .object.sha)"
fi
gh api repos/vercel/next.js/git/refs -f "ref=refs/heads/$INPUT_BRANCHNAME" -f "sha=$sha"
......@@ -15,8 +15,8 @@ permissions: {}
jobs:
update_dev_manifest:
name: Update and upload Rspack development test manifest
if: github.repository_owner == 'vercel'
runs-on: ubuntu-latest
environment: bot-autonomous
permissions:
# Used by `gh api` in test/update-bundler-manifest.js to list and download
# test result artifacts.
......@@ -85,8 +85,8 @@ jobs:
PR_BODY: This auto-generated PR updates the development integration test manifest used when testing Rspack.
update_build_manifest:
name: Update and upload Rspack production test manifest
if: github.repository_owner == 'vercel'
runs-on: ubuntu-latest
environment: bot-autonomous
permissions:
# Used by `gh api` in test/update-bundler-manifest.js to list and download
# test result artifacts.
......
......@@ -28,8 +28,9 @@ concurrency:
jobs:
evaluate:
if: ${{ github.repository_owner == 'vercel' && (github.event_name == 'workflow_dispatch' || (github.event.workflow_run.event == 'push' && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch != 'canary')) }}
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.event == 'push' && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch != 'canary') }}
runs-on: ubuntu-latest
environment: bot-autonomous
permissions:
contents: read
outputs:
......
......@@ -29,6 +29,11 @@ on:
default: false
type: boolean
dryRun:
description: pass --dry-run to start-release.js (no tag, no release)
default: false
type: boolean
name: Trigger Release
env:
......@@ -40,8 +45,11 @@ permissions: {}
jobs:
start:
if: github.repository_owner == 'vercel'
runs-on: ubuntu-latest
# Prerelease channels (and the scheduled nightly, where inputs are empty)
# run autonomously; only stable requires approval before the tag exists.
# Prerelease publishes are still gated by their release-* environments.
environment: ${{ (github.event_name == 'schedule' || inputs.releaseType != 'stable') && 'bot-autonomous' || 'bot-approved' }}
env:
NEXT_TELEMETRY_DISABLED: 1
......@@ -137,7 +145,7 @@ jobs:
run: pnpm install
- if: steps.new-commits.outputs.has_new_commits == 'true'
run: node ./scripts/start-release.js --release-type "${INPUT_RELEASETYPE}" --semver-type "${INPUT_SEMVERTYPE}"
run: node ./scripts/start-release.js --release-type "${INPUT_RELEASETYPE}" --semver-type "${INPUT_SEMVERTYPE}"${{ inputs.dryRun && ' --dry-run' || '' }}
env:
RELEASE_GITHUB_TOKEN: ${{ steps.release-app-token.outputs.token }}
RELEASE_GITHUB_APP_SLUG: ${{ steps.release-app-token.outputs.app-slug }}
......
......@@ -7,10 +7,13 @@ on:
# Allow manual runs
workflow_dispatch:
permissions:
contents: read
jobs:
create-pull-request:
runs-on: ubuntu-latest
if: github.repository_owner == 'vercel'
environment: bot-autonomous
steps:
- name: Create GitHub App token
id: release-app-token
......
......@@ -19,6 +19,7 @@ env:
jobs:
create-pull-request:
runs-on: ubuntu-latest
environment: bot-autonomous
permissions:
# The built-in token is only used to read the facebook/react compare API
# for the changelog. Everything that writes to this repository
......@@ -71,8 +72,10 @@ jobs:
- name: Create Pull Request
shell: bash
run: pnpm sync-react --actor "${{ github.actor }}" --commit --create-pull --version "${{ inputs.version }}"
run: pnpm sync-react --actor "$ACTOR" --commit --create-pull --version "$INPUT_VERSION"
env:
ACTOR: ${{ github.actor }}
INPUT_VERSION: ${{ inputs.version }}
# Only used to authenticate the facebook/react compare API request
# that builds the changelog, so it doesn't hit anonymous rate limits.
# The commits, branch, and Pull Request all use the app token below.
......
......@@ -36,6 +36,29 @@ commit and tag. That tag then triggers
which builds the packages and publishes them to npm under the dist-tag matching
the channel.
### Approvals (four-eyes principle)
The release bot's credentials are stored in GitHub environments, not in
repository secrets, so using them is gated by deployment rules:
- Prerelease channels (`canary`, `preview`, `beta`, `release-candidate`) are
_triggered_ autonomously (environment `bot-autonomous`, deployable only
from the `canary` branch and release tags). This is what keeps the nightly
canary unattended. Prerelease tags only ever point at reviewed branch
content, so creating them needs no approval.
- Only `stable` requires a deployment approval from the Next.js Engineering team
**before the release tag is created** (environment `bot-approved`). The
person who dispatched the release cannot approve it themselves.
- Publishing to npm is gated per channel: the publish job only runs in the
channel's `release-*` environment (deployable only from matching tags), and
every channel except canary (`release-stable`, `release-beta`,
`release-release-candidate`, `release-preview`) requires Next.js
Engineering approval there.
So a stable release is approved twice — once before its tag exists and once
before the packages reach npm — every other prerelease is approved once (at
publish time), and a canary release never.
Releases happen on `canary` and the two long-lived LTS branches
`releases/lts/active` (the current major's release line) and
`releases/lts/maintenance` (the previous major's). The LTS branches are
......@@ -58,23 +81,39 @@ branch or tag the release was dispatched from:
### Releases based on older tags
To make a change based on an older tag — e.g. a fix for the 15.4.x line once
the 15.x line has moved on — create a branch from that tag. The branch name
does not matter functionally; by convention we use the old
`next-<major>-<minor>` pattern (`next-15-4`), and branches matching
`next-*-*` are covered by the CI push filters, so such a branch needs no
setup. Any maintainer can create it:
```bash
git push origin v15.4.8^{commit}:refs/heads/next-15-4
```
the 15.x line has moved on — create a branch from that tag under the
`releases/` prefix, by convention `releases/<major>-<minor>`
(`releases/15-4`). (The old `next-<major>-<minor>` branch names are retired;
existing ones are frozen and every release is tagged, so they can always be
re-branched from their tags.) Branch creation under `releases/**` is
restricted by ruleset to the release bot, so use the
[`Create Release Branch`](https://github.com/vercel/next.js/actions/workflows/create_release_branch.yml)
workflow (dispatch on `canary` with `branchName=releases/15-4` and
`tagName=v15.4.8`). Any maintainer can dispatch it and no approval is needed —
the tag's content is already reviewed, and the new branch is protected like
any other `releases/**` branch. Branches can only be created from release
tags (`v*`).
Branches matching `releases/**` are covered by the CI push filters, so such a
branch needs no further setup.
If the branch is cut from a tag that predates the environment-based bot
credentials, its workflow files still expect the old repository-level bot
secret. Backport https://github.com/vercel/next.js/pull/100121 (the change
that moved the bot credentials into GitHub environments) onto the new branch
before dispatching `Trigger Release` on it — otherwise the App-token mint
fails.
Backport the fix into the branch, then dispatch `Trigger Release` (stable,
`patch`) on it. The release commit advances the branch itself, and no LTS
refs move — newer versions of that major are already published. Publishing is
gated on the tag, which only the release bot can create; since such a version
is below npm `latest`, it is published under the `backport` dist-tag.
`patch`) on it. The dispatch requires a `bot-approved` deployment approval
(see [Approvals](#approvals-four-eyes-principle)) before the tag is created.
The release commit advances the branch itself, and no LTS refs move — newer
versions of that major are already published. Publishing is additionally
gated on the `release-stable` environment, and since such a version is below
npm `latest`, it is published under the `backport` dist-tag.
For a one-shot release that needs no changes (e.g. a release cut from an
older canary tag), no branch is needed: dispatching `Trigger Release` on a
tag performs a tag-only release — the release commit lands only on the new
tag — and the version-based rules above still move the LTS refs.
tag — and the version-based rules above still move the LTS refs. The same
`bot-approved` approval applies for stable-line releases.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment