Files
paseo/scripts/reconcile-release.test.mjs
T
Mohamed Boudra 01aa8b3406 Verify releases on isolated release branches and harden shipping (#10396)
* chore(release): verify releases on isolated release branches and harden shipping

High-traffic merges on main cancel more than half of main CI runs, so waiting on main CI repeatedly stalls releases. Releases also ran duplicate post-tag CI, lacked a release-branch Desktop Packages trigger, hit unretried Apple notarytool polling errors and a finalize-rollout directory bug on macOS retries, and relied on a non-idempotent npm publish chain and conflict-prone reconcile cherry-picks.

This splits release execution into release:prep:* (reversible version commit without tagging, pushed once to release/** for isolated CI + Desktop Packages) and release:ship[:beta] (idempotent npm publishing with retry, propagation checks, automatic beta dist-tag sync on stable, and release/*-only tag push), adds conflict-free main reconciliation, and extends macOS xcrun retries to notarytool submit and wait.

* fix(release): address review findings on Docker retries, tag push, and reconciliation

Isolate manual Docker publish dispatches in their own non-cancelling concurrency group, verify HEAD matches origin/<release-branch> before release:ship publishes or tags (and remove one-shot combined scripts that bypassed release-branch checks), drop --refs from peeled annotated-tag lookups in push-current-release-tag.mjs, retry lockfile sync in reconcile-release.mjs when package-lock.json version lags package.json, and document cutting from pre-existing tags.

* fix(release): preserve TTY OTP prompts in npm publish and keep newer beta changelogs

Inherit TTY stdin/stdout for interactive npm publish and dist-tag add (plus --otp passthrough) while keeping stderr piped for retry classification, and keep newer beta or promoted stable changelog entries intact when an older beta tag is reconciled.
2026-11-21 18:32:08 +07:00

290 lines
9.5 KiB
JavaScript

import assert from "node:assert/strict";
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import test from "node:test";
import { mergeChangelogEntry, reconcileRelease } from "./reconcile-release.mjs";
const MAIN_CHANGELOG_WITH_BETA = `# Changelog
## 0.17.0-beta.1 - 2026-11-19
- **Beta 1 highlight:** Initial beta. ([#101](https://github.com/getpaseo/paseo/pull/101))
### Fixed
- Fixed beta 1 bug ([#101](https://github.com/getpaseo/paseo/pull/101))
## 0.16.2 - 2026-11-18
### Fixed
- Fixed 0.16.2 bug ([#99](https://github.com/getpaseo/paseo/pull/99))
`;
test("replaces an earlier beta entry in place for follow-up betas and promotions", () => {
const tagBeta2 = `# Changelog
## 0.17.0-beta.2 - 2026-11-21
- **Beta 2 highlight:** Updated beta. ([#105](https://github.com/getpaseo/paseo/pull/105))
## 0.16.2 - 2026-11-18
### Fixed
- Fixed 0.16.2 bug ([#99](https://github.com/getpaseo/paseo/pull/99))
`;
const mergedBeta2 = mergeChangelogEntry(MAIN_CHANGELOG_WITH_BETA, tagBeta2, "0.17.0-beta.2");
assert.doesNotMatch(mergedBeta2, /## 0\.17\.0-beta\.1/);
assert.match(mergedBeta2, /^# Changelog\n\n## 0\.17\.0-beta\.2 - 2026-11-21\n/);
assert.match(mergedBeta2, /## 0\.16\.2 - 2026-11-18/);
const tagStable = `# Changelog
## 0.17.0 - 2026-11-22
- **Stable highlight:** Shipped stable. ([#105](https://github.com/getpaseo/paseo/pull/105))
## 0.16.2 - 2026-11-18
`;
const mergedStable = mergeChangelogEntry(mergedBeta2, tagStable, "0.17.0");
assert.doesNotMatch(mergedStable, /## 0\.17\.0-beta\.2/);
assert.match(mergedStable, /^# Changelog\n\n## 0\.17\.0 - 2026-11-22\n/);
assert.match(mergedStable, /## 0\.16\.2 - 2026-11-18/);
});
test("inserts a stable hotfix below a newer active beta entry", () => {
const tagHotfix = `# Changelog
## 0.16.3 - 2026-11-20
### Fixed
- Fixed urgent 0.16.3 regression ([#103](https://github.com/getpaseo/paseo/pull/103))
## 0.16.2 - 2026-11-18
### Fixed
- Fixed 0.16.2 bug ([#99](https://github.com/getpaseo/paseo/pull/99))
`;
const merged = mergeChangelogEntry(MAIN_CHANGELOG_WITH_BETA, tagHotfix, "0.16.3");
const betaIndex = merged.indexOf("## 0.17.0-beta.1 - 2026-11-19");
const hotfixIndex = merged.indexOf("## 0.16.3 - 2026-11-20");
const prevStableIndex = merged.indexOf("## 0.16.2 - 2026-11-18");
assert.ok(betaIndex >= 0 && hotfixIndex > betaIndex && prevStableIndex > hotfixIndex);
});
test("keeps newer beta or promoted stable changelog entries when reconciling an older beta", () => {
const mainWithBeta2 = `# Changelog
## 0.17.0-beta.2 - 2026-11-21
- **Beta 2 highlight:** Newer beta. ([#105](https://github.com/getpaseo/paseo/pull/105))
## 0.16.2 - 2026-11-18
`;
const mainWithStable = `# Changelog
## 0.17.0 - 2026-11-22
- **Stable highlight:** Shipped stable. ([#105](https://github.com/getpaseo/paseo/pull/105))
## 0.16.2 - 2026-11-18
`;
assert.equal(
mergeChangelogEntry(mainWithBeta2, MAIN_CHANGELOG_WITH_BETA, "0.17.0-beta.1"),
mainWithBeta2,
);
assert.equal(
mergeChangelogEntry(mainWithStable, MAIN_CHANGELOG_WITH_BETA, "0.17.0-beta.1"),
mainWithStable,
);
});
test("reconcileRelease updates changelogs, F-Droid files, and versions only when tag is newer", () => {
const dir = mkdtempSync(path.join(tmpdir(), "reconcile-release-"));
try {
writeFileSync(path.join(dir, "CHANGELOG.md"), MAIN_CHANGELOG_WITH_BETA);
writeFileSync(
path.join(dir, "CHANGELOG.zh-CN.md"),
"# Changelog\n\n## 0.17.0-beta.1 - 2026-11-19\n\n- 旧内容\n\n## 0.16.2 - 2026-11-18\n\n- 0.16.2\n",
);
writeFileSync(
path.join(dir, "package.json"),
`${JSON.stringify({ name: "paseo", version: "0.17.0-beta.1" }, null, 2)}\n`,
);
const tagFiles = new Map([
[
"CHANGELOG.md",
"# Changelog\n\n## 0.16.3 - 2026-11-20\n\n### Fixed\n\n- Hotfix ([#103](https://github.com/getpaseo/paseo/pull/103))\n\n## 0.16.2 - 2026-11-18\n",
],
[
"CHANGELOG.zh-CN.md",
"# Changelog\n\n## 0.16.3 - 2026-11-20\n\n### 修复\n\n- 热修复 ([#103](https://github.com/getpaseo/paseo/pull/103))\n\n## 0.16.2 - 2026-11-18\n",
],
["fastlane/metadata/android/en-US/changelogs/160031.txt", "Hotfix notes\n"],
["fastlane/metadata/android/en-US/changelogs/160032.txt", "Hotfix notes\n"],
]);
const ranCommands = [];
const hotfixResult = reconcileRelease(
{ tag: "v0.16.3", cwd: dir },
{
getFdroidVersionCodes: () => [
{ abi: "armeabi-v7a", versionCode: 160031 },
{ abi: "arm64-v8a", versionCode: 160032 },
],
readTagFile(_tag, filePath) {
if (!tagFiles.has(filePath)) {
throw new Error(`Missing ${filePath}`);
}
return tagFiles.get(filePath);
},
verifyTag: () => {},
runNpm(args) {
ranCommands.push(args);
},
},
);
// Hotfix 0.16.3 is older than main's 0.17.0-beta.1: keep main's version untouched.
assert.equal(hotfixResult.versionUpdated, false);
assert.deepEqual(ranCommands, []);
assert.equal(
JSON.parse(readFileSync(path.join(dir, "package.json"), "utf8")).version,
"0.17.0-beta.1",
);
assert.equal(
readFileSync(path.join(dir, "fastlane/metadata/android/en-US/changelogs/160031.txt"), "utf8"),
"Hotfix notes\n",
);
assert.match(
readFileSync(path.join(dir, "CHANGELOG.md"), "utf8"),
/## 0\.17\.0-beta\.1[\s\S]*## 0\.16\.3[\s\S]*## 0\.16\.2/,
);
// Now reconcile 0.17.0 promotion (newer than 0.17.0-beta.1): updates root version and runs sync + prepare.
mkdirSync(path.join(dir, "fastlane/metadata/android/en-US/changelogs"), { recursive: true });
tagFiles.set(
"CHANGELOG.md",
"# Changelog\n\n## 0.17.0 - 2026-11-22\n\n- **Shipped:** Ready. ([#105](https://github.com/getpaseo/paseo/pull/105))\n",
);
tagFiles.set(
"CHANGELOG.zh-CN.md",
"# Changelog\n\n## 0.17.0 - 2026-11-22\n\n- **已发布**:就绪。([#105](https://github.com/getpaseo/paseo/pull/105))\n",
);
tagFiles.set("fastlane/metadata/android/en-US/changelogs/170001.txt", "0.17.0 notes\n");
const promoResult = reconcileRelease(
{ tag: "v0.17.0", cwd: dir },
{
getFdroidVersionCodes: () => [{ abi: "armeabi-v7a", versionCode: 170001 }],
readTagFile(_tag, filePath) {
return tagFiles.get(filePath);
},
verifyTag: () => {},
runNpm(args) {
ranCommands.push(args);
},
},
);
assert.equal(promoResult.versionUpdated, true);
assert.equal(
JSON.parse(readFileSync(path.join(dir, "package.json"), "utf8")).version,
"0.17.0",
);
assert.deepEqual(ranCommands, [
["run", "version:sync-internal"],
["run", "release:prepare"],
]);
assert.doesNotMatch(
readFileSync(path.join(dir, "CHANGELOG.md"), "utf8"),
/## 0\.17\.0-beta\.1/,
);
assert.match(
readFileSync(path.join(dir, "CHANGELOG.md"), "utf8"),
/## 0\.17\.0 - 2026-11-22[\s\S]*## 0\.16\.3 - 2026-11-20/,
);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
test("reconcileRelease retries version sync and lockfile install when a prior run failed before updating package-lock.json", () => {
const dir = mkdtempSync(path.join(tmpdir(), "reconcile-retry-"));
try {
writeFileSync(path.join(dir, "CHANGELOG.md"), MAIN_CHANGELOG_WITH_BETA);
writeFileSync(
path.join(dir, "CHANGELOG.zh-CN.md"),
"# Changelog\n\n## 0.17.0-beta.1 - 2026-11-19\n\n- 旧内容\n",
);
// Simulate a previous reconcile attempt where package.json was bumped to 0.17.0-beta.2
// before `npm run release:prepare` failed, leaving package-lock.json at 0.17.0-beta.1.
writeFileSync(
path.join(dir, "package.json"),
`${JSON.stringify({ name: "paseo", version: "0.17.0-beta.2" }, null, 2)}\n`,
);
writeFileSync(
path.join(dir, "package-lock.json"),
`${JSON.stringify({ name: "paseo", version: "0.17.0-beta.1", packages: { "": { version: "0.17.0-beta.1" } } }, null, 2)}\n`,
);
const tagFiles = new Map([
["CHANGELOG.md", "# Changelog\n\n## 0.17.0-beta.2 - 2026-11-21\n\n- Beta 2\n"],
["CHANGELOG.zh-CN.md", "# Changelog\n\n## 0.17.0-beta.2 - 2026-11-21\n\n- Beta 2\n"],
]);
const ranCommands = [];
const result = reconcileRelease(
{ tag: "v0.17.0-beta.2", cwd: dir },
{
readTagFile: (_tag, filePath) => tagFiles.get(filePath),
verifyTag: () => {},
runNpm(args) {
ranCommands.push(args);
if (args[1] === "release:prepare") {
writeFileSync(
path.join(dir, "package-lock.json"),
`${JSON.stringify({ name: "paseo", version: "0.17.0-beta.2", packages: { "": { version: "0.17.0-beta.2" } } }, null, 2)}\n`,
);
}
},
},
);
assert.equal(result.versionUpdated, true);
assert.deepEqual(ranCommands, [
["run", "version:sync-internal"],
["run", "release:prepare"],
]);
// A third run once package-lock.json matches is a no-op for version/lockfile sync.
ranCommands.length = 0;
const idempotent = reconcileRelease(
{ tag: "v0.17.0-beta.2", cwd: dir },
{
readTagFile: (_tag, filePath) => tagFiles.get(filePath),
verifyTag: () => {},
runNpm(args) {
ranCommands.push(args);
},
},
);
assert.equal(idempotent.versionUpdated, false);
assert.deepEqual(ranCommands, []);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});