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. ...@@ -18,13 +18,17 @@ branch.
## Inputs ## Inputs
- Require a PR number and a target release branch: - Require a PR number and a target release branch. Almost always the target
`releases/lts/active` (the current major's release line) or is one of the LTS branches: `releases/lts/active` (the current major's
`releases/lts/maintenance` (the previous major's), depending on which release line) or `releases/lts/maintenance` (the previous major's). Only in
released line needs the fix. 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 - If the target branch is not provided and cannot be inferred confidently from
the user's request, ask before mutating git state. the user's request, ask before mutating git state — and default to an LTS
- Treat the target branch as variable; do not hard-code either LTS branch 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. except when the user explicitly asks for it.
## Workflow ## Workflow
...@@ -90,10 +94,18 @@ branch. ...@@ -90,10 +94,18 @@ branch.
## PR Shape ## PR Shape
The PR title should indicate the target branch and the original PR title.
Use a title like: Use a title like:
```text ```text
[backport] <original PR title> [lts-active] <original PR title>
```
or
```text
[lts-maintenance] <original PR title>
``` ```
Use a concise PR body: Use a concise PR body:
......
...@@ -3,7 +3,8 @@ name: build-and-deploy ...@@ -3,7 +3,8 @@ name: build-and-deploy
on: on:
push: 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 # 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:
...@@ -111,7 +112,8 @@ jobs: ...@@ -111,7 +112,8 @@ jobs:
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/lts/active' ||
''"${GIT_REF}"'' == 'refs/heads/releases/lts/maintenance' ]] ''"${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' ]
......
...@@ -2,7 +2,8 @@ name: build-and-test ...@@ -2,7 +2,8 @@ name: build-and-test
on: on:
push: push:
branches: ['canary', 'releases/lts/active', 'releases/lts/maintenance'] branches:
['canary', 'releases/lts/active', 'releases/lts/maintenance', 'next-*-*']
pull_request: pull_request:
types: [opened, synchronize] types: [opened, synchronize]
......
...@@ -36,16 +36,45 @@ commit and tag. That tag then triggers ...@@ -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 which builds the packages and publishes them to npm under the dist-tag matching
the channel. the channel.
Version bumps are restricted to the release branches listed in Releases happen on `canary` and the two long-lived LTS branches
`scripts/release-branches.json`: `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 created `releases/lts/maintenance` (the previous major's). The LTS branches are
manually, once, and from then on a stable release moves the refs automatically: created manually, once, and from then on a stable release adjusts the refs
automatically. The rules are purely version-based — it never matters which
- `patch`: no ref moves — the release commit already advances the branch it was branch or tag the release was dispatched from:
cut on.
- `minor`: the new tag is routed by its major against the latest published - The released version is on the latest published major (the npm `latest`
major (the npm `latest` dist-tag) — equal moves `releases/lts/active` to the dist-tag) and newer than everything published in that line:
tag; latest − 1 moves `releases/lts/maintenance` to the tag. `releases/lts/active` moves to the new tag.
- `major`: `releases/lts/maintenance` is moved to where `releases/lts/active` - It is on the previous major and newer than everything published in that
pointed, and `releases/lts/active` is moved to the new tag. 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"]
This diff is collapsed.
...@@ -34,13 +34,7 @@ async function main() { ...@@ -34,13 +34,7 @@ async function main() {
await execa( await execa(
'node', 'node',
[ ['scripts/version-bump.js', version, '--no-git-tag-version'],
'scripts/version-bump.js',
version,
'--no-git-tag-version',
'--allow-branch',
'**',
],
{ cwd: repoRoot, stdio: 'inherit' } { cwd: repoRoot, stdio: 'inherit' }
) )
......
...@@ -198,13 +198,6 @@ async function main() { ...@@ -198,13 +198,6 @@ async function main() {
versionBumpArgs.push('--preid', 'beta') 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, { const child = execa('node', versionBumpArgs, {
stdio: 'inherit', stdio: 'inherit',
}) })
...@@ -255,8 +248,6 @@ async function main() { ...@@ -255,8 +248,6 @@ async function main() {
if (releaseType === 'stable') { if (releaseType === 'stable') {
await updateLtsBranchRefs(githubToken, { await updateLtsBranchRefs(githubToken, {
// Validated against SEMVER_TYPES above (stable always requires one).
semverType: /** @type {'patch' | 'minor' | 'major'} */ (semverType),
tagName, tagName,
tagSha: signedTagSha, tagSha: signedTagSha,
githubRequest: mockRequest, githubRequest: mockRequest,
......
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
--preid <id> prerelease identifier for pre* increments --preid <id> prerelease identifier for pre* increments
--no-git-tag-version update the manifests but do not commit or tag --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') const fs = require('fs/promises')
...@@ -32,7 +30,6 @@ const { readReleaseVersion } = require('./release-version') ...@@ -32,7 +30,6 @@ const { readReleaseVersion } = require('./release-version')
const repoRoot = path.join(__dirname, '..') const repoRoot = path.join(__dirname, '..')
const packagesDir = path.join(repoRoot, 'packages') const packagesDir = path.join(repoRoot, 'packages')
const releaseBranchesPath = path.join(__dirname, 'release-branches.json')
const SEMVER_INCREMENTS = new Set([ const SEMVER_INCREMENTS = new Set([
'major', 'major',
...@@ -53,8 +50,6 @@ function parseArgs(argv) { ...@@ -53,8 +50,6 @@ function parseArgs(argv) {
/** @type {string | undefined} */ /** @type {string | undefined} */
let preid let preid
let gitTagVersion = true let gitTagVersion = true
/** @type {string[]} */
const allowBranch = []
for (let i = 0; i < argv.length; i++) { for (let i = 0; i < argv.length; i++) {
const arg = argv[i] const arg = argv[i]
...@@ -63,9 +58,6 @@ function parseArgs(argv) { ...@@ -63,9 +58,6 @@ function parseArgs(argv) {
case '--preid': case '--preid':
preid = argv[++i] preid = argv[++i]
break break
case '--allow-branch':
allowBranch.push(argv[++i])
break
case '--no-git-tag-version': case '--no-git-tag-version':
gitTagVersion = false gitTagVersion = false
break break
...@@ -86,39 +78,7 @@ function parseArgs(argv) { ...@@ -86,39 +78,7 @@ function parseArgs(argv) {
throw new Error('Missing <version|increment> argument') throw new Error('Missing <version|increment> argument')
} }
return { versionArg, preid, gitTagVersion, allowBranch } return { versionArg, preid, gitTagVersion }
}
/**
* 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.`
)
}
} }
/** /**
...@@ -196,11 +156,7 @@ async function writeVersionToPackages(nextVersion) { ...@@ -196,11 +156,7 @@ async function writeVersionToPackages(nextVersion) {
} }
async function main() { async function main() {
const { versionArg, preid, gitTagVersion, allowBranch } = parseArgs( const { versionArg, preid, gitTagVersion } = parseArgs(process.argv.slice(2))
process.argv.slice(2)
)
await assertBranchIsAllowed(allowBranch)
const currentVersion = readReleaseVersion() const currentVersion = readReleaseVersion()
const nextVersion = computeNextVersion(currentVersion, versionArg, preid) const nextVersion = computeNextVersion(currentVersion, versionArg, preid)
...@@ -244,6 +200,5 @@ if (require.main === module) { ...@@ -244,6 +200,5 @@ if (require.main === module) {
module.exports = { module.exports = {
parseArgs, parseArgs,
computeNextVersion, computeNextVersion,
assertBranchIsAllowed,
writeVersionToPackages, 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