From c04641af19683934f595770579c959d7fe87bc70 Mon Sep 17 00:00:00 2001 From: egdev6 Date: Fri, 20 Nov 2026 15:24:17 +0100 Subject: [PATCH 1/4] feat(release): add Linux release preflight for existing releases --- odd/tasks/linux-release-attach.md | 40 ++++++ scripts/linux-release-preflight.mjs | 135 ++++++++++++++++++++ scripts/linux-release-preflight.test.mjs | 154 +++++++++++++++++++++++ 3 files changed, 329 insertions(+) create mode 100644 odd/tasks/linux-release-attach.md create mode 100644 scripts/linux-release-preflight.mjs create mode 100644 scripts/linux-release-preflight.test.mjs diff --git a/odd/tasks/linux-release-attach.md b/odd/tasks/linux-release-attach.md new file mode 100644 index 0000000..b38b67e --- /dev/null +++ b/odd/tasks/linux-release-attach.md @@ -0,0 +1,40 @@ +# Linux release attach (v0.9.0) + +Manual workflow that builds the Linux `.deb` and `.AppImage` from an existing release's exact source commit and attaches them to that release, so v0.9.0 gets an official Linux installer without a new version. +Owner: @egdev6. Branch: `ci/linux-release-attach`. Risk: item 5 (release delivery / CI). + +## Specs + +- S1. Goal, from the owner: «hay que sacar la 0.10.0 para poder oficializar el instalador de linux? no podemos arreglar lo que queda e inclurlo en la 0.9.0?» → Linux installers are attached to the already published `v0.9.0`; no new version. +- S2. Accepted proposal («haz el workflow»): a new `.github/workflows/linux-release.yml`, following the macOS pattern: + - manual `workflow_dispatch` only, from `main`, with inputs `version` and `source_sha`; + - verifies the release already exists; + - checks out that exact commit; + - builds the `.deb` and `.AppImage` on Ubuntu; + - attaches them to the release without overwriting anything. +- S3. Reuse what already works: the Linux system dependencies, build and clean-container verification steps of `linux-ci.yml` (`Install Tauri 2 Linux system dependencies`, `Build Linux bundles (deb + AppImage)`, `Verify bundles in clean Ubuntu 22.04` / `scripts/verify-linux-bundles`), on `ubuntu-22.04` like `linux-ci.yml`. +- S4. Safety, mirroring `macos-release.yml` / `scripts/macos-release-preflight.mjs` / `scripts/macos-release-resume-publish.mjs`: + - refuse unless `github.ref == refs/heads/main`; + - validate `version` (stable SemVer) and `source_sha` (40 lowercase hex, ancestor of `origin/main`, manifests at that SHA declare `version`) before building; + - the release `v` must already exist (published or draft) and its tag must point to `source_sha`; + - inputs reach shell only through `env`, never interpolated into `run:`; + - actions pinned by full SHA as in the existing workflows; `permissions: contents: read` at workflow level, `contents: write` only in the attach job; no other secrets than `GITHUB_TOKEN`; + - never create or move tags, never edit the release body, never touch `latest.json` or updater files; + - attach only `Quorb__amd64.deb`, `Quorb__amd64.AppImage` and one `.sha256` per file; if any of those names already exists on the release, fail without overwriting; on a partial upload failure, delete only the assets this run uploaded. +- S5. Tests in the repo's existing style (`node --test`, like `scripts/macos-release-workflow.test.mjs` and `scripts/macos-release-preflight.test.mjs`): structural workflow assertions (trigger, ref guard, permissions, pinned actions, no input interpolation, attach-only names) and unit tests of the preflight/attach scripts, wired into `npm test`. +- S6. Document how to run it (inputs, what it attaches, manual updates on Linux, AppImage FUSE caveat) in `docs/release-linux.md`. + +## Tasks + +| ID | Specs | Route | Commit | +| --- | --- | --- | --- | +| T1 | S2–S6 | gentle-ai-worker | — | +| T2 | S1–S6 | gentle-ai-verify (Risk: item 5) | — | +| T3 | S1 | parent, after the owner runs the workflow: release notes, README Linux row | — | + +## Log + +- L1 (2026-11-20, owner): «habría que añadir los links de descarga de linux al readme. Puedes hacer que los links descarguen la latest y no haya que cambiarlo manualmente en cada despliegue? Hazte pull antes» +- L2 (owner): «el instalador ya está para linux no? que la descarga apunte a él» — evidence: no release v0.1.1–v0.9.0 has Linux assets; `release.yml` is Windows-only; Linux bundles are private `linux-ci.yml` artifacts. +- L3 (owner): «a ver aclarémonos...hay que sacar la 0.10.0 para poder oficializar el instalador de linux? no podemos arreglar lo que queda e inclurlo en la 0.9.0?» +- L4 (owner): «haz el workflow» diff --git a/scripts/linux-release-preflight.mjs b/scripts/linux-release-preflight.mjs new file mode 100644 index 0000000..a49473e --- /dev/null +++ b/scripts/linux-release-preflight.mjs @@ -0,0 +1,135 @@ +import { execFileSync as execute } from 'node:child_process'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { validateReleaseInputs } from './macos-release-preflight.mjs'; +import { packageJsonVersion, packageLockVersions, cargoTomlVersion, cargoLockVersion } from './bump.mjs'; + +const projectRoot = fileURLToPath(new URL('../', import.meta.url)); +const repository = 'egdev6/quorb'; +const record = (value) => value !== null && typeof value === 'object' && !Array.isArray(value); +const validSha = (value) => typeof value === 'string' && /^[0-9a-f]{40}$/.test(value) && value === value.trim(); + +export function linuxAssetNames(version) { + validateReleaseInputs({ ref: 'refs/heads/main', version, sourceSha: '0'.repeat(40) }); + const deb = `Quorb_${version}_amd64.deb`; + const appimage = `Quorb_${version}_amd64.AppImage`; + return [deb, `${deb}.sha256`, appimage, `${appimage}.sha256`]; +} + +async function readJson(response, signal) { + if (!response?.ok || response.status !== 200 || typeof response.body?.getReader !== 'function') throw new Error(); + const reader = response.body.getReader(); + const cancel = () => { void reader.cancel().catch(() => {}); }; + signal.addEventListener('abort', cancel, { once: true }); + let complete = false; + try { + const chunks = []; + let size = 0; + for (;;) { + signal.throwIfAborted(); + const { done, value } = await reader.read(); + signal.throwIfAborted(); + if (done) break; + if (!(value instanceof Uint8Array)) throw new Error(); + size += value.byteLength; + if (size > 1024 * 1024) throw new Error(); + chunks.push(value); + } + complete = true; + return JSON.parse(Buffer.concat(chunks, size).toString('utf8')); + } finally { + signal.removeEventListener('abort', cancel); + if (!complete) cancel(); + reader.releaseLock(); + } +} + +// No import-time I/O; Git and HTTP can be replaced by offline test fakes. +export async function preflightRelease({ root = projectRoot, env = process.env, + execFileSync = execute, fetch = globalThis.fetch } = {}) { + const { GITHUB_REF: ref, RELEASE_VERSION: version, RELEASE_SOURCE_SHA: sourceSha, + GITHUB_REPOSITORY, GH_TOKEN: token } = env; + validateReleaseInputs({ ref, version, sourceSha }); + if (GITHUB_REPOSITORY !== repository || typeof token !== 'string' || !token.trim() || /[\r\n]/.test(token)) { + throw new Error('Invalid release environment'); + } + const git = (args) => execFileSync('git', args, { + cwd: root, encoding: 'utf8', timeout: 10_000, maxBuffer: 4 * 1024 * 1024, stdio: ['ignore', 'pipe', 'pipe'], + }); + let failure = 'Release source_sha must be an ancestor of origin/main'; + try { + git(['merge-base', '--is-ancestor', sourceSha, 'origin/main']); + failure = 'Release manifest versions or Tauri configuration do not match source_sha'; + const at = (file) => git(['show', `${sourceSha}:${file}`]); + const versions = [packageJsonVersion(at('package.json')), + ...packageLockVersions(at('package-lock.json')), + cargoTomlVersion(at('src-tauri/Cargo.toml')), + cargoLockVersion(at('src-tauri/Cargo.lock'))]; + const tauri = JSON.parse(at('src-tauri/tauri.conf.json')); + if (versions.some((value) => value !== version) || tauri?.productName !== 'Quorb' || + !['../package.json', version].includes(tauri?.version)) throw new Error(); + + // Bound all pages, annotated-tag hops and response bodies by one deadline. + const signal = AbortSignal.timeout(30_000); + const request = async (route) => readJson(await fetch(`https://api.github.com/repos/${repository}${route}`, { + method: 'GET', redirect: 'error', signal, + headers: { Accept: 'application/vnd.github+json', Authorization: `Bearer ${token}`, + 'X-GitHub-Api-Version': '2022-11-28' }, + }), signal); + const list = async (route) => { + const entries = []; + for (let page = 1; page <= 20; page++) { + const data = await request(`${route}?per_page=100&page=${page}`); + if (!Array.isArray(data) || data.length > 100 || data.some((entry) => !record(entry))) throw new Error(); + entries.push(...data); + if (data.length < 100) return entries; + } + throw new Error(); + }; + failure = 'Unable to verify release metadata'; + // The list endpoint also discovers drafts; the tag endpoint does not. + const releases = await list('/releases'); + if (releases.some((release) => typeof release.tag_name !== 'string')) throw new Error(); + const found = releases.filter((release) => release.tag_name === `v${version}`); + if (found.length === 0) throw new Error(`Release v${version} must already exist`); + if (found.length !== 1 || !Number.isSafeInteger(found[0].id) || found[0].id <= 0 || + typeof found[0].draft !== 'boolean') throw new Error(); + const release = found[0]; + + failure = 'Release tag must point at source_sha'; + let object = (await request(`/git/ref/tags/v${version}`)).object; + const visited = new Set(); + for (let depth = 0; ; depth++) { + if (!record(object) || !validSha(object.sha)) throw new Error(); + if (object.type === 'commit') { + if (object.sha !== sourceSha) throw new Error(); + break; + } + if (object.type !== 'tag' || depth >= 8 || visited.has(object.sha)) throw new Error(); + visited.add(object.sha); + object = (await request(`/git/tags/${object.sha}`)).object; + } + + failure = 'Unable to verify release assets'; + const assets = await list(`/releases/${release.id}/assets`); + if (assets.some((asset) => typeof asset.name !== 'string')) throw new Error(); + for (const name of linuxAssetNames(version)) { + if (assets.some((asset) => asset.name === name)) throw new Error(`Release already contains ${name}`); + } + return { sourceSha, version, releaseId: release.id }; + } catch (error) { + if (failure === 'Unable to verify release metadata' && error.message === `Release v${version} must already exist`) { + throw new Error(error.message); + } + if (failure === 'Unable to verify release assets' && + linuxAssetNames(version).some((name) => error.message === `Release already contains ${name}`)) { + throw new Error(error.message); + } + throw new Error(failure); + } +} + +if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { + try { console.log(JSON.stringify(await preflightRelease())); } + catch (error) { console.error(error.message); process.exitCode = 1; } +} diff --git a/scripts/linux-release-preflight.test.mjs b/scripts/linux-release-preflight.test.mjs new file mode 100644 index 0000000..760255d --- /dev/null +++ b/scripts/linux-release-preflight.test.mjs @@ -0,0 +1,154 @@ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { preflightRelease } from './linux-release-preflight.mjs'; + +const sha = 'a'.repeat(40); +const other = 'b'.repeat(40); +const secret = 'SYNTHETIC_TOKEN_MARKER'; +const version = '0.9.0'; +const names = [`Quorb_${version}_amd64.deb`, `Quorb_${version}_amd64.deb.sha256`, + `Quorb_${version}_amd64.AppImage`, `Quorb_${version}_amd64.AppImage.sha256`]; + +function fixture() { + const calls = []; + const env = { GITHUB_REF: 'refs/heads/main', GITHUB_REPOSITORY: 'egdev6/quorb', + RELEASE_VERSION: version, RELEASE_SOURCE_SHA: sha, GH_TOKEN: secret }; + const files = { + 'package.json': JSON.stringify({ version }), + 'package-lock.json': JSON.stringify({ version, packages: { '': { version } } }), + 'src-tauri/Cargo.toml': `[package]\nname = "quorb"\nversion = "${version}"\n[dependencies]\n`, + 'src-tauri/Cargo.lock': `[[package]]\nname = "quorb"\nversion = "${version}"\n`, + 'src-tauri/tauri.conf.json': JSON.stringify({ productName: 'Quorb', version: '../package.json' }), + }; + const release = { id: 42, tag_name: `v${version}`, draft: false, target_commitish: 'main' }; + const routes = { + '/releases?per_page=100&page=1': [release], + [`/git/ref/tags/v${version}`]: { object: { type: 'commit', sha } }, + '/releases/42/assets?per_page=100&page=1': [], + }; + const options = { env, root: '/fake-root', + execFileSync(command, args, settings) { + calls.push(['git', command, args, settings]); + if (args[0] === 'merge-base') return ''; + assert.equal(args[0], 'show'); + const file = args[1].slice(`${sha}:`.length); + assert.ok(Object.hasOwn(files, file), file); + return files[file]; + }, + async fetch(url, settings) { + calls.push(['fetch', url, settings]); + const route = url.replace('https://api.github.com/repos/egdev6/quorb', ''); + assert.ok(Object.hasOwn(routes, route), `Unexpected route ${route}`); + const value = routes[route]; + return value instanceof Response ? value : new Response(JSON.stringify(value)); + }, + }; + return { env, files, release, routes, calls, options, run: (overrides = {}) => preflightRelease({ ...options, ...overrides }) }; +} +async function rejects(f, message, overrides) { + await assert.rejects(f.run(overrides), (error) => { + assert.equal(error.message, message); + assert.ok(!String(error).includes(secret)); + return true; + }); + assert.ok(f.calls.filter(([kind]) => kind === 'fetch').every(([, , options]) => options.method === 'GET')); +} + +test('accepts exact ancestor, all release manifests, config and existing tag without mutation', async () => { + const f = fixture(); + assert.deepEqual(await f.run(), { sourceSha: sha, version, releaseId: 42 }); + const git = f.calls.filter(([kind]) => kind === 'git'); + assert.deepEqual(git[0][2], ['merge-base', '--is-ancestor', sha, 'origin/main']); + assert.deepEqual(git.slice(1).map(([, , args]) => args[1]), Object.keys(f.files).map((file) => `${sha}:${file}`)); + for (const [, , , settings] of git) assert.equal(settings.cwd, '/fake-root'); + for (const [, url, settings] of f.calls.filter(([kind]) => kind === 'fetch')) { + assert.ok(url.startsWith('https://api.github.com/repos/egdev6/quorb/')); + assert.equal(settings.method, 'GET'); + assert.equal(settings.redirect, 'error'); + assert.equal(settings.headers.Authorization, `Bearer ${secret}`); + } +}); + +test('rejects invalid ref, version, SHA, repository and token before any I/O', async () => { + const cases = [ + ['GITHUB_REF', 'refs/heads/feature', 'Release ref must be refs/heads/main'], + ...[undefined, '', 'v0.9.0', '00.9.0', '0.9.0-rc.1', '0.9.0+build', '0.9.0\n', '../0.9.0'].map((v) => ['RELEASE_VERSION', v, 'Release version must be stable SemVer']), + ...[undefined, '', 'A'.repeat(40), 'g'.repeat(40), `${sha}\n`, sha.slice(1)].map((v) => ['RELEASE_SOURCE_SHA', v, 'Release source_sha must be 40 lowercase hex characters']), + ['GITHUB_REPOSITORY', 'other/quorb', 'Invalid release environment'], + ['GH_TOKEN', '', 'Invalid release environment'], ['GH_TOKEN', `${secret}\n`, 'Invalid release environment'], + ]; + for (const [key, value, message] of cases) { + const f = fixture(); f.env[key] = value; + await rejects(f, message); assert.deepEqual(f.calls, []); + } +}); + +test('rejects non-ancestor and every mismatching or missing version source before HTTP', async () => { + const f = fixture(); + await rejects(f, 'Release source_sha must be an ancestor of origin/main', { execFileSync: () => { throw new Error(secret); } }); + for (const [file, text] of [ + ['package.json', '{"version":"0.8.0"}'], + ['package-lock.json', '{"version":"0.9.0","packages":{"":{"version":"0.8.0"}}}'], + ['src-tauri/Cargo.toml', '[package]\nversion = "0.8.0"'], + ['src-tauri/Cargo.lock', '[[package]]\nname = "quorb"\nversion = "0.8.0"'], + ['src-tauri/tauri.conf.json', '{"productName":"Other","version":"../package.json"}'], + ['src-tauri/tauri.conf.json', '{"productName":"Quorb","version":"0.8.0"}'], + ['package.json', '{'], + ]) { + const g = fixture(); g.files[file] = text; + await rejects(g, 'Release manifest versions or Tauri configuration do not match source_sha'); + assert.ok(!g.calls.some(([kind]) => kind === 'fetch')); + } +}); + +test('requires one existing release and its actual matching tag, including drafts', async () => { + const missing = fixture(); missing.routes['/releases?per_page=100&page=1'] = []; + await rejects(missing, `Release v${version} must already exist`); + const duplicate = fixture(); duplicate.routes['/releases?per_page=100&page=1'] = [duplicate.release, duplicate.release]; + await rejects(duplicate, 'Unable to verify release metadata'); + for (const draft of [true, false]) { + const f = fixture(); f.release.draft = draft; + f.routes[`/git/ref/tags/v${version}`] = new Response('', { status: 404 }); + await rejects(f, 'Release tag must point at source_sha'); + } + const mismatch = fixture(); mismatch.routes[`/git/ref/tags/v${version}`].object.sha = other; + await rejects(mismatch, 'Release tag must point at source_sha'); + const draft = fixture(); draft.release.draft = true; + assert.equal((await draft.run()).releaseId, 42); +}); + +test('resolves annotated tags and rejects cycles and malformed objects', async () => { + const f = fixture(); + f.routes[`/git/ref/tags/v${version}`] = { object: { type: 'tag', sha: other } }; + f.routes[`/git/tags/${other}`] = { object: { type: 'commit', sha } }; + assert.equal((await f.run()).releaseId, 42); + for (const object of [null, {}, { type: 'tree', sha }, { type: 'tag', sha: other }]) { + const g = fixture(); g.routes[`/git/ref/tags/v${version}`] = { object }; + g.routes[`/git/tags/${other}`] = { object: { type: 'tag', sha: other } }; + await rejects(g, 'Release tag must point at source_sha'); + } +}); + +test('checks all four asset names across pages and leaves unrelated release assets intact', async () => { + for (const name of names) { + const f = fixture(); + f.routes['/releases/42/assets?per_page=100&page=1'] = Array.from({ length: 100 }, (_, i) => ({ name: `other-${i}` })); + f.routes['/releases/42/assets?per_page=100&page=2'] = [{ name }]; + await rejects(f, `Release already contains ${name}`); + } + const f = fixture(); + f.routes['/releases?per_page=100&page=1'] = Array.from({ length: 100 }, (_, i) => ({ id: i + 1, tag_name: `other-${i}` })); + f.routes['/releases?per_page=100&page=2'] = [f.release]; + f.routes['/releases/42/assets?per_page=100&page=1'] = [{ name: 'latest.json' }, { name: 'windows.exe' }]; + assert.equal((await f.run()).releaseId, 42); +}); + +test('fails closed on malformed HTTP, pagination and secret-bearing errors', async () => { + for (const value of [new Response('no', { status: 403 }), new Response('{'), new Response(' '.repeat(1024 * 1024 + 1)), {}]) { + const f = fixture(); f.routes['/releases?per_page=100&page=1'] = value; + await rejects(f, 'Unable to verify release metadata'); + } + await rejects(fixture(), 'Unable to verify release metadata', { fetch: async () => { throw new Error(secret); } }); + const f = fixture(); f.routes['/releases/42/assets?per_page=100&page=1'] = [null]; + await rejects(f, 'Unable to verify release assets'); +}); From 5bac5ea7e153c422cccc508306b6b6f84beee74f Mon Sep 17 00:00:00 2001 From: egdev6 Date: Fri, 20 Nov 2026 15:24:17 +0100 Subject: [PATCH 2/4] feat(release): attach Linux bundles without overwrite, with own-upload rollback --- scripts/linux-release-attach.mjs | 110 ++++++++++++++++++ scripts/linux-release-attach.test.mjs | 155 ++++++++++++++++++++++++++ 2 files changed, 265 insertions(+) create mode 100644 scripts/linux-release-attach.mjs create mode 100644 scripts/linux-release-attach.test.mjs diff --git a/scripts/linux-release-attach.mjs b/scripts/linux-release-attach.mjs new file mode 100644 index 0000000..9068938 --- /dev/null +++ b/scripts/linux-release-attach.mjs @@ -0,0 +1,110 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import { createHash } from 'node:crypto'; +import { fileURLToPath } from 'node:url'; +import { validateReleaseInputs } from './macos-release-preflight.mjs'; +import { linuxAssetNames, preflightRelease } from './linux-release-preflight.mjs'; + +const repository = 'egdev6/quorb'; +const maxBundle = 512 * 1024 * 1024; +const hash = (bytes) => createHash('sha256').update(bytes).digest('hex'); +const positiveId = (value) => typeof value === 'string' && /^[1-9][0-9]*$/.test(value) && + Number.isSafeInteger(Number(value)); +const digest = (value) => typeof value === 'string' && /^[0-9a-f]{64}$/.test(value) && value === value.trim(); +const publicationError = (message) => Object.assign(new Error(message), { safePublish: true }); + +// The producer hashes the verified bytes before same-run artifact upload. Refuse +// extra files, symlinks, changed bytes and invalid fingerprints before any POST. +export function loadBundles({ env = process.env, io = fs } = {}) { + validateReleaseInputs({ ref: env.GITHUB_REF, version: env.RELEASE_VERSION, sourceSha: env.RELEASE_SOURCE_SHA }); + if (typeof env.BUNDLE_DIR !== 'string' || !path.isAbsolute(env.BUNDLE_DIR) || + !digest(env.DEB_SHA256) || !digest(env.APPIMAGE_SHA256)) throw new Error('Invalid bundle context'); + const [deb, debSum, appimage, appimageSum] = linuxAssetNames(env.RELEASE_VERSION); + const entries = io.readdirSync(env.BUNDLE_DIR); + if (entries.length !== 2 || !entries.includes(deb) || !entries.includes(appimage)) throw new Error('Unexpected bundle files'); + const read = (name, expected) => { + const file = path.join(env.BUNDLE_DIR, name); + const stat = io.lstatSync(file); + if (!stat.isFile() || stat.isSymbolicLink() || !Number.isSafeInteger(stat.size) || + stat.size < 1 || stat.size > maxBundle) throw new Error('Invalid bundle file'); + const bytes = io.readFileSync(file); + if (!Buffer.isBuffer(bytes) || bytes.length !== stat.size || hash(bytes) !== expected) throw new Error('Bundle digest mismatch'); + return bytes; + }; + const debBytes = read(deb, env.DEB_SHA256); + const appimageBytes = read(appimage, env.APPIMAGE_SHA256); + const checksum = (name, bytes) => Buffer.from(`${hash(bytes)} ${name}\n`); + return new Map([[deb, debBytes], [debSum, checksum(deb, debBytes)], + [appimage, appimageBytes], [appimageSum, checksum(appimage, appimageBytes)]]); +} + +async function uploadId(response) { + if (response?.status !== 201 || typeof response.body?.getReader !== 'function') throw new Error(); + const reader = response.body.getReader(); + let size = 0; + const chunks = []; + try { + for (;;) { + const { done, value } = await reader.read(); + if (done) break; + if (!(value instanceof Uint8Array)) throw new Error(); + size += value.byteLength; + if (size > 65_536) throw new Error(); + chunks.push(value); + } + const data = JSON.parse(Buffer.concat(chunks, size).toString('utf8')); + if (!Number.isSafeInteger(data.id) || data.id <= 0) throw new Error(); + return data.id; + } finally { + await reader.cancel().catch(() => {}); + reader.releaseLock(); + } +} + +export async function attachRelease({ env = process.env, io = fs, fetch = globalThis.fetch, + preflight = preflightRelease } = {}) { + if (!positiveId(env.RELEASE_ID)) throw new Error('Invalid release identity'); + const files = loadBundles({ env, io }); + // Recheck release identity, tag and all four absent names immediately before + // POST. GitHub rejects duplicate names; never use an overwrite/clobber API. + const release = await preflight({ env, fetch }); + if (String(release.releaseId) !== env.RELEASE_ID) throw new Error('Release identity changed'); + const headers = { Authorization: `Bearer ${env.GH_TOKEN}`, Accept: 'application/vnd.github+json', + 'X-GitHub-Api-Version': '2022-11-28' }; + const uploaded = []; + try { + for (const [name, bytes] of files) { + const response = await fetch(`https://uploads.github.com/repos/${repository}/releases/${env.RELEASE_ID}/assets?name=${encodeURIComponent(name)}`, { + method: 'POST', redirect: 'error', signal: AbortSignal.timeout(120_000), + headers: { ...headers, 'Content-Type': name.endsWith('.sha256') ? 'text/plain' : 'application/octet-stream' }, + body: bytes, + }); + const id = await uploadId(response); + if (uploaded.includes(id)) throw new Error(); + uploaded.push(id); + } + } catch { + const failed = []; + // A failed/ambiguous POST has no reliable owned ID: never guess by name. + // Continue rollback even if one deletion fails, and report each failed ID. + for (const id of uploaded.reverse()) { + try { + const response = await fetch(`https://api.github.com/repos/${repository}/releases/assets/${id}`, { + method: 'DELETE', redirect: 'error', signal: AbortSignal.timeout(30_000), headers, + }); + if (response.status !== 204) throw new Error(); + } catch { failed.push(id); } + } + if (failed.length) throw publicationError(`Upload failed; rollback failed for owned asset IDs ${failed.join(', ')}; inspect release assets`); + throw publicationError('Upload failed or ambiguous; removed confirmed uploads only; inspect release assets before retrying'); + } + return { outcome: 'attached', names: [...files.keys()] }; +} + +if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { + try { console.log(JSON.stringify(await attachRelease())); } + catch (error) { + console.error(error.safePublish ? error.message : 'Attachment failed; inspect release assets before recovery'); + process.exitCode = 1; + } +} diff --git a/scripts/linux-release-attach.test.mjs b/scripts/linux-release-attach.test.mjs new file mode 100644 index 0000000..fedaf0d --- /dev/null +++ b/scripts/linux-release-attach.test.mjs @@ -0,0 +1,155 @@ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { createHash } from 'node:crypto'; +import path from 'node:path'; +import { attachRelease, loadBundles } from './linux-release-attach.mjs'; + +const version = '0.9.0'; +const deb = `Quorb_${version}_amd64.deb`; +const appimage = `Quorb_${version}_amd64.AppImage`; +const names = [deb, `${deb}.sha256`, appimage, `${appimage}.sha256`]; +const hash = (bytes) => createHash('sha256').update(bytes).digest('hex'); +const checksum = (name, bytes) => Buffer.from(`${hash(bytes)} ${name}\n`); + +function fixture({ failAt = 0, rollbackFailure = false, badResponse = false } = {}) { + const files = new Map([[deb, Buffer.from('deb bundle')], [appimage, Buffer.from('appimage bundle')]]); + const env = { GITHUB_REF: 'refs/heads/main', GITHUB_REPOSITORY: 'egdev6/quorb', + RELEASE_VERSION: version, RELEASE_SOURCE_SHA: 'a'.repeat(40), RELEASE_ID: '42', + GH_TOKEN: 'fixture-token', BUNDLE_DIR: '/fake-bundles', + DEB_SHA256: hash(files.get(deb)), APPIMAGE_SHA256: hash(files.get(appimage)) }; + const calls = []; + const stored = new Map([['windows.exe', { id: 10, bytes: Buffer.from('untouched') }]]); + let attempt = 0; + const options = { env, + io: { + readdirSync: () => [...files.keys()], + lstatSync: (file) => ({ isFile: () => true, isSymbolicLink: () => false, size: files.get(path.basename(file)).length }), + readFileSync: (file) => files.get(path.basename(file)), + }, + preflight: async () => { calls.push('preflight'); return { releaseId: 42 }; }, + fetch: async (url, request) => { + calls.push([url, request]); + if (request.method === 'DELETE') { + if (rollbackFailure) return new Response('', { status: 500 }); + const id = Number(url.split('/').at(-1)); + for (const [name, asset] of stored) if (asset.id === id) stored.delete(name); + return new Response(null, { status: 204 }); + } + assert.equal(request.method, 'POST'); + attempt++; + if (attempt === failAt) { + if (badResponse) return new Response('not-json', { status: 201 }); + return new Response('fixture-token', { status: 422 }); + } + const name = new URL(url).searchParams.get('name'); + assert.ok(!stored.has(name), 'fake API never overwrites'); + const id = 100 + attempt; + stored.set(name, { id, bytes: request.body }); + return new Response(JSON.stringify({ id }), { status: 201 }); + }, + }; + return { env, files, stored, calls, options, run: (patch = {}) => attachRelease({ ...options, ...patch }) }; +} + +test('loads only exact verified bundles and constructs sha256sum-compatible checksums', () => { + const f = fixture(); + const result = loadBundles(f.options); + assert.deepEqual([...result.keys()], names); + assert.deepEqual(result.get(deb), f.files.get(deb)); + assert.deepEqual(result.get(`${deb}.sha256`), checksum(deb, f.files.get(deb))); + assert.deepEqual(result.get(`${appimage}.sha256`), checksum(appimage, f.files.get(appimage))); +}); + +test('rejects wrong, missing, extra, nonregular or modified artifact files before any upload', async () => { + const scenarios = [ + (f) => f.files.delete(deb), + (f) => f.files.set('unexpected.txt', Buffer.from('x')), + (f) => f.files.set(deb, Buffer.from('changed')), + (f) => { f.env.DEB_SHA256 = 'x'.repeat(64); }, + (f) => { f.options.io.lstatSync = () => ({ isFile: () => false, isSymbolicLink: () => true, size: 1 }); }, + (f) => { f.files.set(appimage, Buffer.alloc(0)); }, + ]; + for (const change of scenarios) { + const f = fixture(); change(f); + await assert.rejects(f.run()); + assert.deepEqual(f.calls, []); + assert.deepEqual([...f.stored.keys()], ['windows.exe']); + } +}); + +test('revalidates release identity and uploads exactly four assets without overwriting', async () => { + const f = fixture(); + assert.deepEqual(await f.run(), { outcome: 'attached', names }); + assert.equal(f.calls[0], 'preflight'); + const requests = f.calls.slice(1); + assert.equal(requests.length, 4); + assert.deepEqual(requests.map(([url]) => new URL(url).searchParams.get('name')), names); + for (const [url, request] of requests) { + assert.ok(url.startsWith('https://uploads.github.com/repos/egdev6/quorb/releases/42/assets?name=')); + assert.equal(request.method, 'POST'); + assert.equal(request.redirect, 'error'); + assert.equal(request.headers.Authorization, 'Bearer fixture-token'); + } + assert.deepEqual(f.stored.get(`${deb}.sha256`).bytes, checksum(deb, f.files.get(deb))); + assert.deepEqual(f.stored.get(`${appimage}.sha256`).bytes, checksum(appimage, f.files.get(appimage))); + assert.deepEqual(f.stored.get('windows.exe'), { id: 10, bytes: Buffer.from('untouched') }); +}); + +test('changed identity, collision or invalid release ID abort before writes', async () => { + for (const change of [ + (f) => { f.options.preflight = async () => ({ releaseId: 43 }); }, + (f) => { f.options.preflight = async () => { throw new Error('Release already contains an asset'); }; }, + (f) => { f.env.RELEASE_ID = '42/../10'; }, + ]) { + const f = fixture(); change(f); + await assert.rejects(f.run()); + assert.ok(!f.calls.some((call) => Array.isArray(call))); + assert.deepEqual([...f.stored.keys()], ['windows.exe']); + } +}); + +test('each partial upload failure rolls back every confirmed asset from this run only', async () => { + for (let failAt = 1; failAt <= names.length; failAt++) { + const f = fixture({ failAt }); + await assert.rejects(f.run(), (error) => { + assert.match(error.message, /upload failed/i); + assert.ok(!error.message.includes('fixture-token')); + return true; + }); + const deletions = f.calls.filter((call) => Array.isArray(call) && call[1].method === 'DELETE'); + assert.deepEqual(deletions.map(([url]) => Number(url.split('/').at(-1))), Array.from({ length: failAt - 1 }, (_, i) => 100 + failAt - 1 - i)); + assert.deepEqual([...f.stored.keys()], ['windows.exe']); + } +}); + +test('a name claimed after preflight is never overwritten or deleted on upload failure', async () => { + const f = fixture(); + const fetch = f.options.fetch; + f.options.fetch = async (url, request) => { + if (request.method === 'POST' && new URL(url).searchParams.get('name') === appimage) { + f.calls.push([url, request]); + f.stored.set(appimage, { id: 900, bytes: Buffer.from('concurrent upload') }); + return new Response('', { status: 422 }); + } + return fetch(url, request); + }; + await assert.rejects(f.run(), /upload failed/i); + assert.deepEqual(f.stored.get(appimage), { id: 900, bytes: Buffer.from('concurrent upload') }); + assert.deepEqual([...f.stored.keys()], ['windows.exe', appimage]); + const deletes = f.calls.filter((call) => Array.isArray(call) && call[1].method === 'DELETE'); + assert.deepEqual(deletes.map(([url]) => Number(url.split('/').at(-1))), [102, 101]); +}); + +test('ambiguous responses roll back confirmed IDs only; failed cleanup is reported and attempted for all', async () => { + const ambiguous = fixture({ failAt: 3, badResponse: true }); + await assert.rejects(ambiguous.run(), /ambiguous|inspect/i); + assert.deepEqual([...ambiguous.stored.keys()], ['windows.exe']); + const failed = fixture({ failAt: 4, rollbackFailure: true }); + await assert.rejects(failed.run(), (error) => { + assert.match(error.message, /rollback failed/i); + for (const id of ['101', '102', '103']) assert.ok(error.message.includes(id)); + return true; + }); + assert.equal(failed.calls.filter((call) => Array.isArray(call) && call[1].method === 'DELETE').length, 3); + assert.ok(failed.stored.has('windows.exe')); +}); From 5bd5fdc3fae81b3f0ef2196863084951e1879252 Mon Sep 17 00:00:00 2001 From: egdev6 Date: Fri, 20 Nov 2026 15:24:17 +0100 Subject: [PATCH 3/4] ci(release): add manual workflow to attach Linux installers to a release --- .github/workflows/linux-release.yml | 222 ++++++++++++++++++++++++ docs/release-linux.md | 21 +++ package.json | 2 +- scripts/linux-release-workflow.test.mjs | 94 ++++++++++ 4 files changed, 338 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/linux-release.yml create mode 100644 docs/release-linux.md create mode 100644 scripts/linux-release-workflow.test.mjs diff --git a/.github/workflows/linux-release.yml b/.github/workflows/linux-release.yml new file mode 100644 index 0000000..36592e6 --- /dev/null +++ b/.github/workflows/linux-release.yml @@ -0,0 +1,222 @@ +name: Attach Linux installers to existing release + +on: + workflow_dispatch: + inputs: + version: + description: Exact stable version of the existing release + required: true + type: string + source_sha: + description: Full lowercase SHA of the release tag, ancestor of main + required: true + type: string + +permissions: + contents: read + +concurrency: + group: linux-release-attach + cancel-in-progress: false + +jobs: + preflight: + name: Validate the existing release and source + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-22.04 + timeout-minutes: 5 + outputs: + source_sha: ${{ steps.validate.outputs.sourceSha }} + version: ${{ steps.validate.outputs.version }} + release_id: ${{ steps.validate.outputs.releaseId }} + steps: + - name: Checkout trusted workflow source + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + ref: ${{ github.sha }} + fetch-depth: 0 + persist-credentials: false + + - name: Node 22 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 + with: + node-version: 22 + package-manager-cache: false + + - name: Validate release, tag and bundle names + id: validate + env: + RELEASE_VERSION: ${{ inputs.version }} + RELEASE_SOURCE_SHA: ${{ inputs.source_sha }} + GH_TOKEN: ${{ github.token }} + run: | + node --input-type=module <<'NODE' + import { appendFileSync } from 'node:fs'; + import { preflightRelease } from './scripts/linux-release-preflight.mjs'; + const result = await preflightRelease(); + for (const [key, value] of Object.entries(result)) { + appendFileSync(process.env.GITHUB_OUTPUT, key + '=' + value + '\n'); + } + NODE + + build: + name: Build and verify Linux bundles + needs: preflight + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-22.04 + timeout-minutes: 90 + outputs: + deb_sha256: ${{ steps.fingerprints.outputs.deb_sha256 }} + appimage_sha256: ${{ steps.fingerprints.outputs.appimage_sha256 }} + artifact_id: ${{ steps.bundles.outputs.artifact-id }} + env: + RELEASE_VERSION: ${{ needs.preflight.outputs.version }} + steps: + # `runner` is not allowed in job-level env; derive the path at runtime. + - name: Set bundle directory + run: echo "BUNDLE_DIR=$RUNNER_TEMP/quorb-bundles" >> "$GITHUB_ENV" + + - name: Checkout trusted verification tools + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + ref: ${{ github.sha }} + persist-credentials: false + + - name: Checkout validated build source + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + ref: ${{ needs.preflight.outputs.source_sha }} + path: source + persist-credentials: false + + - name: Node 22 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 + with: + node-version: 22 + package-manager-cache: false + + - name: Rust stable + uses: dtolnay/rust-toolchain@89b12181fb390509a0842a86cc55eeb8eb928c1d + with: + toolchain: stable + + - name: Install Tauri 2 Linux system dependencies + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + build-essential \ + pkg-config \ + curl \ + wget \ + file \ + patchelf \ + libwebkit2gtk-4.1-dev \ + libxdo-dev \ + libssl-dev \ + libayatana-appindicator3-dev \ + librsvg2-dev \ + libsecret-1-dev \ + gnome-keyring \ + libnotify-dev \ + libfuse2 \ + xvfb \ + dbus \ + dbus-x11 + + - name: Install locked frontend dependencies + working-directory: source + run: npm ci + + - name: Build Linux bundles (deb + AppImage) + working-directory: source + run: npm run app:build + + - name: Stage exactly the expected bundles + run: | + mkdir -p "$BUNDLE_DIR" + cp "source/src-tauri/target/release/bundle/deb/Quorb_${RELEASE_VERSION}_amd64.deb" "$BUNDLE_DIR/" + cp "source/src-tauri/target/release/bundle/appimage/Quorb_${RELEASE_VERSION}_amd64.AppImage" "$BUNDLE_DIR/" + + - name: Launch AppImage directly (FUSE mount path) + run: | + APPIMAGE="$BUNDLE_DIR/Quorb_${RELEASE_VERSION}_amd64.AppImage" + chmod +x "$APPIMAGE" + set +e + timeout -k 10 60 dbus-run-session -- xvfb-run -a "$APPIMAGE" >/tmp/appimage-launch.log 2>&1 + code=$? + set -e + if [ "$code" -ne 124 ]; then + echo "AppImage launch failed (code $code)" >&2 + tail -40 /tmp/appimage-launch.log >&2 + exit 1 + fi + + - name: Build build-verify image + run: docker build -t quorb-build-verify .testcontainer + + - name: Verify bundles in clean Ubuntu 22.04 + run: | + test -f "$BUNDLE_DIR/Quorb_${RELEASE_VERSION}_amd64.deb" + test -f "$BUNDLE_DIR/Quorb_${RELEASE_VERSION}_amd64.AppImage" + docker run --rm -v "$BUNDLE_DIR:/artifacts" --platform linux/amd64 quorb-build-verify + + - name: Fingerprint verified bundles + id: fingerprints + run: | + deb_hash="$(sha256sum "$BUNDLE_DIR/Quorb_${RELEASE_VERSION}_amd64.deb")" + appimage_hash="$(sha256sum "$BUNDLE_DIR/Quorb_${RELEASE_VERSION}_amd64.AppImage")" + echo "deb_sha256=${deb_hash%% *}" >> "$GITHUB_OUTPUT" + echo "appimage_sha256=${appimage_hash%% *}" >> "$GITHUB_OUTPUT" + + - name: Retain verified bundles for this run + id: bundles + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f + with: + name: linux-release-${{ github.run_id }}-${{ github.run_attempt }} + path: ${{ runner.temp }}/quorb-bundles/ + if-no-files-found: error + compression-level: 0 + retention-days: 14 + overwrite: false + + attach: + name: Attach verified bundles without overwrite + needs: [preflight, build] + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-22.04 + timeout-minutes: 15 + permissions: + contents: write + env: + RELEASE_VERSION: ${{ needs.preflight.outputs.version }} + RELEASE_SOURCE_SHA: ${{ needs.preflight.outputs.source_sha }} + RELEASE_ID: ${{ needs.preflight.outputs.release_id }} + DEB_SHA256: ${{ needs.build.outputs.deb_sha256 }} + APPIMAGE_SHA256: ${{ needs.build.outputs.appimage_sha256 }} + steps: + - name: Checkout trusted publication tools + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + ref: ${{ github.sha }} + fetch-depth: 0 + persist-credentials: false + + - name: Node 22 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 + with: + node-version: 22 + package-manager-cache: false + + - name: Download this run's verified bundles by artifact ID + uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 + with: + artifact-ids: ${{ needs.build.outputs.artifact_id }} + merge-multiple: true + path: ${{ runner.temp }}/linux-release-verified + + - name: Revalidate release and attach only the verified files and checksums + env: + GH_TOKEN: ${{ github.token }} + # `runner` is allowed in step-level env, not in job-level env. + BUNDLE_DIR: ${{ runner.temp }}/linux-release-verified + run: node scripts/linux-release-attach.mjs diff --git a/docs/release-linux.md b/docs/release-linux.md new file mode 100644 index 0000000..0048456 --- /dev/null +++ b/docs/release-linux.md @@ -0,0 +1,21 @@ +# Attach Linux installers to an existing release + +Run **Actions → Attach Linux installers to existing release** manually from +`main`. Supply the stable `version` without `v` (for example `0.9.0`) and the +full 40-character lowercase `source_sha` of that release's tag. The SHA must +be an ancestor of `origin/main`; the release and its matching tag must already +exist, including for a draft. Manifest versions and the Tauri configuration +must match. No tag or release is created or changed. + +The Ubuntu 22.04 build verifies both bundles in a clean container and attaches +only `Quorb__amd64.deb`, `Quorb__amd64.AppImage`, and a +`.sha256` file for each. It refuses to overwrite any of these names and checks +again immediately before uploading. On an upload failure it rolls back only +IDs confirmed as uploaded by this run. If an upload response is ambiguous or +rollback fails, inspect the release assets and clean up any reported leftovers +manually before retrying. + +Linux updates are manual: download and install a newer release yourself; there +is no Linux entry in `latest.json`. The `.deb` is recommended. The AppImage +requires FUSE (`libfuse2`) and may fail on some desktops even with FUSE +installed. diff --git a/package.json b/package.json index b4b673a..7ec10b5 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "dev": "vite", "build": "tsc --noEmit && vite build", "typecheck": "tsc --noEmit", - "test": "vitest run --dir src && node --test scripts/bump.test.mjs scripts/i18n-inventory.test.mjs scripts/release-check.test.mjs scripts/setup-signing.test.mjs scripts/dev-retirement.test.mjs scripts/uninstall.test.mjs scripts/installer-locale.test.mjs scripts/security/check-repository.test.mjs scripts/security/semgrep-report.test.mjs scripts/security/export-snapshot.test.mjs scripts/security/snapshot-report.test.mjs scripts/security/semgrep-entry.test.mjs scripts/security/run-semgrep.test.mjs scripts/security/semgrep-parse-gate.test.mjs scripts/security/provision-tools.test.mjs scripts/security/zizmor-report.test.mjs scripts/security/zizmor-entry.test.mjs scripts/security/run-zizmor.test.mjs scripts/security/provider-logo-regexp.test.mjs scripts/security/code-safety.test.mjs scripts/verify-macos-bundle.test.mjs scripts/macos-ci.test.mjs scripts/macos-preview-policy.test.mjs scripts/macos-preview-preflight.test.mjs scripts/macos-preview-artifact.test.mjs scripts/macos-preview-workflow.test.mjs scripts/updates-section-regression.test.mjs scripts/verify-linux-bundles.test.mjs scripts/macos-release-preflight.test.mjs scripts/macos-release-workflow.test.mjs scripts/macos-notary-workflow.test.mjs scripts/macos-notary-checkpoint.test.mjs scripts/macos-notary-submit.test.mjs scripts/macos-notary-artifact.test.mjs scripts/macos-release-resume.test.mjs scripts/macos-release-resume-workflow.test.mjs scripts/macos-release-resume-publish.test.mjs", + "test": "vitest run --dir src && node --test scripts/bump.test.mjs scripts/i18n-inventory.test.mjs scripts/release-check.test.mjs scripts/setup-signing.test.mjs scripts/dev-retirement.test.mjs scripts/uninstall.test.mjs scripts/installer-locale.test.mjs scripts/security/check-repository.test.mjs scripts/security/semgrep-report.test.mjs scripts/security/export-snapshot.test.mjs scripts/security/snapshot-report.test.mjs scripts/security/semgrep-entry.test.mjs scripts/security/run-semgrep.test.mjs scripts/security/semgrep-parse-gate.test.mjs scripts/security/provision-tools.test.mjs scripts/security/zizmor-report.test.mjs scripts/security/zizmor-entry.test.mjs scripts/security/run-zizmor.test.mjs scripts/security/provider-logo-regexp.test.mjs scripts/security/code-safety.test.mjs scripts/verify-macos-bundle.test.mjs scripts/macos-ci.test.mjs scripts/macos-preview-policy.test.mjs scripts/macos-preview-preflight.test.mjs scripts/macos-preview-artifact.test.mjs scripts/macos-preview-workflow.test.mjs scripts/updates-section-regression.test.mjs scripts/verify-linux-bundles.test.mjs scripts/macos-release-preflight.test.mjs scripts/macos-release-workflow.test.mjs scripts/macos-notary-workflow.test.mjs scripts/macos-notary-checkpoint.test.mjs scripts/macos-notary-submit.test.mjs scripts/macos-notary-artifact.test.mjs scripts/macos-release-resume.test.mjs scripts/macos-release-resume-workflow.test.mjs scripts/macos-release-resume-publish.test.mjs scripts/linux-release-workflow.test.mjs scripts/linux-release-preflight.test.mjs scripts/linux-release-attach.test.mjs", "tauri": "tauri", "app:dev": "tauri dev", "app:build": "tauri build", diff --git a/scripts/linux-release-workflow.test.mjs b/scripts/linux-release-workflow.test.mjs new file mode 100644 index 0000000..5a1ca8d --- /dev/null +++ b/scripts/linux-release-workflow.test.mjs @@ -0,0 +1,94 @@ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { readFileSync } from 'node:fs'; + +const read = (name) => readFileSync(new URL(`../${name}`, import.meta.url), 'utf8').replaceAll('\r\n', '\n'); +const workflow = () => read('.github/workflows/linux-release.yml'); +const job = (text, name, next) => text.split(` ${name}:\n`)[1]?.split(next ? ` ${next}:\n` : '\n# end of jobs')[0]; + +test('manual dispatch accepts only the required version and source SHA', () => { + const text = workflow(); + const trigger = text.split('\non:\n')[1]?.split('\npermissions:\n')[0]; + assert.ok(trigger); + assert.deepEqual([...trigger.matchAll(/^ ([\w-]+):/gm)].map((m) => m[1]), ['workflow_dispatch']); + assert.deepEqual([...trigger.matchAll(/^ ([\w-]+):/gm)].map((m) => m[1]), ['version', 'source_sha']); + for (const name of ['version', 'source_sha']) { + assert.match(trigger, new RegExp(` ${name}:\\n(?: [^\\n]*\\n)*? required: true\\n(?: [^\\n]*\\n)*? type: string`)); + } +}); + +test('all three jobs guard main, and only attach receives write permission', () => { + const text = workflow(); + assert.match(text, /\npermissions:\n contents: read\n/); + const preflight = job(text, 'preflight', 'build'); + const build = job(text, 'build', 'attach'); + const attach = job(text, 'attach'); + for (const part of [preflight, build, attach]) { + assert.ok(part); + assert.match(part, /\n if: github\.ref == 'refs\/heads\/main'\n/); + assert.match(part, /\n runs-on: ubuntu-22\.04\n/); + } + assert.doesNotMatch(preflight + build, /contents: write/); + assert.match(attach, /\n permissions:\n contents: write\n/); + assert.equal((text.match(/contents: write/g) ?? []).length, 1); + assert.doesNotMatch(text, /\$\{\{\s*secrets\./); +}); + +test('each action is SHA pinned, and user input never enters run blocks', () => { + const text = workflow(); + const actions = [...text.matchAll(/^\s*-?\s*uses:\s*(\S+)/gm)].map((m) => m[1]); + assert.ok(actions.length >= 6); + for (const action of actions) assert.match(action, /^[^@\s]+@[0-9a-f]{40}$/); + for (const line of text.split('\n').filter((line) => /\$\{\{\s*inputs\./.test(line))) { + assert.match(line, /^\s+(RELEASE_VERSION|RELEASE_SOURCE_SHA): \$\{\{ inputs\.(version|source_sha) \}\}$/); + } + assert.doesNotMatch(text, /run:[^\n]*\$\{\{\s*inputs\./); +}); + +test('validated exact source is built and clean-container verified before same-run attachment', () => { + const text = workflow(); + const preflight = job(text, 'preflight', 'build'); + const build = job(text, 'build', 'attach'); + const attach = job(text, 'attach'); + assert.match(preflight, /scripts\/linux-release-preflight\.mjs/); + assert.match(build, /needs: preflight/); + assert.match(build, /ref: \$\{\{ needs\.preflight\.outputs\.source_sha \}\}\n\s+path: source/); + assert.match(build, /working-directory: source\n\s+run: npm ci/); + assert.match(build, /working-directory: source\n\s+run: npm run app:build/); + for (const dependency of ['libwebkit2gtk-4.1-dev', 'libxdo-dev', 'libssl-dev', 'libayatana-appindicator3-dev', 'librsvg2-dev', 'libsecret-1-dev', 'libfuse2', 'xvfb', 'dbus-x11']) assert.ok(build.includes(dependency), dependency); + assert.match(build, /source\/src-tauri\/target\/release\/bundle\/deb\/Quorb_\$\{RELEASE_VERSION\}_amd64\.deb/); + assert.match(build, /source\/src-tauri\/target\/release\/bundle\/appimage\/Quorb_\$\{RELEASE_VERSION\}_amd64\.AppImage/); + assert.match(build, /docker build -t quorb-build-verify \.testcontainer/); + assert.match(build, /docker run --rm -v "\$BUNDLE_DIR:\/artifacts" --platform linux\/amd64 quorb-build-verify/); + assert.match(build, /actions\/upload-artifact@[0-9a-f]{40}/); + assert.match(attach, /needs: \[preflight, build\]/); + assert.match(attach, /actions\/download-artifact@[0-9a-f]{40}/); + assert.match(attach, /artifact-ids: \$\{\{ needs\.build\.outputs\.artifact_id \}\}/); + assert.match(attach, /run: node scripts\/linux-release-attach\.mjs/); + assert.equal((attach.match(/^\s+run:/gm) ?? []).length, 1, 'attach job cannot invoke another publisher'); + assert.doesNotMatch(text, /gh release|gh api|git tag|git push|\/git\/refs|latest\.json|release body|--clobber|continue-on-error/); +}); + +test('Tauri naming configuration and npm test wiring agree with the release contract', () => { + const config = JSON.parse(read('src-tauri/tauri.conf.json')); + assert.equal(config.productName, 'Quorb'); + assert.equal(config.version, '../package.json'); + const pkg = JSON.parse(read('package.json')); + for (const name of ['linux-release-workflow', 'linux-release-preflight', 'linux-release-attach']) { + assert.ok(pkg.scripts.test.includes(`scripts/${name}.test.mjs`), name); + } +}); + +test('Linux release documentation explains the operator and user caveats', () => { + const text = read('docs/release-linux.md'); + for (const expression of [/workflow_dispatch|Actions/i, /\bversion\b/, /\bsource_sha\b/, /\.deb/, /\.AppImage/, /\.sha256/, /main/, /manual/i, /latest\.json/, /libfuse2/i, /desktop/i, /recommend/i]) assert.match(text, expression); +}); + +test('job-level env uses only contexts GitHub allows there', () => { + // GitHub rejects `runner`, `steps`, `job` and `env` in `jobs..env`; the + // workflow would fail to load before any job runs. + const text = workflow(); + const blocks = [...text.matchAll(/\n env:\n((?: {6}[^\n]*\n)+)/g)]; + assert.ok(blocks.length > 0); + for (const block of blocks) assert.doesNotMatch(block[1], /\$\{\{\s*(runner|steps|job|env)\./, block[1]); +}); From 2456da6ff0d3dc53a28888c9b7658378e759d99d Mon Sep 17 00:00:00 2001 From: egdev6 Date: Fri, 20 Nov 2026 15:24:31 +0100 Subject: [PATCH 4/4] docs(odd): record linux-release verification and slices --- odd/tasks/linux-release-attach.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/odd/tasks/linux-release-attach.md b/odd/tasks/linux-release-attach.md index b38b67e..cf10abd 100644 --- a/odd/tasks/linux-release-attach.md +++ b/odd/tasks/linux-release-attach.md @@ -28,8 +28,8 @@ Owner: @egdev6. Branch: `ci/linux-release-attach`. Risk: item 5 (release deliver | ID | Specs | Route | Commit | | --- | --- | --- | --- | -| T1 | S2–S6 | gentle-ai-worker | — | -| T2 | S1–S6 | gentle-ai-verify (Risk: item 5) | — | +| T1 | S2–S6 | gentle-ai-worker | c04641a, 5bac5ea, 5bd5fdc | +| T2 | S1–S6 | gentle-ai-verify (Risk: item 5) | fix in this commit | | T3 | S1 | parent, after the owner runs the workflow: release notes, README Linux row | — | ## Log @@ -38,3 +38,5 @@ Owner: @egdev6. Branch: `ci/linux-release-attach`. Risk: item 5 (release deliver - L2 (owner): «el instalador ya está para linux no? que la descarga apunte a él» — evidence: no release v0.1.1–v0.9.0 has Linux assets; `release.yml` is Windows-only; Linux bundles are private `linux-ci.yml` artifacts. - L3 (owner): «a ver aclarémonos...hay que sacar la 0.10.0 para poder oficializar el instalador de linux? no podemos arreglar lo que queda e inclurlo en la 0.9.0?» - L4 (owner): «haz el workflow» +- L5 (verify): S3–S6 pass; B1 blocker: `runner.temp` in job-level `env:` (not allowed by GitHub). `scripts/verify-linux-bundles` does not exist; `.testcontainer` (used by linux-ci) is the equivalent. +- L6 (parent): B1 fixed (build: `$RUNNER_TEMP` via `$GITHUB_ENV`; attach: step-level env, keeping a single `run:`), regression test added (RED then GREEN). Focused 21/21, `npm test` exit 0 (vitest 1241, node 329), actionlint v1.7.7 exit 0. Slices: c04641a (preflight), 5bac5ea (attach), 5bd5fdc (workflow + docs).