Skip to content

Commit d290bd4

Browse files
committed
no-mistakes(review): gate latest-regression before npm publish; clean unpushed-branch die
1 parent bc2abfb commit d290bd4

5 files changed

Lines changed: 91 additions & 11 deletions

File tree

‎docs/RELEASING.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,9 @@ The converse is enforced: `finish-release` refuses to tag a patch on a line olde
642642
that already exists (`v1.2.3` once `v1.3.0` exists), because the deploy would never resolve it.
643643
So a maintenance patch is for a line that is still the newest release. The same holds on npm:
644644
`release.mjs` publishes to `latest`, and a patch cut after a newer minor shipped would move
645-
`latest` backwards.
645+
`latest` backwards — so `release.mjs` refuses, in its preflight and before anything is
646+
published, any version older than the newest release tag (resolved the same way the site
647+
deploy resolves its tag). It offers no non-`latest` dist-tag path.
646648
647649
**Then bring the fix to `main`.** A maintenance branch is never merged back wholesale (its
648650
version bumps and CHANGELOG would collide with `main`'s). Cherry-pick or re-land each fix on

‎scripts/finish-release.mjs‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { dirname, join, resolve } from "node:path";
3737
import { fileURLToPath } from "node:url";
3838
import { mavenVersion } from "./maven-coordinate.mjs";
3939
import { ejectReleaseRefusalAt } from "./eject-release-gate.mjs";
40-
import { releaseBranchRefusal } from "./lib/release-branch.mjs";
40+
import { releaseBranchRefusal, newestNpmReleaseTag } from "./lib/release-branch.mjs";
4141

4242
const REPO = resolve(dirname(fileURLToPath(import.meta.url)), "..");
4343
const CHECK_ONLY = process.argv.includes("--check");
@@ -386,13 +386,9 @@ ok("the llms mirrors state this release");
386386
// newest tag of a frozen line and passes green forever. After the 1.0 cut it would have
387387
// resolved v0.25.0 at every future release, so the check could never fire again — the same
388388
// defect that kept the live site on 0.25.0 with every deploy step green. Nothing here needs
389-
// maintaining at the next major.
390-
const resolved = out(`git tag -l 'v*' | grep -E '^v[0-9]+\\.[0-9]+\\.[0-9]+$' | sort -rV || true`)
391-
.split("\n").map((t) => t.trim()).filter(Boolean)
392-
.find((t) => {
393-
const pkg = out(`git show ${t}:server/typescript/packages/cli/package.json 2>/dev/null || true`);
394-
try { return JSON.parse(pkg).version === t.slice(1); } catch { return false; }
395-
}) ?? "";
389+
// maintaining at the next major. The selector itself is shared with `release.mjs`
390+
// (scripts/lib/release-branch.mjs), so the two cannot disagree about the npm line.
391+
const resolved = newestNpmReleaseTag(out);
396392
const wouldResolve = [resolved, tag].filter(Boolean).sort((a, b) =>
397393
a.localeCompare(b, undefined, { numeric: true })).at(-1);
398394
if (wouldResolve !== tag) {

‎scripts/lib/release-branch.mjs‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,46 @@ export function releaseBranchRefusal(branch, version) {
3636
}
3737
return null;
3838
}
39+
40+
/**
41+
* The newest tag on the npm release line, the way the site deploy resolves it: the newest
42+
* `vN.N.N` whose `server/typescript/packages/cli/package.json` is versioned as the tag —
43+
* the property that DEFINES the npm line, never a version prefix (the JVM `v7.20.12` ships
44+
* cli `0.20.11` and must not count). `""` when no release tag exists.
45+
*
46+
* @param {(cmd: string) => string} out run a command and return its trimmed stdout, like
47+
* each script's own `out`
48+
* @returns {string}
49+
*/
50+
export function newestNpmReleaseTag(out) {
51+
return out(`git tag -l 'v*' | grep -E '^v[0-9]+\\.[0-9]+\\.[0-9]+$' | sort -rV || true`)
52+
.split("\n").map((t) => t.trim()).filter(Boolean)
53+
.find((t) => {
54+
const pkg = out(`git show ${t}:server/typescript/packages/cli/package.json 2>/dev/null || true`);
55+
try { return JSON.parse(pkg).version === t.slice(1); } catch { return false; }
56+
}) ?? "";
57+
}
58+
59+
/**
60+
* Why `version` may not be released while `newestTag` is the newest release tag, or `null`
61+
* when it may. `bun publish` tags `latest`, so a version older than the newest release
62+
* would move `latest` backwards — including an `-rc` cut on a line a newer release passed.
63+
*
64+
* @param {string} version the version being cut (`1.2.4`, or `1.2.4-rc.1`)
65+
* @param {string} newestTag the newest npm-line release tag (`v1.3.0`), or `""` if none
66+
* @returns {string | null}
67+
*/
68+
export function latestRegressionRefusal(version, newestTag) {
69+
if (newestTag === "") return null;
70+
const a = /^(\d+)\.(\d+)\.(\d+)/.exec(version);
71+
const b = /^v(\d+)\.(\d+)\.(\d+)$/.exec(newestTag);
72+
if (a === null || b === null) return null;
73+
for (let i = 1; i <= 3; i++) {
74+
if (Number(a[i]) === Number(b[i])) continue;
75+
if (Number(a[i]) > Number(b[i])) return null;
76+
return `${version} is older than ${newestTag.slice(1)}, the newest release — npm publishes to ` +
77+
`\`latest\`, so this would move \`latest\` backwards. A patch on a line a newer release ` +
78+
`has passed needs a non-\`latest\` dist-tag path this script does not yet offer.`;
79+
}
80+
return null;
81+
}

‎scripts/release.mjs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { createInterface } from "node:readline/promises";
3333
import { publishSet } from "./publish-set.mjs";
3434
import { mavenVersion } from "./maven-coordinate.mjs";
3535
import { ejectReleaseRefusalAt } from "./eject-release-gate.mjs";
36-
import { releaseBranchRefusal } from "./lib/release-branch.mjs";
36+
import { releaseBranchRefusal, newestNpmReleaseTag, latestRegressionRefusal } from "./lib/release-branch.mjs";
3737

3838
const VERSION = process.argv[2];
3939
const DRY = process.argv.includes("--dry-run");
@@ -78,6 +78,9 @@ const branch = out("git rev-parse --abbrev-ref HEAD");
7878
const branchRefusal = releaseBranchRefusal(branch, VERSION);
7979
if (branchRefusal !== null) die(branchRefusal);
8080
sh("git fetch origin", { quiet: true });
81+
if (out(`git rev-parse --verify --quiet origin/${branch} || true`) === "") {
82+
die(`${branch} has no origin/${branch} — push the branch first`);
83+
}
8184
if (out(`git rev-list --count HEAD..origin/${branch}`) !== "0") die(`${branch} is behind origin/${branch} — pull first`);
8285

8386
// Clean tree, except the CHANGELOG (we promote its [Unreleased] section) and untracked noise.
@@ -87,6 +90,13 @@ if (dirty.length) die(`uncommitted changes:\n${dirty.join("\n")}\n(commit or sta
8790

8891
if (out(`git tag -l v${VERSION}`)) die(`tag v${VERSION} already exists`);
8992

93+
// `bun publish` tags `latest`, so a version older than the newest release would move
94+
// `latest` backwards — finish-release gate 6 catches that only after the publish; this
95+
// refuses it before anything irreversible. Same npm-line tag resolution the site deploy
96+
// uses (scripts/lib/release-branch.mjs).
97+
const latestRefusal = latestRegressionRefusal(VERSION, newestNpmReleaseTag(out));
98+
if (latestRefusal !== null) die(latestRefusal);
99+
90100
// Can we publish AT ALL? Checked here, before the version bump, because the bump is
91101
// committed and pushed long before the first `bun publish` — so discovering a dead
92102
// credential at the publish step strands the release mid-flight. The 0.24.0 cut found

‎scripts/test-release-branch.mjs‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// node scripts/test-release-branch.mjs
55

6-
import { releaseBranchRefusal } from "./lib/release-branch.mjs";
6+
import { releaseBranchRefusal, latestRegressionRefusal, newestNpmReleaseTag } from "./lib/release-branch.mjs";
77

88
let fails = 0;
99
const check = (cond, label) => (cond ? console.log(`ok: ${label}`) : (console.error(`FAIL: ${label}`), fails++));
@@ -35,6 +35,35 @@ check(refused("HEAD", "1.2.2"), "a detached HEAD is refused");
3535
check(releaseBranchRefusal("release-prep", "1.2.2")?.includes("not on main") === true,
3636
"the refusal for an ordinary branch still says it is not on main");
3737

38+
// `latest` never moves backwards: `bun publish` tags `latest`, so a version older than the
39+
// newest release must be refused. The oracle is npm's own dist-tag semantics: `latest`
40+
// resolves to whichever version was published last, so publishing an older one regresses it.
41+
check(latestRegressionRefusal("1.2.4", "v1.3.0") !== null,
42+
"a version older than the newest release is refused");
43+
check(latestRegressionRefusal("1.2.4-rc.1", "v1.3.0") !== null,
44+
"an RC on a line a newer release passed is refused too");
45+
check(latestRegressionRefusal("1.3.1", "v1.3.0") === null,
46+
"a version newer than the newest release passes");
47+
check(latestRegressionRefusal("1.2.4", "v1.2.3") === null,
48+
"a patch on the newest release line passes");
49+
check(latestRegressionRefusal("1.2.4", "") === null,
50+
"no released tag yet passes");
51+
check(latestRegressionRefusal("1.2.4", "v1.3.0")?.includes("`latest` backwards") === true,
52+
"the refusal names the `latest` constraint");
53+
54+
// The newest release is resolved by the property that defines the npm line (deploy.yml's
55+
// selector): the newest `vN.N.N` whose cli/package.json is versioned as the tag. A version
56+
// prefix would wrongly pick `v8.2.2` (no cli tree) or the JVM `v7.20.12` (cli 0.20.11).
57+
const cliOf = new Map([["v1.3.0", "1.3.0"], ["v1.2.2", "1.2.2"], ["v7.20.12", "0.20.11"]]);
58+
const fakeOut = (cmd) => {
59+
if (cmd.startsWith("git tag -l")) return "v8.2.2\nv1.3.0\nv1.2.2\nv7.20.12";
60+
const t = /^git show (v[\d.]+):/.exec(cmd)?.[1];
61+
const v = t === undefined ? undefined : cliOf.get(t);
62+
return v === undefined ? "" : `{"name":"@metaobjectsdev/cli","version":"${v}"}`;
63+
};
64+
check(newestNpmReleaseTag(fakeOut) === "v1.3.0",
65+
"the newest npm-line tag wins; a treeless tag and the JVM line are skipped");
66+
3867
if (fails > 0) {
3968
console.error(`\n${fails} check(s) failed`);
4069
process.exit(1);

0 commit comments

Comments
 (0)