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 ...@@ -3,8 +3,7 @@ name: build-and-deploy
on: on:
push: push:
branches: branches: ['canary', 'releases/**']
['canary', 'releases/lts/active', 'releases/lts/maintenance', 'next-*-*']
# Run on release tags so publishing is driven by the tag push rather than # Run on release tags so publishing is driven by the tag push rather than
# the release-commit branch push (see the deploy-target step). # the release-commit branch push (see the deploy-target step).
tags: tags:
...@@ -71,7 +70,7 @@ jobs: ...@@ -71,7 +70,7 @@ jobs:
- name: Determine deploy target - name: Determine deploy target
# 'force-preview' performs a full preview build but only if acknowledged i.e. workflow_dispatch # '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. # '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 id: deploy-target
run: | run: |
RELEASE_VERSION="$(node ./scripts/check-is-release.js 2> /dev/null || :)" RELEASE_VERSION="$(node ./scripts/check-is-release.js 2> /dev/null || :)"
...@@ -111,9 +110,7 @@ jobs: ...@@ -111,9 +110,7 @@ jobs:
echo "release_environment=$RELEASE_ENVIRONMENT" >> $GITHUB_OUTPUT echo "release_environment=$RELEASE_ENVIRONMENT" >> $GITHUB_OUTPUT
fi fi
elif [[ ''"${GIT_REF}"'' == 'refs/heads/canary' || elif [[ ''"${GIT_REF}"'' == 'refs/heads/canary' ||
''"${GIT_REF}"'' == 'refs/heads/releases/lts/active' || ''"${GIT_REF}"'' == refs/heads/releases/* ]]
''"${GIT_REF}"'' == 'refs/heads/releases/lts/maintenance' ||
''"${GIT_REF}"'' == refs/heads/next-*-* ]]
then then
echo "value=staging" >> $GITHUB_OUTPUT echo "value=staging" >> $GITHUB_OUTPUT
elif [ '${{ github.event_name }}' == 'workflow_dispatch' ] elif [ '${{ github.event_name }}' == 'workflow_dispatch' ]
...@@ -675,6 +672,10 @@ jobs: ...@@ -675,6 +672,10 @@ jobs:
merge-multiple: true merge-multiple: true
path: crates/wasm 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 - name: Create GitHub App token
id: release-app-token id: release-app-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
......
...@@ -2,8 +2,7 @@ name: build-and-test ...@@ -2,8 +2,7 @@ name: build-and-test
on: on:
push: push:
branches: branches: ['canary', 'releases/**']
['canary', 'releases/lts/active', 'releases/lts/maintenance', 'next-*-*']
pull_request: pull_request:
types: [opened, synchronize] 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: {} ...@@ -15,8 +15,8 @@ permissions: {}
jobs: jobs:
update_dev_manifest: update_dev_manifest:
name: Update and upload Rspack development test manifest name: Update and upload Rspack development test manifest
if: github.repository_owner == 'vercel'
runs-on: ubuntu-latest runs-on: ubuntu-latest
environment: bot-autonomous
permissions: permissions:
# Used by `gh api` in test/update-bundler-manifest.js to list and download # Used by `gh api` in test/update-bundler-manifest.js to list and download
# test result artifacts. # test result artifacts.
...@@ -85,8 +85,8 @@ jobs: ...@@ -85,8 +85,8 @@ jobs:
PR_BODY: This auto-generated PR updates the development integration test manifest used when testing Rspack. PR_BODY: This auto-generated PR updates the development integration test manifest used when testing Rspack.
update_build_manifest: update_build_manifest:
name: Update and upload Rspack production test manifest name: Update and upload Rspack production test manifest
if: github.repository_owner == 'vercel'
runs-on: ubuntu-latest runs-on: ubuntu-latest
environment: bot-autonomous
permissions: permissions:
# Used by `gh api` in test/update-bundler-manifest.js to list and download # Used by `gh api` in test/update-bundler-manifest.js to list and download
# test result artifacts. # test result artifacts.
......
...@@ -28,8 +28,9 @@ concurrency: ...@@ -28,8 +28,9 @@ concurrency:
jobs: jobs:
evaluate: 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 runs-on: ubuntu-latest
environment: bot-autonomous
permissions: permissions:
contents: read contents: read
outputs: outputs:
......
...@@ -29,6 +29,11 @@ on: ...@@ -29,6 +29,11 @@ on:
default: false default: false
type: boolean type: boolean
dryRun:
description: pass --dry-run to start-release.js (no tag, no release)
default: false
type: boolean
name: Trigger Release name: Trigger Release
env: env:
...@@ -40,8 +45,11 @@ permissions: {} ...@@ -40,8 +45,11 @@ permissions: {}
jobs: jobs:
start: start:
if: github.repository_owner == 'vercel'
runs-on: ubuntu-latest 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: env:
NEXT_TELEMETRY_DISABLED: 1 NEXT_TELEMETRY_DISABLED: 1
...@@ -137,7 +145,7 @@ jobs: ...@@ -137,7 +145,7 @@ jobs:
run: pnpm install run: pnpm install
- if: steps.new-commits.outputs.has_new_commits == 'true' - 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: env:
RELEASE_GITHUB_TOKEN: ${{ steps.release-app-token.outputs.token }} RELEASE_GITHUB_TOKEN: ${{ steps.release-app-token.outputs.token }}
RELEASE_GITHUB_APP_SLUG: ${{ steps.release-app-token.outputs.app-slug }} RELEASE_GITHUB_APP_SLUG: ${{ steps.release-app-token.outputs.app-slug }}
......
...@@ -7,10 +7,13 @@ on: ...@@ -7,10 +7,13 @@ on:
# Allow manual runs # Allow manual runs
workflow_dispatch: workflow_dispatch:
permissions:
contents: read
jobs: jobs:
create-pull-request: create-pull-request:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.repository_owner == 'vercel' environment: bot-autonomous
steps: steps:
- name: Create GitHub App token - name: Create GitHub App token
id: release-app-token id: release-app-token
......
...@@ -19,6 +19,7 @@ env: ...@@ -19,6 +19,7 @@ env:
jobs: jobs:
create-pull-request: create-pull-request:
runs-on: ubuntu-latest runs-on: ubuntu-latest
environment: bot-autonomous
permissions: permissions:
# The built-in token is only used to read the facebook/react compare API # The built-in token is only used to read the facebook/react compare API
# for the changelog. Everything that writes to this repository # for the changelog. Everything that writes to this repository
...@@ -71,8 +72,10 @@ jobs: ...@@ -71,8 +72,10 @@ jobs:
- name: Create Pull Request - name: Create Pull Request
shell: bash 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: env:
ACTOR: ${{ github.actor }}
INPUT_VERSION: ${{ inputs.version }}
# Only used to authenticate the facebook/react compare API request # Only used to authenticate the facebook/react compare API request
# that builds the changelog, so it doesn't hit anonymous rate limits. # that builds the changelog, so it doesn't hit anonymous rate limits.
# The commits, branch, and Pull Request all use the app token below. # The commits, branch, and Pull Request all use the app token below.
......
...@@ -36,6 +36,29 @@ commit and tag. That tag then triggers ...@@ -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 which builds the packages and publishes them to npm under the dist-tag matching
the channel. 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 happen on `canary` and the two long-lived LTS branches
`releases/lts/active` (the current major's release line) and `releases/lts/active` (the current major's release line) and
`releases/lts/maintenance` (the previous major's). The LTS branches are `releases/lts/maintenance` (the previous major's). The LTS branches are
...@@ -58,23 +81,39 @@ branch or tag the release was dispatched from: ...@@ -58,23 +81,39 @@ branch or tag the release was dispatched from:
### Releases based on older tags ### 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 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 the 15.x line has moved on — create a branch from that tag under the
does not matter functionally; by convention we use the old `releases/` prefix, by convention `releases/<major>-<minor>`
`next-<major>-<minor>` pattern (`next-15-4`), and branches matching (`releases/15-4`). (The old `next-<major>-<minor>` branch names are retired;
`next-*-*` are covered by the CI push filters, so such a branch needs no existing ones are frozen and every release is tagged, so they can always be
setup. Any maintainer can create it: re-branched from their tags.) Branch creation under `releases/**` is
restricted by ruleset to the release bot, so use the
```bash [`Create Release Branch`](https://github.com/vercel/next.js/actions/workflows/create_release_branch.yml)
git push origin v15.4.8^{commit}:refs/heads/next-15-4 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, Backport the fix into the branch, then dispatch `Trigger Release` (stable,
`patch`) on it. The release commit advances the branch itself, and no LTS `patch`) on it. The dispatch requires a `bot-approved` deployment approval
refs move — newer versions of that major are already published. Publishing is (see [Approvals](#approvals-four-eyes-principle)) before the tag is created.
gated on the tag, which only the release bot can create; since such a version The release commit advances the branch itself, and no LTS refs move — newer
is below npm `latest`, it is published under the `backport` dist-tag. 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 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 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 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