fix(release): decouple download mirrors from source synchronization

This commit is contained in:
AAA committed 2026-11-13 15:21:51 -04:00
1 parent 15d159bff0
commit c40ae1e403
8 files changed
+66 -80

No files matched your search

+9 -6
View File
@@ -3,7 +3,6 @@ import { createHash } from "node:crypto";
import { openAsBlob } from "node:fs";
import { setTimeout as delay } from "node:timers/promises";
import { readReleaseArtifacts, recoverUpdateArtifacts } from "./release-artifacts.mjs";
import { mirrorSourceReady } from "./release-mirror-ready.mjs";
const [directory, version, revision, option] = process.argv.slice(2);
if (option && option !== "--dry-run") {
@@ -59,7 +58,13 @@ async function request(path, method = "GET", body) {
body: body ? JSON.stringify(body) : undefined,
}, 20_000, async response => {
if (response.status === 404 && method === "GET") return null;
if (!response.ok) throw new Error(`HTTP ${response.status}`);
if (!response.ok) {
const detail = await response.json().catch(() => null);
const message = typeof detail?.message === "string" ? detail.message
: typeof detail?.error_message === "string" ? detail.error_message
: typeof detail?.error === "string" ? detail.error : "";
throw new Error(`HTTP ${response.status}${message ? `: ${message.replaceAll(token, "[redacted]").slice(0, 500)}` : ""}`);
}
return response.json();
});
}
@@ -117,16 +122,14 @@ if (option === "--dry-run") {
!release.body?.split(/\r?\n/).includes(marker))) {
throw new Error("Existing mirror release belongs to a different or unknown source revision");
}
const body = `${source.body ?? ""}\n\nSource: https://github.com/${repository}/commit/${revision}\n\n${marker}\n`;
const body = `${source.body ?? ""}\n\n此镜像分发 GitHub 的原始安装包;源码以 GitHub 为准。 / This mirror distributes the original GitHub packages; GitHub owns their source.\n\nSource: https://github.com/${repository}/commit/${revision}\n\n${marker}\n`;
if (!release || release.prerelease) requireLatestSource();
if (!release) {
if (!await mirrorSourceReady(version, revision, request))
throw new Error("AtomGit Git synchronization is pending; the scheduled mirror check will resume after the matching commit and tag arrive");
const repo = await request("");
if (!repo || repo.private || !repo.default_branch) throw new Error("A public initialized AtomGit mirror is required");
release = await request("/releases", "POST", {
tag_name: version, name: source.name || `Piik ${version}`, body, release_status: "pre",
target_commitish: revision,
target_commitish: repo.default_branch,
});
}
const attachments = release.assets;
+2 -21
View File
@@ -12,24 +12,6 @@ export async function readMirror(path) {
return response.json();
}
// Git synchronization belongs to AtomGit. Release creation must never create a tag.
export async function mirrorSourceReady(version, revision, read = readMirror) {
const commit = await read(`/commits/${revision}`);
if (!commit) return false;
if (commit.sha !== revision) throw new Error("AtomGit source commit differs from the published source");
for (let page = 1; page <= 10; page++) {
const tags = await read(`/tags?per_page=100&page=${page}`);
if (!Array.isArray(tags)) throw new Error("Unexpected AtomGit tag list");
const tag = tags.find(tag => tag.name === version);
if (tag) {
if (tag.commit?.sha !== revision) throw new Error("AtomGit release tag belongs to another source revision");
return true;
}
if (tags.length < 100) return false;
}
throw new Error("AtomGit tag inventory exceeds 10 pages; source readiness cannot be determined");
}
export async function mirrorReadiness(source, read = readMirror) {
if (source.draft !== false || source.prerelease !== false || typeof source.tag_name !== "string"
|| !/^[a-f0-9]{40}$/.test(source.target_commitish)) throw new Error("A published GitHub release with a full source SHA is required");
@@ -55,7 +37,7 @@ export async function mirrorReadiness(source, read = readMirror) {
return { status: "complete", version, revision };
}
}
return { status: await mirrorSourceReady(version, revision, read) ? "ready" : "deferred", version, revision };
return { status: "ready", version, revision };
}
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
@@ -65,8 +47,7 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
const result = await mirrorReadiness(source);
if (process.env.GITHUB_OUTPUT) appendFileSync(process.env.GITHUB_OUTPUT, `status=${result.status}\n`);
if (process.env.GITHUB_STEP_SUMMARY) appendFileSync(process.env.GITHUB_STEP_SUMMARY,
result.status === "deferred" ? `Mirror ${result.version} deferred until AtomGit's scheduled Git synchronization supplies the matching commit and tag. The next mirror check will resume automatically.\n`
: result.status === "complete" ? `Mirror ${result.version} is already stable with the complete published attachment inventory.\n`
result.status === "complete" ? `Mirror ${result.version} is already stable with the complete published attachment inventory.\n`
: `Mirror ${result.version} is ready to resume from original CI artifacts.\n`);
console.log(JSON.stringify(result));
}