mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 19:46:11 +00:00
fix(ci): a package that fails to publish is tried again before the release fails (#8333)
One failed upload failed the whole release with the other packages already out, and the next run could not finish it. The publish step now tries each package up to three times. Every try asks the registry first, so a package that went out on a try that reported failure is not sent again, a version there with other contents still fails at once, and after the last try the registry is asked once more before the package counts as failed. Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
861046f508
commit
55cfbe0081
@@ -859,6 +859,85 @@ test("publishing skips only identical uploads and fails on a version it did not
|
||||
assert.doesNotMatch(rerun.calls, /npm publish/);
|
||||
});
|
||||
|
||||
test("a publish that fails on the way is tried again, three times in all, asking npm first each time", () => {
|
||||
const step = stepOf(publish, "Publish packages");
|
||||
// The fake npm fails its first `failures` publishes; with `lands` the package is on npm after a failed one.
|
||||
const run = ({ failures, lands = "" }) => {
|
||||
const temp = mkdtempSync(join(tmpdir(), "hyperframes-publish-retry-"));
|
||||
try {
|
||||
const bin = join(temp, "bin");
|
||||
mkdirSync(bin);
|
||||
const log = join(temp, "npm.log");
|
||||
const seen = join(temp, "on-npm");
|
||||
writeFileSync(log, "");
|
||||
writeFileSync(
|
||||
join(bin, "npm"),
|
||||
`#!/bin/sh
|
||||
echo "npm $1" >> "${log}"
|
||||
if [ "$1" = view ]; then [ -s "${seen}" ] || exit 1; cat "${seen}"; exit 0; fi
|
||||
tried=$(grep -c "^npm publish" "${log}")
|
||||
if [ "$tried" -le "$FAILURES" ]; then [ -z "$LANDS" ] || echo "$LANDS" > "${seen}"; exit 1; fi
|
||||
echo "$INTEGRITY" > "${seen}"
|
||||
`,
|
||||
);
|
||||
chmodSync(join(bin, "npm"), 0o755);
|
||||
packTarball(temp, "core.tgz", { name: "@hyperframes/core", version: "1.2.3-alpha.1" });
|
||||
writeFileSync(
|
||||
join(temp, "publish-order.tsv"),
|
||||
`@hyperframes/core\t${join(temp, "core.tgz")}\n`,
|
||||
);
|
||||
const integrity = `sha512-${createHash("sha512")
|
||||
.update(readFileSync(join(temp, "core.tgz")))
|
||||
.digest("base64")}`;
|
||||
const result = runStep(step, {
|
||||
cwd: temp,
|
||||
path: `${bin}:${process.env.PATH}`,
|
||||
env: {
|
||||
VERSION: "1.2.3-alpha.1",
|
||||
DIST_TAG: "alpha",
|
||||
NODE_AUTH_TOKEN: "",
|
||||
PUBLISH_RETRY_SECONDS: "0",
|
||||
FAILURES: String(failures),
|
||||
LANDS: lands === "same" ? integrity : lands,
|
||||
INTEGRITY: integrity,
|
||||
},
|
||||
});
|
||||
const calls = readFileSync(log, "utf8").trim().split("\n");
|
||||
return { ...result, calls, publishes: calls.filter((c) => c === "npm publish").length };
|
||||
} finally {
|
||||
rmSync(temp, { recursive: true, force: true });
|
||||
}
|
||||
};
|
||||
|
||||
// fails without the fix: one failed publish failed the release, with the rest of the packages already out.
|
||||
const second = run({ failures: 1 });
|
||||
assert.equal(second.status, 0, second.stdout + second.stderr);
|
||||
assert.equal(second.publishes, 2);
|
||||
assert.deepEqual(second.calls, ["npm view", "npm publish", "npm view", "npm publish"]);
|
||||
|
||||
const third = run({ failures: 2 });
|
||||
assert.equal(third.status, 0, third.stdout);
|
||||
assert.equal(third.publishes, 3);
|
||||
|
||||
const never = run({ failures: 9 });
|
||||
assert.equal(never.status, 1);
|
||||
assert.equal(never.publishes, 3);
|
||||
assert.match(never.stdout, /failed to publish/);
|
||||
|
||||
// The publish answered with a failure but the package went out: it is not sent a second time.
|
||||
const landed = run({ failures: 9, lands: "same" });
|
||||
assert.equal(landed.status, 0, landed.stdout);
|
||||
assert.equal(landed.publishes, 1);
|
||||
const landedLast = run({ failures: 9, lands: "" });
|
||||
assert.equal(landedLast.calls.at(-1), "npm view", "npm is asked once more after the last try");
|
||||
|
||||
// Someone else's contents under this version, seen between tries: no further try, and the release fails.
|
||||
const others = run({ failures: 9, lands: "sha512-other" });
|
||||
assert.equal(others.status, 1);
|
||||
assert.equal(others.publishes, 1);
|
||||
assert.match(others.stdout, /this run did not publish it/);
|
||||
});
|
||||
|
||||
test("every publish runs in npm-publish, the environment npm trusted publishing names", () => {
|
||||
assert.equal(publish.environment, "npm-publish");
|
||||
const jobsWithEnvironment = Object.entries(config.jobs).filter(([, job]) => job.environment);
|
||||
|
||||
Reference in New Issue
Block a user