Files
piik/scripts/release-mirror-ready.mjs
T
TNTcraft cf99f748a5 fix(release): resume pending mirrors from original artifacts
## Problem and outcome / 问题与结果

An otherwise published release could leave its AtomGit downloads incomplete when the platform had not yet synchronized its Git tag, or when a larger package exceeded the upload deadline. Recovery previously required a manual workflow run.

The existing mirror workflow now checks every three hours and after CI completion. It only resumes the latest published release, locates its original CI artifacts, and retains the existing full-download checksum verification. Complete or deferred mirrors use a sparse tooling checkout and skip dependency installation and artifact downloads. Git synchronization remains entirely with AtomGit; publication waits for the matching synchronized commit and tag and never creates or changes Git references.

Increase only the signed upload deadline from three to ten minutes, following the observed 51 MB APK timeout. Metadata/read timeouts, retry counts and the workflow's 30-minute limit remain unchanged.

## Verification / 验证

- 58 focused mirror/publisher tests, TypeScript, documentation and diff checks passed.
- Actual AtomGit readiness was checked against the v2.6.1 source and tag. Fixtures include the provider's four automatic source archives and distinguish them from uploaded packages.
- The release planner returns `publish: false`. This workflow resumes existing verified packages and performs no software build.

## Impact / 影响

Release automation only. Source synchronization belongs to AtomGit; Release and attachment completion belong to this workflow. Missing original artifacts or conflicting source identities remain explicit failures and never cause a published version to be rebuilt or overwritten.
2026-11-08 15:26:58 -04:00

69 lines
4.0 KiB
JavaScript

import { execFileSync } from "node:child_process";
import { appendFileSync } from "node:fs";
import { pathToFileURL } from "node:url";
const repository = "TNTcraftHIM/Piik";
export async function readMirror(path) {
const response = await fetch(`https://api.atomgit.com/api/v5/repos/${repository}${path}`, {
redirect: "error", signal: AbortSignal.timeout(30_000), headers: { Accept: "application/json" },
});
if (response.status === 404) return null;
if (!response.ok) throw new Error(`AtomGit readiness ${path}: HTTP ${response.status}`);
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");
const version = source.tag_name, revision = source.target_commitish;
const mirror = await read(`/releases/tags/${encodeURIComponent(version)}`);
if (mirror) {
if (mirror.tag_name !== version || ![true, false].includes(mirror.prerelease)
|| !mirror.body?.split(/\r?\n/).includes(`<!-- piik-source: ${revision} -->`))
throw new Error("Existing mirror release belongs to a different or unknown source revision");
const packages = source.assets?.filter(asset => asset.name?.startsWith("piik-"));
const complete = packages?.length > 0 && Array.isArray(mirror.assets) && packages.every(asset => {
const matches = mirror.assets.filter(candidate => candidate.type === "attach" && candidate.name === asset.name);
return asset.state === "uploaded" && /^sha256:[a-f0-9]{64}$/.test(asset.digest ?? "")
&& matches.length === 1 && matches[0].size === asset.size
&& matches[0].browser_download_url === `https://atomgit.com/${repository}/releases/download/${version}/${asset.name}`;
});
if (!mirror.prerelease) {
if (!complete) throw new Error("Published mirror is incomplete; it cannot be silently replaced");
return { status: "complete", version, revision };
}
}
return { status: await mirrorSourceReady(version, revision, read) ? "ready" : "deferred", version, revision };
}
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
const source = JSON.parse(execFileSync("gh", ["api", `repos/${repository}/releases/latest`], {
encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 30_000,
}));
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`
: `Mirror ${result.version} is ready to resume from original CI artifacts.\n`);
console.log(JSON.stringify(result));
}