forked from cflmy/deepseek-harness
The GitHub remote is CI/CD only: workflows download the exact Gitea archive for the requested source SHA instead of mirroring the large git history through a proxy (Git pack generation hits Cloudflare 524 limits). Source/SHA stay authoritative in Gitea; run-name + evidence record the Gitea SHA. The scheduled dispatcher reads Gitea tags and requests a release build for tags without an authoritative Release. Also allow MQDH_SOURCE_SHA without git metadata.
199 lines
8.8 KiB
JavaScript
Executable File
199 lines
8.8 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, portableZipNameFor, 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 packaging host to a release target. */
|
|
function targetOf(nodePlatform: string, machine: string): string {
|
|
if (nodePlatform === 'win32') {
|
|
if (machine === 'x64' || machine === 'x86_64') return 'x86_64-pc-windows-msvc'
|
|
throw new Error(`unsupported packaging architecture: ${machine}`)
|
|
}
|
|
if (nodePlatform === 'linux') {
|
|
if (machine === 'x86_64' || machine === 'x64') return 'x86_64-unknown-linux-gnu'
|
|
throw new Error(`unsupported packaging architecture: ${machine}`)
|
|
}
|
|
throw new Error(`unsupported packaging platform: ${nodePlatform}`)
|
|
}
|
|
|
|
/** Release platform fields for one supported target. */
|
|
function platformFieldsFor(target: string): { os: string; arch: string; min_glibc: string | null } {
|
|
if (target === 'x86_64-pc-windows-msvc') return { os: 'windows', arch: 'x64', min_glibc: null }
|
|
if (target === 'x86_64-unknown-linux-gnu') return { os: 'linux', arch: 'x64', min_glibc: '2.39' }
|
|
throw new Error(`unsupported release target: ${target}`)
|
|
}
|
|
|
|
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 = process.arch
|
|
const target = flag(parsed, 'target') ?? targetOf(process.platform, machine)
|
|
const platformFields = platformFieldsFor(target)
|
|
const format = flag(parsed, 'format') ?? 'tar.gz'
|
|
if (format !== 'tar.gz' && format !== 'portable-zip') throw new Error(`unsupported release format: ${format}`)
|
|
const expectedName = format === 'portable-zip' ? portableZipNameFor(version) : assetNameFor(version, target)
|
|
if (basename(archivePath) !== expectedName) {
|
|
throw new Error(`archive name must be ${expectedName}, got ${basename(archivePath)}`)
|
|
}
|
|
const envSourceSha = (process.env.MQDH_SOURCE_SHA ?? '').trim()
|
|
const sourceSha = flag(parsed, 'source-sha') ?? (envSourceSha !== '' ? envSourceSha : 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: platformFields.os,
|
|
arch: platformFields.arch,
|
|
min_glibc: platformFields.min_glibc,
|
|
minimum_os: null,
|
|
},
|
|
channel: version.includes('-') ? 'beta' : 'stable',
|
|
asset: { name: expectedName, 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 ciProvider = (process.env.MQDH_CI_PROVIDER ?? '').trim()
|
|
let ci: Record<string, unknown> | undefined
|
|
if (ciProvider === 'github-actions') {
|
|
const runId = Number(process.env.GITHUB_RUN_ID ?? '')
|
|
const headSha = (process.env.MQDH_CI_HEAD_SHA ?? process.env.GITHUB_SHA ?? '').trim()
|
|
if (!Number.isInteger(runId) || runId <= 0) throw new Error('GITHUB_RUN_ID is required for github-actions evidence')
|
|
if (headSha !== sourceSha) throw new Error(`GITHUB_SHA ${headSha} does not match source ${sourceSha}`)
|
|
const repository = (process.env.GITHUB_REPOSITORY ?? 'cflmy/marqdo-app-harness').trim()
|
|
ci = {
|
|
provider: 'github-actions',
|
|
workflow: (process.env.MQDH_CI_WORKFLOW ?? 'mqdh-tauri-release.yml').trim(),
|
|
run_id: runId,
|
|
run_url: (process.env.MQDH_CI_RUN_URL ?? `https://github.com/${repository}/actions/runs/${runId}`).trim(),
|
|
head_sha: headSha,
|
|
}
|
|
} else if (ciProvider !== '') {
|
|
throw new Error(`unsupported MQDH_CI_PROVIDER: ${ciProvider}`)
|
|
}
|
|
|
|
const evidence = {
|
|
schema: 'marqdo.mqdh.release-evidence',
|
|
schema_version: 1,
|
|
generated_at: new Date().toISOString(),
|
|
status: 'PASS',
|
|
tag: flag(parsed, 'tag') ?? `mqdh-v${version}`,
|
|
version,
|
|
target,
|
|
archive: { name: basename(archivePath), size: info.size, sha256 },
|
|
format,
|
|
manifest: MANIFEST_ASSET,
|
|
signature: signed ? 'ed25519' : 'unsigned',
|
|
app: { source_sha: sourceSha, dsh_upstream_sha: upstreamSha, node },
|
|
compatibility: payload.compatibility,
|
|
...(ci === undefined ? {} : { ci }),
|
|
dependencies: (() => {
|
|
const cliSha = (process.env.MQDH_CLI_SOURCE_SHA ?? '').trim()
|
|
if (cliSha === '') return []
|
|
if (!/^[0-9a-f]{40}$/.test(cliSha)) throw new Error('MQDH_CLI_SOURCE_SHA must be a full commit SHA')
|
|
return [{ id: 'cli', source_sha: cliSha }]
|
|
})(),
|
|
commands: [
|
|
`node scripts/release-manifest.ts --archive ${basename(archivePath)} --target ${target} --format ${format}`,
|
|
],
|
|
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`)
|