From c40ae1e403cafc2e2c5f99bc8e6595d511d7fa62 Mon Sep 17 00:00:00 2001 From: AAA <35992542+TNTcraftHIM@users.noreply.github.com> Date: Fri, 13 Nov 2026 15:15:18 -0400 Subject: [PATCH] fix(release): decouple download mirrors from source synchronization --- .github/workflows/atomgit-mirror.yml | 2 +- docs/operations/github.md | 38 ++++++++++++++++++---------- docs/standards/versioning.md | 14 +++++----- docs/todo.md | 4 +++ scripts/mirror-release.mjs | 15 ++++++----- scripts/release-mirror-ready.mjs | 23 ++--------------- tests/publish-release.test.ts | 13 +++------- tests/release-mirror-ready.test.ts | 37 +++++++++++---------------- 8 files changed, 66 insertions(+), 80 deletions(-) diff --git a/.github/workflows/atomgit-mirror.yml b/.github/workflows/atomgit-mirror.yml index ef130f027..6e4443539 100644 --- a/.github/workflows/atomgit-mirror.yml +++ b/.github/workflows/atomgit-mirror.yml @@ -93,6 +93,6 @@ jobs: - name: Explain recovery if: failure() && steps.source.outputs.mirror == 'true' run: | - printf 'Mirror failed; the scheduled check will retry from original CI run %s. GitHub publication and Website are independent. If artifacts expired, recover the retained original build output; do not rebuild this version. See docs/operations/github.md.\n' "$PIIK_SOURCE_RUN_ID" >> "$GITHUB_STEP_SUMMARY" + printf 'Release mirror remains incomplete. Resume from original CI run %s; do not wait for source synchronization. If artifacts expired, recover retained original build output without rebuilding this version. See docs/operations/github.md.\n' "$PIIK_SOURCE_RUN_ID" >> "$GITHUB_STEP_SUMMARY" env: PIIK_SOURCE_RUN_ID: ${{ steps.source.outputs.run_id }} diff --git a/docs/operations/github.md b/docs/operations/github.md index b1e8d3fe3..e7d0029a5 100644 --- a/docs/operations/github.md +++ b/docs/operations/github.md @@ -117,14 +117,22 @@ signing identity before distributing a package that promises automatic updates. ## AtomGit Download Mirror [AtomGit TNTcraftHIM/Piik](https://atomgit.com/TNTcraftHIM/Piik) is the public -source and Release mirror. GitHub owns development, issues and original packages. -AtomGit's configured repository synchronization handles branches, tags and commits; -the **AtomGit mirror** GitHub workflow separately copies published binary assets. -Git synchronization remains AtomGit's responsibility; this workflow does not push, -create or change Git references, and does not ask users to synchronize them manually. +download mirror. GitHub owns development, issues, source identity and original packages. +The **AtomGit mirror** GitHub workflow copies published binary assets. Repository +synchronization is optional and must not gate package distribution. A mirror's +local Release tag only locates attachments; the GitHub source marker and verified +original package digests establish their identity. Release creation uses the +mirror's initialized default branch when the local tag does not exist. Its repository Actions secret is `ATOMGIT_TOKEN`. Never put this token in source, a remote URL or a distributed package. GitHub publication keeps its scoped token. +Use a writable repository for package distribution. AtomGit's Pull-mirror mode +rejects Release creation when it needs to create a tag, with an `image repository` +error. Remove that Pull association in **Project Settings → Repository Mirroring** +without deleting the repository or its Releases. Automatic source synchronization +is optional; it must not make the distribution repository read-only. Provider-generated +source archives are not the canonical source linked in the mirrored release body. + After a completed main-push CI run, the workflow checks the current stable GitHub release and finds its original publishing CI run, even when the triggering run only updated tooling. A later failed container step does not prevent @@ -134,18 +142,19 @@ If that published Release includes signed update metadata, the mirror restores those two original GitHub attachments, verifies their digest and signature against the package inventory, and uploads identical bytes. It never generates a new signature or requires the private signing key. -GitHub publication and **Website** do not depend on mirror success. An unfinished mirror remains a +An authorized release is not complete until its mirror and managed deployments +pass their postflight checks. GitHub publication and **Website** can proceed independently, +but a failed mirror remains unfinished release work. An unfinished mirror remains a prerelease until every package passes anonymous full-download SHA-256 validation. This includes the original signed Android APK without rebuilding it. Every three hours the same workflow also checks the latest GitHub release's mirror metadata. A stable mirror with the matching source marker and complete package inventory of uploaded attachments needs no further work; provider-generated source -archives do not count as packages. A missing source commit or matching tag is -reported as deferred until AtomGit's scheduled Git synchronization completes. -Both outcomes use a sparse tools-only checkout and skip dependency installation -and artifact downloads. API failures -or conflicting source identities remain failures, not successful deferrals. +archives do not count as packages. A missing or incomplete prerelease resumes +publication from original artifacts without reading mirrored commits or tags. +Completed mirrors use a sparse tools-only checkout and skip dependency installation +and artifact downloads. API failures or conflicting source identities remain failures. When ready, recovery locates the completed main-push CI run for that exact source, downloads its original artifacts and resumes the existing publisher. It never @@ -161,9 +170,10 @@ For recovery, rerun **AtomGit mirror** with the original publishing CI run ID: gh workflow run atomgit-mirror.yml --repo TNTcraftHIM/Piik --ref main -f run_id=RUN_ID ``` -The run ID is optional for a manual status check; without it, the workflow uses -the same latest-release lookup as its scheduled check. Ordinary delayed source -synchronization or interrupted uploads need no manual trigger. +The run ID is optional; without it, the workflow resolves the latest GitHub release. +The scheduled check is recovery support, not the release-completion gate. If a +scheduled run is delayed or an upload fails, run this recovery during the authorized +release instead of assuming a later schedule will finish it. The source must be a completed main-push CI run matching the latest published GitHub release. The workflow runs trusted main tooling and treats artifacts only diff --git a/docs/standards/versioning.md b/docs/standards/versioning.md index f877b59b8..c434b2a6e 100644 --- a/docs/standards/versioning.md +++ b/docs/standards/versioning.md @@ -394,10 +394,11 @@ presentation, not Piik's version selection or feature claims. ## Release Sources GitHub Releases is the primary publication. The public -[AtomGit project](https://atomgit.com/TNTcraftHIM/Piik) mirrors source branches, -tags and commits through its configured repository synchronization. Release -metadata and binary attachments are published separately; Git synchronization -alone does not make packages available. +[AtomGit project](https://atomgit.com/TNTcraftHIM/Piik) distributes the same original +Release packages. Optional source synchronization is independent of that duty +and must not delay it. The mirror's local tag is an attachment locator, not the +authority for the package's source revision; GitHub and the retained source marker +own that identity. Build each target once. The mirror publisher reuses the shared artifact validator, compares every original package with GitHub's published SHA-256 digest, and copies @@ -412,8 +413,9 @@ credentials and must not appear in logs. Before marking the release stable, anonymously download every package and verify its complete size and SHA-256. A rerun inventories the existing release and attachments first; never blindly retry a timed-out mutation or replace a published package. An incomplete release -remains a prerelease. GitHub and website publication remain independent of mirror -success. No automatic deletion or Gitee-specific quota policy applies to AtomGit. +remains a prerelease. GitHub and website publication may proceed independently, +but release completion requires the matching verified mirror. Scheduled retries +do not replace this postflight. No automatic deletion or Gitee-specific quota policy applies to AtomGit. GitHub remains the first update source; the current Rust App and Server use AtomGit when it is unavailable. Published 2.x binaries retain their embedded diff --git a/docs/todo.md b/docs/todo.md index c28fbe5ae..cc74b2b0a 100644 --- a/docs/todo.md +++ b/docs/todo.md @@ -20,6 +20,10 @@ the feedback period; they do not delay that delivery. fixes a separate reproduced defect; verify the updated candidate on the reported setup and whether intended sound remains after exclusion. Neither that correction nor the earlier local-preview fix yet explains the PID-specific report. +- [ ] **Release mirror repository mode.** Remove AtomGit's read-only Pull + association so future Release tags can be created independently of source + synchronization. Keep the repository URL and published attachments; + [mirror operations](./operations/github.md#atomgit-download-mirror) owns setup. - [ ] **Windows sound only works with exclusion (#534).** Compare the affected application's playback endpoint with Piik's default-endpoint capture. The [output-routing control](./research/media-fidelity.md#windows-output-routing) diff --git a/scripts/mirror-release.mjs b/scripts/mirror-release.mjs index d1206e213..2050bfe57 100644 --- a/scripts/mirror-release.mjs +++ b/scripts/mirror-release.mjs @@ -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; diff --git a/scripts/release-mirror-ready.mjs b/scripts/release-mirror-ready.mjs index caf590a95..e9ee631c8 100644 --- a/scripts/release-mirror-ready.mjs +++ b/scripts/release-mirror-ready.mjs @@ -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)); } diff --git a/tests/publish-release.test.ts b/tests/publish-release.test.ts index a737dcf3b..f1f4defc6 100644 --- a/tests/publish-release.test.ts +++ b/tests/publish-release.test.ts @@ -52,7 +52,7 @@ describe("AtomGit mirror publication", () => { async function mirror(options: { existing?: "pending" | "published" | "unknown"; corrupt?: boolean; updates?: { name: string; bytes: Buffer }[]; wrongSource?: boolean; wrongDigest?: boolean; missing?: boolean; uploadFailure?: boolean | number; - stale?: boolean; supersededDuringUpload?: boolean; mirrorSourceMissing?: boolean; + stale?: boolean; supersededDuringUpload?: boolean; downloadFault?: { remaining: number; name: "TimeoutError" | "TypeError" }; fault?: { method: string; remaining: number; status: number | "timeout" | "body-timeout" } } = {}) { const interrupted = (bytes: Uint8Array, error: Error) => { @@ -136,11 +136,10 @@ describe("AtomGit mirror publication", () => { ? Response.json({ id: 42, tag_name: version, body: options.existing === "unknown" ? "unknown" : marker, prerelease: pending, assets: [...present] }) : new Response(null, { status: 404 }); if (path === "") return Response.json({ private: false, default_branch: "master" }); - if (path === `/commits/${revision}`) return options.mirrorSourceMissing ? new Response(null, { status: 404 }) : Response.json({ sha: revision }); - if (path === "/tags?per_page=100&page=1") return Response.json([{ name: version, commit: { sha: revision } }]); if (path === "/releases" && method === "POST") { const body = JSON.parse(String(init?.body)); expect(body.release_status).toBe("pre"); + expect(body.target_commitish).toBe("master"); expect(body.body).toContain(marker); return Response.json({ ...body, prerelease: true, assets: [] }); } @@ -175,13 +174,7 @@ describe("AtomGit mirror publication", () => { return { mutations, failure }; } - it("waits for AtomGit Git synchronization without creating a release or tag", async () => { - const result = await mirror({ mirrorSourceMissing: true }); - expect(result.failure).toContain("Git synchronization is pending"); - expect(result.mutations).toEqual([]); - }); - - it("copies the published bytes, verifies anonymous downloads and marks stable last", async () => { + it("copies original packages without mirrored source lookups, verifies anonymous downloads and marks stable last", async () => { const result = await mirror(); expect(result.failure).toBeUndefined(); expect(result.mutations[0]).toBe("POST /releases"); diff --git a/tests/release-mirror-ready.test.ts b/tests/release-mirror-ready.test.ts index 77a61df97..cdba70c9e 100644 --- a/tests/release-mirror-ready.test.ts +++ b/tests/release-mirror-ready.test.ts @@ -1,5 +1,5 @@ import { expect, test, vi } from "vitest"; -import { mirrorReadiness, mirrorSourceReady, readMirror } from "../scripts/release-mirror-ready.mjs"; +import { mirrorReadiness, readMirror } from "../scripts/release-mirror-ready.mjs"; const revision = "a".repeat(40), version = "v2.6.1"; const asset = { name: "piik-app-fixture.zip", state: "uploaded", size: 1024, digest: `sha256:${"b".repeat(64)}` }; @@ -25,23 +25,18 @@ test("signed releases require both original update attachments in the completed ] }))).toEqual({ status: "complete", version, revision }); }); -test.each(["commit", "tag"])("missing synced %s defers without a Git mutation", async missing => { - const read = vi.fn(async (path: string) => path.startsWith("/releases/") ? null - : path.startsWith("/commits/") ? missing === "commit" ? null : { sha: revision } : []); - expect(await mirrorReadiness(source, read)).toEqual({ status: "deferred", version, revision }); -}); - -test("a pending release resumes only after its exact tag and source exist", async () => { - const read = vi.fn(async (path: string) => path.startsWith("/releases/") ? { ...mirror, prerelease: true, assets: [] } - : path.startsWith("/commits/") ? { sha: revision } : [{ name: version, commit: { sha: revision } }]); +test.each([null, { ...mirror, prerelease: true, assets: [] }])("a missing or pending mirror is ready without querying mirrored commits or tags", async pending => { + const read = vi.fn(async (path: string) => { + if (path !== `/releases/tags/${version}`) throw new Error("Mirrored source is irrelevant to release distribution"); + return pending; + }); expect(await mirrorReadiness(source, read)).toEqual({ status: "ready", version, revision }); - expect(read.mock.calls.every(([path]) => path.startsWith("/releases/") || path.startsWith("/commits/") || path.startsWith("/tags?"))).toBe(true); + expect(read.mock.calls).toEqual([[`/releases/tags/${version}`]]); }); -test("a missing attachment in a published release and a conflicting tag fail rather than silently repairing identity", async () => { +test("a missing attachment or conflicting source marker fails rather than claiming a completed mirror", async () => { await expect(mirrorReadiness(source, async () => ({ ...mirror, assets: [] }))).rejects.toThrow("incomplete"); - await expect(mirrorSourceReady(version, revision, async (path: string) => path.startsWith("/commits/") - ? { sha: revision } : [{ name: version, commit: { sha: "c".repeat(40) } }])).rejects.toThrow("another source"); + await expect(mirrorReadiness(source, async () => ({ ...mirror, body: `` }))).rejects.toThrow("different or unknown source revision"); }); test("a provider source archive cannot stand in for a published package", async () => { @@ -50,16 +45,14 @@ test("a provider source archive cannot stand in for a published package", async }))).rejects.toThrow("incomplete"); }); -test("a truncated tag inventory fails after ten pages rather than claiming the source is absent", async () => { - const read = vi.fn(async (path: string) => path.startsWith("/commits/") ? { sha: revision } - : Array.from({ length: 100 }, (_, index) => ({ name: `other-${index}`, commit: { sha: revision } }))); - await expect(mirrorSourceReady(version, revision, read)).rejects.toThrow("exceeds 10 pages"); - expect(read).toHaveBeenCalledTimes(11); - expect(read.mock.calls.at(-1)).toEqual(["/tags?per_page=100&page=10"]); +test.each([{ ...source, draft: true }, { ...source, prerelease: true }, { ...source, target_commitish: "main" }])("GitHub published source identity remains required before any mirror lookup", async invalid => { + const read = vi.fn(); + await expect(mirrorReadiness(invalid, read)).rejects.toThrow("published GitHub release"); + expect(read).not.toHaveBeenCalled(); }); -test("readiness treats an unavailable API as failure, not pending synchronization", async () => { +test("readiness treats an unavailable API as failure, not an absent or completed mirror", async () => { vi.stubGlobal("fetch", vi.fn(async () => new Response(null, { status: 503 }))); - try { await expect(readMirror("/commits/" + revision)).rejects.toThrow("HTTP 503"); } + try { await expect(mirrorReadiness(source, readMirror)).rejects.toThrow("HTTP 503"); } finally { vi.unstubAllGlobals(); } });