Files
piik/scripts/release-mirror-source.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

59 lines
3.4 KiB
JavaScript

import { execFileSync } from "node:child_process";
import { appendFileSync } from "node:fs";
import { pathToFileURL } from "node:url";
import { isReleaseVersion } from "./release-version.mjs";
const repository = "TNTcraftHIM/Piik";
const gh = (path) => JSON.parse(execFileSync("gh", ["api", `repos/${repository}/${path}`], {
encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 30_000,
}));
export function resolveMirrorSource(runId, automatic = false) {
if (!runId && automatic) {
const latest = gh("releases/latest");
if (latest.draft !== false || latest.prerelease !== false || !isReleaseVersion(latest.tag_name)
|| !/^[a-f0-9]{40}$/.test(latest.target_commitish)) throw new Error("A published stable GitHub release with a full source SHA is required");
const runs = gh(`actions/workflows/repository-hygiene.yml/runs?event=push&branch=main&status=completed&head_sha=${latest.target_commitish}&per_page=100`);
const source = runs.workflow_runs?.find(run => run.head_sha === latest.target_commitish);
if (!source) throw new Error("The published release's original completed CI run is unavailable; do not rebuild its packages");
return resolveMirrorSource(String(source.id), true);
}
if (!/^[1-9]\d*$/.test(runId) || !Number.isSafeInteger(Number(runId))) {
throw new Error("Provide the original CI run's numeric ID");
}
const run = gh(`actions/runs/${runId}`);
if (run.id !== Number(runId) || run.repository?.full_name !== repository ||
run.head_repository?.full_name !== repository || run.event !== "push" ||
run.head_branch !== "main" || run.path !== ".github/workflows/repository-hygiene.yml" ||
run.status !== "completed" || !/^[a-f0-9]{40}$/.test(run.head_sha)) {
throw new Error("Mirror artifacts must come from a completed main push in this repository's CI workflow");
}
// A later publication step can fail after GitHub has published the packages.
// The matching stable release owns mirror identity, not the CI aggregate result.
const release = gh("releases/latest");
if (release.draft !== false || release.prerelease !== false || !isReleaseVersion(release.tag_name) ||
!/^[a-f0-9]{40}$/.test(release.target_commitish)) {
throw new Error("A published stable GitHub release with a full source SHA is required");
}
if (release.target_commitish !== run.head_sha) {
if (automatic) return null;
throw new Error("This CI run does not match the latest GitHub release; use its original publishing run");
}
return { run_id: String(run.id), version: release.tag_name, revision: run.head_sha };
}
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
const source = resolveMirrorSource(process.argv[2], ["workflow_run", "schedule"].includes(process.env.GITHUB_EVENT_NAME) || !process.argv[2]);
const output = { mirror: source !== null, ...source };
if (process.env.GITHUB_OUTPUT) {
appendFileSync(process.env.GITHUB_OUTPUT,
Object.entries(output).map(([key, value]) => `${key}=${value}\n`).join(""));
}
if (process.env.GITHUB_STEP_SUMMARY) {
appendFileSync(process.env.GITHUB_STEP_SUMMARY, source
? `Mirror ${source.version} from original [CI run ${source.run_id}](https://github.com/${repository}/actions/runs/${source.run_id}).\n`
: "This CI run did not publish the current GitHub release; no mirror work is needed.\n");
}
console.log(JSON.stringify(output));
}