release candidates: draft assets are read by their attachment uuid (the tag URL is 404 for drafts: the record job could not merge SHA256SUMS); the installers are scanned with the private terms in their build jobs, so the record job needs no apt tools (it spent 5 minutes installing them)

This commit is contained in:
CRTkafa 2026-10-15 01:18:55 +08:00
parent cdaecc2afb
commit 6873f2cc68
5 changed files with 34 additions and 23 deletions

View file

@ -101,7 +101,10 @@ export function mergeSums(existing: string, add: { file: string; sha256: string
return [...m].sort((a, b) => a[0].localeCompare(b[0])).map(([f, h]) => `${h} ${f}`).join('\n') + '\n';
}
export interface Release { id: number; tag_name: string; name: string; draft: boolean; prerelease: boolean; body: string; assets: { id: number; name: string; size: number; browser_download_url: string }[] }
export interface Release { id: number; tag_name: string; name: string; draft: boolean; prerelease: boolean; body: string; assets: { id: number; name: string; size: number; uuid?: string; browser_download_url: string }[] }
/** Where an asset downloads: drafts (release candidates) only by their attachment uuid; the tag URL is 404 there. */
export const assetUrl = (a: { uuid?: string; browser_download_url: string }): string => (a.uuid ? `${(process.env.FORGEJO_URL ?? "https://git.crt.fyi").replace(/\/+$/, "")}/attachments/${a.uuid}` : a.browser_download_url);
/** Release entries `prune --keep <tag>` deletes: every other entry, the kept one must exist and be published.
* Release candidates (rc-<sha> drafts of ci.yml, tools/release-candidate.ts) are not entries: they have their own
@ -241,7 +244,7 @@ export async function upsert(o: UpsertOptions): Promise<Release | null> {
const files = o.files.filter(f => basename(f) !== SUMS);
let rel = (await listReleases()).find(r => r.tag_name === o.tag) ?? null;
const sumsBefore = rel?.assets.find(a => a.name === SUMS);
const existingSums = sumsBefore ? await api<string>('GET', sumsBefore.browser_download_url, undefined, true) : '';
const existingSums = sumsBefore ? await api<string>('GET', assetUrl(sumsBefore), undefined, true) : '';
const sums = mergeSums(existingSums, files.map(f => ({ file: basename(f), sha256: sha256(f) })));
console.log(`${rel ? `update release ${rel.id}` : 'create release'} ${o.tag}${o.draft ? ' (draft)' : ''}: ${o.title ?? rel?.name ?? o.tag}`);
for (const f of files) console.log(` ${rel?.assets.some(a => a.name === basename(f)) ? 'replace' : 'attach '} ${basename(f)} (${(statSync(f).size / 1e6).toFixed(1)} MB)`);