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

[cd] Support non-LTS releases (#99948)

#99807 replaced versioned release branches with the fixed
`releases/lts/active` + `releases/lts/maintenance` refs. This PR builds
the complete story for releases that do not fit those two branches, in
four parts:

**1. Purely version-based LTS ref adjustment** (revises the routing
merged in #99807)

`updateLtsBranchRefs` no longer looks at `semverType` at all. After a
stable release it compares only the released version
(`readReleaseVersion()`) against npm, and it never matters which branch
or tag the release was dispatched from:

- released version starts a **new major** → `releases/lts/maintenance`
takes `releases/lts/active`'s position, then `releases/lts/active` moves
to the new tag
- on the **latest published major** (npm `latest`) and newer than
everything published in that line → `releases/lts/active` moves to the
new tag
- on the **previous major** and newer than everything published in that
line → `releases/lts/maintenance` moves to the new tag
- anything else (older versions, prerelease channels) → no refs move

The "newer than everything published in that line" check resolves the
caret range of the released version against npm (equivalent to `npm view
next@^<version> version`), doubling as a no-rewind guard: an errant
release cut on an old line (e.g. 15.5.0 while 15.7.x is published)
cannot drag a branch backwards. This also fixes the gap the old
patch-does-nothing rule had: releasing 16.5.0 from the
`v16.5.0-canary.1` tag while canary sits at `16.5.0-canary.2` moves
`active` as it should.

**2. Tag-dispatched (detached HEAD) releases**

Dispatching `Trigger Release` on a tag — e.g. cutting a stable version
from an older canary tag — performs a tag-only release: the signed
release commit lives only on the new tag and pushes no branch; the
version-based rules above then move the LTS refs exactly as for any
other dispatch. The tag push drives `build_and_deploy` as usual, and
`sync_backport_canary_release` advances canary afterwards when the
release is semver-ahead of it. (Dispatching on a tag runs the tag's own
workflow and scripts, so this takes effect for tags cut after this
lands; pre-existing `next-*` branches remain usable for older lines in
the meantime.)

**3. Zero-setup branches for changes based on older tags**

A tag-only release cannot carry changes, so a fix for an older line
(e.g. 15.4.x once 15.x has moved on) gets a branch. The name is
functionally irrelevant — by convention we keep the old
`next-<major>-<minor>` pattern — and any maintainer can create it with
no workflow and no setup commit, because publishing is gated on
bot-created tags, not on branches:

```bash
git push origin v15.4.8^{commit}:refs/heads/next-15-4
```

The `build_and_test.yml` / `build_and_deploy.yml` push filters include
`next-*-*`, and the staging deploy-target condition globs
`refs/heads/next-*-*`, so CI and the pre-publish build run on pushes
automatically. Backport the fix, dispatch `Trigger Release` (stable,
`patch`) on the branch, and the bot-created tag drives the publish; no
LTS refs move since newer versions of that major are already published.

**4. `scripts/release-branches.json` removed**

Its only consumer was the `version-bump.js` branch gate
(`assertBranchIsAllowed` / `--allow-branch`), which protected nothing
the publish path doesn't already protect: tags are bot-only, real
releases run through the workflow's app credentials, and the gate read
per-branch content so it could never stop a determined actor. The gate,
the flag, and the bypass call sites in `start-release.js` /
`set-preview-version.js` are gone.

Docs and the `backport-pr` skill describe the new model: LTS branches by
default, a "Releases based on older tags" section covering both flows
(branch + backport + dispatch for changes, tag dispatch for no-change
one-shots).

## Verification

All as `node ./scripts/start-release.js --release-type <t> --semver-type
<s> --dry-run` (mock client, zero API calls):

- attached **patch** (16.5.0 > npm latest 16.4.0) → `PATCH
refs/heads/releases/lts/active` to the tag SHA
- attached **minor** → same move; attached **major** → `maintenance`
move (active's pre-move tip) before the `active` move
- attached **canary** → zero LTS ref API calls
- **detached** patch (the canary.1 scenario) → tag-only release (no
branch PATCH from the release commit) **plus** the `releases/lts/active`
move

---------
Co-authored-by: 's avatarClaude Code <noreply@anthropic.com>
parent 52a822cf
......@@ -18,13 +18,17 @@ branch.
## Inputs
- Require a PR number and a target release branch:
`releases/lts/active` (the current major's release line) or
`releases/lts/maintenance` (the previous major's), depending on which
released line needs the fix.
- Require a PR number and a target release branch. Almost always the target
is one of the LTS branches: `releases/lts/active` (the current major's
release line) or `releases/lts/maintenance` (the previous major's). Only in
exceptionally rare circumstances — a fix for an older minor line that
neither LTS branch supports anymore — is the target a non-LTS branch
(`next-<major>-<minor>`, which any maintainer can create by pushing a
branch from that line's last tag).
- If the target branch is not provided and cannot be inferred confidently from
the user's request, ask before mutating git state.
- Treat the target branch as variable; do not hard-code either LTS branch
the user's request, ask before mutating git state — and default to an LTS
branch unless the user explicitly names an old minor line.
- Treat the target branch as variable; do not hard-code a specific branch
except when the user explicitly asks for it.
## Workflow
......@@ -90,10 +94,18 @@ branch.
## PR Shape
The PR title should indicate the target branch and the original PR title.
Use a title like:
```text
[backport] <original PR title>
[lts-active] <original PR title>
```
or
```text
[lts-maintenance] <original PR title>
```
Use a concise PR body:
......
......@@ -3,7 +3,8 @@ name: build-and-deploy
on:
push:
branches: ['canary', 'releases/lts/active', 'releases/lts/maintenance']
branches:
['canary', 'releases/lts/active', 'releases/lts/maintenance', 'next-*-*']
# 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:
......@@ -111,7 +112,8 @@ jobs:
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/releases/lts/maintenance' ||
''"${GIT_REF}"'' == refs/heads/next-*-* ]]
then
echo "value=staging" >> $GITHUB_OUTPUT
elif [ '${{ github.event_name }}' == 'workflow_dispatch' ]
......
......@@ -2,7 +2,8 @@ name: build-and-test
on:
push:
branches: ['canary', 'releases/lts/active', 'releases/lts/maintenance']
branches:
['canary', 'releases/lts/active', 'releases/lts/maintenance', 'next-*-*']
pull_request:
types: [opened, synchronize]
......
......@@ -36,16 +36,45 @@ commit and tag. That tag then triggers
which builds the packages and publishes them to npm under the dist-tag matching
the channel.
Version bumps are restricted to the release branches listed in
`scripts/release-branches.json`: `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/maintenance` (the previous major's). The LTS branches are created
manually, once, and from then on a stable release moves the refs automatically:
- `patch`: no ref moves — the release commit already advances the branch it was
cut on.
- `minor`: the new tag is routed by its major against the latest published
major (the npm `latest` dist-tag) — equal moves `releases/lts/active` to the
tag; latest − 1 moves `releases/lts/maintenance` to the tag.
- `major`: `releases/lts/maintenance` is moved to where `releases/lts/active`
pointed, and `releases/lts/active` is moved to the new tag.
`releases/lts/maintenance` (the previous major's). The LTS branches are
created manually, once, and from then on a stable release adjusts the refs
automatically. The rules are purely version-based — it never matters which
branch or tag the release was dispatched from:
- The released version is on the latest published major (the npm `latest`
dist-tag) and newer than everything published in that line:
`releases/lts/active` moves to the new tag.
- It is on the previous major and newer than everything published in that
line: `releases/lts/maintenance` moves to the new tag.
- It starts a new major: `releases/lts/maintenance` moves to where
`releases/lts/active` pointed, and `releases/lts/active` moves to the new
tag.
- Anything older (or a prerelease channel): no refs move. The "newer than
everything published in that line" check guards against rewinding a branch
to an older version of its line.
### 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
```
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.
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.
["canary", "releases/lts/active", "releases/lts/maintenance"]
......@@ -79,6 +79,8 @@ async function getSingleParent(commitSha) {
* Signs every local commit between the remote base and local HEAD. The release
* tag is placed on the signed commit that corresponds to the local
* release commit; the branch is fast-forwarded to the final signed commit.
* On a detached HEAD (a release triggered on a tag, for an older minor line
* that has no branch of its own) only the tag is created and no branch moves.
*
* For a normal release this is a single commit (tag == branch head). For an
* ad-hoc preview release the local history is two commits — the preview
......@@ -104,9 +106,10 @@ async function createGitHubReleaseCommit(token, options = {}) {
captureOutput: true,
})
if (branch === 'HEAD') {
throw new Error('Cannot create a GitHub release commit from detached HEAD')
}
// Detached HEAD means the release was triggered on a tag (an irregular
// release for an older minor line that has no branch of its own). The
// release commit then lives only on the new tag and no branch is moved.
const isDetachedHead = branch === 'HEAD'
const localHead = await git(['rev-parse', 'HEAD'], {
captureOutput: true,
......@@ -149,10 +152,17 @@ async function createGitHubReleaseCommit(token, options = {}) {
})
createdTag = true
await request(token, 'PATCH', `${REPO_API_PATH}/git/refs/heads/${branch}`, {
sha: headSha,
force: false,
})
if (!isDetachedHead) {
await request(
token,
'PATCH',
`${REPO_API_PATH}/git/refs/heads/${branch}`,
{
sha: headSha,
force: false,
}
)
}
} catch (error) {
if (createdTag) {
await request(
......@@ -172,14 +182,21 @@ async function createGitHubReleaseCommit(token, options = {}) {
// The signed commits only exist in the mock; there is nothing on the remote
// to sync the local branch against.
console.log(
`Dry run: skipping local branch sync; would set ${branch} to ${headSha} and tag ${tagName} at ${signedTagSha}`
isDetachedHead
? `Dry run: tag-only release (detached HEAD); would tag ${tagName} at ${signedTagSha} without moving any branch`
: `Dry run: skipping local branch sync; would set ${branch} to ${headSha} and tag ${tagName} at ${signedTagSha}`
)
} else if (isDetachedHead) {
console.log(
`Tag-only release (detached HEAD): not moving any branch; ${tagName} points at ${signedTagSha}`
)
} else {
await alignLocalBranchWithSignedCommit(branch, headSha, { tagName })
}
console.log(
`Created GitHub-signed release tag ${tagName} at ${signedTagSha}; branch ${branch} now at ${headSha}`
`Created GitHub-signed release tag ${tagName} at ${signedTagSha}` +
(isDetachedHead ? '' : `; branch ${branch} now at ${headSha}`)
)
return {
......@@ -206,12 +223,12 @@ async function getBranchSha(request, token, branch) {
}
/**
* The latest published stable major, read from npm (equivalent to
* The latest published stable version, read from npm (equivalent to
* `npm view next version`; the same dist-tags endpoint computePreviewVersion
* in start-release.js uses). Older majors publish under the `backport`
* dist-tag, so `latest` always tracks the newest release line.
*/
async function getLatestPublishedMajor() {
async function getLatestPublishedVersion() {
const res = await fetch('https://registry.npmjs.org/-/package/next/dist-tags')
const tags = await res.json()
......@@ -219,24 +236,48 @@ async function getLatestPublishedMajor() {
throw new Error('Failed to read the latest dist-tag of next from npm')
}
return semver.major(tags.latest)
return tags.latest
}
/**
* Move the long-lived LTS branch refs after a stable release:
* - patch: nothing (the release commit already advanced the branch it was cut
* on)
* - minor: routed by the released version's major against the latest
* published major (npm `latest`): equal moves `releases/lts/active` to the
* new tag, latest - 1 moves `releases/lts/maintenance` to the new tag,
* anything else moves nothing
* - major: `releases/lts/maintenance` is moved to active's previous position,
* then `releases/lts/active` is moved to the new tag
* The newest version of next published to npm satisfying the given range, or
* null. Resolved from the (abbreviated) packument — the same data
* `npm view next@<range> version` uses. The LTS ref adjustment uses this as a
* no-rewind guard: `^<released version>` matches everything newer already
* published in that major line, so a non-null result means the line moved on
* and moving the branch would rewind it.
*/
async function getNewestPublishedVersionSatisfying(range) {
const res = await fetch('https://registry.npmjs.org/next', {
headers: { accept: 'application/vnd.npm.install-v1+json' },
})
const packument = await res.json()
return semver.maxSatisfying(Object.keys(packument.versions), range)
}
/**
* Adjust the long-lived LTS branch refs after a stable release. The rules are
* purely version-based — it never matters which branch or tag the release was
* dispatched from:
*
* - the released version starts a new major: `releases/lts/maintenance` is
* moved to active's previous position, then `releases/lts/active` is moved
* to the new tag
* - it is on the latest published major (npm `latest`) and newer than
* everything published in that line: `releases/lts/active` is moved to the
* new tag
* - it is on the previous major and newer than everything published in that
* line: `releases/lts/maintenance` is moved to the new tag
* - anything else (older versions, prerelease channels): no refs move
*
* All PATCHes use `force: true` because the histories diverge (e.g. the tag
* commit for a major cut on canary is not a descendant of active's tip). When
* the release was cut on the LTS branch itself, `createGitHubReleaseCommit`
* already moved that branch to the same commit, so the move is a no-op.
* All PATCHes use `force: true` because the histories can diverge (e.g. the
* tag commit for a major cut on canary is not a descendant of active's tip).
* When the release was cut on the LTS branch itself,
* `createGitHubReleaseCommit` already moved that branch to the same commit,
* so the move is a no-op. The "newer than everything published in that line"
* check (the caret range of the released version against npm) guards against
* rewinding a branch to an older version of its line.
*
* On partial failure (maintenance moved, active move failed) no rollback is
* attempted: every target commit already exists on the remote, nothing
......@@ -245,7 +286,6 @@ async function getLatestPublishedMajor() {
*
* @param {string} token GitHub API token with repo access
* @param {object} options
* @param {'patch' | 'minor' | 'major'} options.semverType
* @param {string} options.tagName The just-created release tag (e.g. v16.3.0)
* @param {string} options.tagSha The signed commit the tag points at
* @param {import('./github-utils/signed-commit').githubRequest} [options.githubRequest]
......@@ -253,14 +293,25 @@ async function getLatestPublishedMajor() {
*/
async function updateLtsBranchRefs(
token,
{ semverType, tagName, tagSha, githubRequest: request = githubRequest }
{ tagName, tagSha, githubRequest: request = githubRequest }
) {
if (semverType === 'patch') {
console.log('Stable patch release: LTS branch refs unchanged')
// The local HEAD is the just-created release commit, so the version source
// of truth carries the released version (same assumption
// `getLocalReleaseTagName` makes).
const newVersion = readReleaseVersion()
if (semver.prerelease(newVersion)) {
console.log(`${newVersion} is a prerelease: LTS branch refs unchanged`)
return
}
if (semverType === 'major') {
const latestVersion = await getLatestPublishedVersion()
const newMajor = semver.major(newVersion)
const latestMajor = semver.major(latestVersion)
if (newMajor > latestMajor) {
// A new major line starts: maintenance inherits the active line, active
// starts the new one.
const activeSha = await getBranchSha(request, token, LTS_ACTIVE_BRANCH)
await request(
......@@ -283,34 +334,38 @@ async function updateLtsBranchRefs(
return
}
// The local HEAD is the just-created release commit, so the version source
// of truth carries the released version (same assumption
// `getLocalReleaseTagName` makes).
const newMajor = semver.major(readReleaseVersion())
const latestMajor = await getLatestPublishedMajor()
let ltsBranch
if (newMajor === latestMajor) {
await request(
token,
'PATCH',
`${REPO_API_PATH}/git/refs/heads/${LTS_ACTIVE_BRANCH}`,
{ sha: tagSha, force: true }
)
console.log(`Moved ${LTS_ACTIVE_BRANCH} to ${tagName} (${tagSha})`)
ltsBranch = LTS_ACTIVE_BRANCH
} else if (newMajor === latestMajor - 1) {
await request(
token,
'PATCH',
`${REPO_API_PATH}/git/refs/heads/${LTS_MAINTENANCE_BRANCH}`,
{ sha: tagSha, force: true }
)
console.log(`Moved ${LTS_MAINTENANCE_BRANCH} to ${tagName} (${tagSha})`)
ltsBranch = LTS_MAINTENANCE_BRANCH
} else {
console.log(
`${tagName} (major ${newMajor}) is on neither the active (major ${latestMajor}) ` +
`nor the maintenance (major ${latestMajor - 1}) line: LTS branch refs unchanged`
)
return
}
// No-rewind guard: a newer version already published in this major line
// means the line moved on (e.g. an errant release cut on an old non-LTS
// branch) and moving the branch would rewind it.
const newer = await getNewestPublishedVersionSatisfying(`^${newVersion}`)
if (newer) {
console.log(
`Not moving ${ltsBranch} to ${tagName}: npm already has ${newer} in the ` +
`${newMajor}.x line, so moving it would rewind the branch`
)
return
}
await request(
token,
'PATCH',
`${REPO_API_PATH}/git/refs/heads/${ltsBranch}`,
{ sha: tagSha, force: true }
)
console.log(`Moved ${ltsBranch} to ${tagName} (${tagSha})`)
}
/**
......
......@@ -34,13 +34,7 @@ async function main() {
await execa(
'node',
[
'scripts/version-bump.js',
version,
'--no-git-tag-version',
'--allow-branch',
'**',
],
['scripts/version-bump.js', version, '--no-git-tag-version'],
{ cwd: repoRoot, stdio: 'inherit' }
)
......
......@@ -198,13 +198,6 @@ async function main() {
versionBumpArgs.push('--preid', 'beta')
}
if (dryRun) {
// So the dry-run can be exercised outside
// of the release branches scripts/release-branches.json restricts
// real version bumps to.
versionBumpArgs.push('--allow-branch', '**')
}
const child = execa('node', versionBumpArgs, {
stdio: 'inherit',
})
......@@ -255,8 +248,6 @@ async function main() {
if (releaseType === 'stable') {
await updateLtsBranchRefs(githubToken, {
// Validated against SEMVER_TYPES above (stable always requires one).
semverType: /** @type {'patch' | 'minor' | 'major'} */ (semverType),
tagName,
tagSha: signedTagSha,
githubRequest: mockRequest,
......
......@@ -20,8 +20,6 @@
--preid <id> prerelease identifier for pre* increments
--no-git-tag-version update the manifests but do not commit or tag
--allow-branch <glob> override the branches releases may run from;
repeatable, `**` allows any branch
*/
const fs = require('fs/promises')
......@@ -32,7 +30,6 @@ const { readReleaseVersion } = require('./release-version')
const repoRoot = path.join(__dirname, '..')
const packagesDir = path.join(repoRoot, 'packages')
const releaseBranchesPath = path.join(__dirname, 'release-branches.json')
const SEMVER_INCREMENTS = new Set([
'major',
......@@ -53,8 +50,6 @@ function parseArgs(argv) {
/** @type {string | undefined} */
let preid
let gitTagVersion = true
/** @type {string[]} */
const allowBranch = []
for (let i = 0; i < argv.length; i++) {
const arg = argv[i]
......@@ -63,9 +58,6 @@ function parseArgs(argv) {
case '--preid':
preid = argv[++i]
break
case '--allow-branch':
allowBranch.push(argv[++i])
break
case '--no-git-tag-version':
gitTagVersion = false
break
......@@ -86,39 +78,7 @@ function parseArgs(argv) {
throw new Error('Missing <version|increment> argument')
}
return { versionArg, preid, gitTagVersion, allowBranch }
}
/**
* Releases are restricted to `canary` and the long-lived LTS release branches
* (`releases/lts/active`, `releases/lts/maintenance`) listed in
* `scripts/release-branches.json`.
*
* @param {string[]} allowBranchOverride
*/
async function assertBranchIsAllowed(allowBranchOverride) {
const patterns =
allowBranchOverride.length > 0
? allowBranchOverride
: JSON.parse(await fs.readFile(releaseBranchesPath, 'utf8'))
if (patterns.includes('**')) {
return
}
const { stdout: currentBranch } = await execa('git', [
'rev-parse',
'--abbrev-ref',
'HEAD',
])
if (!patterns.includes(currentBranch.trim())) {
throw new Error(
`Refusing to bump the version on branch "${currentBranch.trim()}". ` +
`Allowed branches: ${patterns.join(', ')}. ` +
`Pass \`--allow-branch **\` to override.`
)
}
return { versionArg, preid, gitTagVersion }
}
/**
......@@ -196,11 +156,7 @@ async function writeVersionToPackages(nextVersion) {
}
async function main() {
const { versionArg, preid, gitTagVersion, allowBranch } = parseArgs(
process.argv.slice(2)
)
await assertBranchIsAllowed(allowBranch)
const { versionArg, preid, gitTagVersion } = parseArgs(process.argv.slice(2))
const currentVersion = readReleaseVersion()
const nextVersion = computeNextVersion(currentVersion, versionArg, preid)
......@@ -244,6 +200,5 @@ if (require.main === module) {
module.exports = {
parseArgs,
computeNextVersion,
assertBranchIsAllowed,
writeVersionToPackages,
}
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