Files
marqdo-app-harness/scripts/release-manifest.ts
cflmy 980e07dfae
ci/woodpecker/push/ci Pipeline was canceled
build: pin the DSH upstream identity in the package manifest
The tag-only package lane cannot rely on an upstream git remote. Record the\ntested DSH baseline in packages/marqdo/harness/package.json and let the release\nmanifest/evidence fall back to it, so a clean clone still produces a complete\nmanifest. UPSTREAM.md documents the single record and update rule.
2026-11-28 23:14:48 +08:00

153 lines
6.4 KiB
JavaScript
Executable File

#!/usr/bin/env node
/**
* Build the application release manifest, `.sha256` sidecar, optional detached
* Ed25519 signature and build evidence for one packaged archive.
*
* The manifest schema and signing/verification live in the product package;
* this script only supplies release facts. Run from the repository root:
*
* node scripts/release-manifest.ts --archive .ci/marqdo-harness-<v>-<target>.tar.gz \
* [--target <triple>] [--out .ci] [--private-key key.pem --public-key pub.pem]
*/
import { createHash } from 'node:crypto'
import { execFileSync } from 'node:child_process'
import { mkdir, readFile, stat, writeFile } from 'node:fs/promises'
import { basename, join, resolve } from 'node:path'
import {
APP_RELEASE_SCHEMA, APP_RELEASE_SCHEMA_VERSION, assetNameFor, sidecarNameFor,
signAppReleaseManifest, SIGNATURE_ASSET, MANIFEST_ASSET,
} from '../packages/marqdo/harness/src/release/manifest.ts'
import type { AppReleaseManifest } from '../packages/marqdo/harness/src/release/manifest.ts'
/** Parsed CLI flags. */
function args(argv: string[]): Map<string, string[]> {
const map = new Map<string, string[]>()
for (let index = 0; index < argv.length; index++) {
const token = argv[index]
if (token === undefined || !token.startsWith('--')) continue
const value = argv[index + 1]
if (value === undefined || value.startsWith('--')) throw new Error(`missing value for ${token}`)
map.set(token.slice(2), [...(map.get(token.slice(2)) ?? []), value])
index++
}
return map
}
/** Last value of one flag. */
function flag(map: Map<string, string[]>, name: string): string | undefined {
return map.get(name)?.at(-1)
}
/** Git identity helper. */
function git(...command: string[]): string {
try {
return execFileSync('git', command, { encoding: 'utf8' }).trim()
} catch {
return ''
}
}
/** Map the host architecture to a release target. */
function targetOf(machine: string): string {
if (machine === 'x86_64' || machine === 'x64') return 'x86_64-unknown-linux-gnu'
throw new Error(`unsupported packaging architecture: ${machine}`)
}
const parsed = args(process.argv.slice(2))
const archive = flag(parsed, 'archive')
if (archive === undefined) throw new Error('--archive is required')
const archivePath = resolve(archive)
const info = await stat(archivePath)
const bytes = await readFile(archivePath)
const sha256 = createHash('sha256').update(bytes).digest('hex')
const out = resolve(flag(parsed, 'out') ?? '.ci')
await mkdir(out, { recursive: true, mode: 0o700 })
const packageJson = JSON.parse(await readFile(join('packages', 'marqdo', 'harness', 'package.json'), 'utf8')) as { version?: unknown; dshUpstreamSha?: unknown }
const version = typeof packageJson.version === 'string' ? packageJson.version : ''
if (version === '') throw new Error('packages/marqdo/harness/package.json has no version')
const pinnedUpstream = typeof packageJson.dshUpstreamSha === 'string' ? packageJson.dshUpstreamSha : ''
const machine = execFileSync('uname', ['-m'], { encoding: 'utf8' }).trim()
const target = flag(parsed, 'target') ?? targetOf(machine)
if (basename(archivePath) !== assetNameFor(version, target)) {
throw new Error(`archive name must be ${assetNameFor(version, target)}, got ${basename(archivePath)}`)
}
const sourceSha = flag(parsed, 'source-sha') ?? git('rev-parse', 'HEAD')
const upstreamSha = flag(parsed, 'upstream-sha') ?? process.env.MQDH_DSH_UPSTREAM_SHA
?? (git('rev-parse', 'upstream/master') || pinnedUpstream)
if (!/^[0-9a-f]{40}$/.test(sourceSha)) throw new Error(`invalid source SHA: ${sourceSha}`)
if (!/^[0-9a-f]{40}$/.test(upstreamSha)) throw new Error('cannot determine the DSH upstream SHA; set MQDH_DSH_UPSTREAM_SHA')
const node = execFileSync(process.execPath, ['--version'], { encoding: 'utf8' }).trim()
const payload: Omit<AppReleaseManifest, 'signature'> = {
schema: APP_RELEASE_SCHEMA,
schema_version: APP_RELEASE_SCHEMA_VERSION,
app: {
name: 'marqdo-harness',
command: 'mqdh',
version,
source_sha: sourceSha,
dsh_upstream_sha: upstreamSha,
node,
},
platform: {
target,
os: 'linux',
arch: machine === 'x86_64' || machine === 'x64' ? 'x64' : machine,
min_glibc: '2.39',
minimum_os: null,
},
channel: version.includes('-') ? 'beta' : 'stable',
asset: { name: assetNameFor(version, target), size: info.size, sha256, target },
compatibility: {
cli: '>=3.0.0-rc.6 <4.0.0',
bundle: '>=0.1.0',
protocols: { analysis: 3, observation: 1 },
node: '>=24.22.3',
},
known_limits: parsed.get('known-limit') ?? [],
published_at: new Date().toISOString(),
}
let manifest: AppReleaseManifest = payload
let signed = false
const privateKeyPath = flag(parsed, 'private-key')
if (privateKeyPath !== undefined) {
const publicKeyPath = flag(parsed, 'public-key')
if (publicKeyPath === undefined) throw new Error('--public-key is required with --private-key')
manifest = signAppReleaseManifest(payload, await readFile(privateKeyPath, 'utf8'), await readFile(publicKeyPath, 'utf8'))
signed = true
}
const manifestPath = join(out, MANIFEST_ASSET)
await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, { mode: 0o644 })
const sidecarPath = join(out, sidecarNameFor(basename(archivePath)))
await writeFile(sidecarPath, `${sha256} ${basename(archivePath)}\n`, { mode: 0o644 })
if (signed && manifest.signature !== undefined) {
await writeFile(join(out, SIGNATURE_ASSET), `${JSON.stringify(manifest.signature, null, 2)}\n`, { mode: 0o644 })
}
const evidence = {
schema: 'marqdo.mqdh.release-evidence',
schema_version: 1,
generated_at: new Date().toISOString(),
status: 'PASS',
tag: `mqdh-v${version}`,
version,
target,
archive: { name: basename(archivePath), size: info.size, sha256 },
manifest: MANIFEST_ASSET,
signature: signed ? 'ed25519' : 'unsigned',
app: { source_sha: sourceSha, dsh_upstream_sha: upstreamSha, node },
compatibility: payload.compatibility,
commands: [
`node scripts/release-manifest.ts --archive ${basename(archivePath)} --target ${target}`,
],
unverified: [
'official signing key is not configured (release is explicitly unsigned)',
'second clean host and macOS/Windows cold installs are not part of this build',
],
}
await writeFile(join(out, 'release-evidence.json'), `${JSON.stringify(evidence, null, 2)}\n`, { mode: 0o644 })
process.stdout.write(`${JSON.stringify({ manifest: manifestPath, sidecar: sidecarPath, signed, evidence: join(out, 'release-evidence.json') }, null, 2)}\n`)