119 lines
5.9 KiB
JavaScript
119 lines
5.9 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Verify the release manifest against BOTH install channels:
|
|
* - dsh-market-index/index.json (standalone component installs)
|
|
* - QQ-dsh/components.json + vendored package.json (bundle installs)
|
|
*
|
|
* Usage:
|
|
* node verify-release.mjs --qq-dsh ../QQ-dsh
|
|
*
|
|
* This is a static consistency check. It does not build, publish, or modify
|
|
* anything; build artifacts are checked for presence only.
|
|
*/
|
|
import { existsSync, readFileSync } from 'node:fs'
|
|
import { dirname, join, resolve } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const ROOT = dirname(fileURLToPath(import.meta.url))
|
|
const args = process.argv.slice(2)
|
|
const qqAt = args.indexOf('--qq-dsh')
|
|
const QQ = resolve(qqAt >= 0 ? args[qqAt + 1] : join(ROOT, '..', 'QQ-dsh'))
|
|
const sourcesAt = args.indexOf('--sources')
|
|
const SOURCES = sourcesAt >= 0 ? resolve(args[sourcesAt + 1]) : null
|
|
|
|
let checks = 0
|
|
let failures = 0
|
|
function check(condition, label) {
|
|
checks += 1
|
|
if (condition) console.log(`PASS ${label}`)
|
|
else { failures += 1; console.log(`FAIL ${label}`) }
|
|
}
|
|
function readJson(path) { return JSON.parse(readFileSync(path, 'utf8')) }
|
|
function gitHead(dir) {
|
|
try {
|
|
let head = readFileSync(join(dir, '.git', 'HEAD'), 'utf8').trim()
|
|
if (head.startsWith('ref: ')) head = readFileSync(join(dir, '.git', head.slice(5)), 'utf8').trim()
|
|
return /^[0-9a-f]{40}$/i.test(head) ? head : null
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
const manifestPath = join(ROOT, 'release-manifest.json')
|
|
check(existsSync(manifestPath), 'release-manifest.json exists')
|
|
if (!existsSync(manifestPath)) process.exit(1)
|
|
const manifest = readJson(manifestPath)
|
|
const components = Array.isArray(manifest.components) ? manifest.components : []
|
|
check(components.length === 4, `release manifest lists four components (${components.length})`)
|
|
|
|
const indexPath = join(ROOT, 'index.json')
|
|
check(existsSync(indexPath), 'index.json exists')
|
|
if (existsSync(indexPath)) {
|
|
const index = readJson(indexPath)
|
|
for (const component of components) {
|
|
const plugin = (index.plugins ?? []).find((item) => item.name === component.package)
|
|
check(plugin !== undefined, `index has ${component.package}`)
|
|
if (plugin === undefined) continue
|
|
const version = plugin.versions?.[0]
|
|
check(version?.version === component.version, `index version ${component.package} = ${component.version}`)
|
|
check(version?.source?.commit === component.sourceCommit, `index commit ${component.package} = ${String(component.sourceCommit).slice(0, 8)}…`)
|
|
check(version?.source?.url?.endsWith(`/${component.repo}`), `index repo ${component.package} -> ${component.repo}`)
|
|
}
|
|
}
|
|
|
|
const qqPkgPath = join(QQ, 'package.json')
|
|
const qqComponentsPath = join(QQ, 'components.json')
|
|
check(existsSync(qqPkgPath), `QQ-dsh package.json exists at ${QQ}`)
|
|
check(existsSync(qqComponentsPath), 'QQ-dsh components.json exists')
|
|
if (existsSync(qqPkgPath) && existsSync(qqComponentsPath)) {
|
|
const qqPkg = readJson(qqPkgPath)
|
|
const qqComponents = readJson(qqComponentsPath)
|
|
const qqHead = gitHead(QQ)
|
|
check(qqHead !== null, 'QQ-dsh is a Git checkout with a resolvable HEAD')
|
|
if (qqHead !== null && manifest.bundle?.sourceCommit) {
|
|
check(qqHead === manifest.bundle.sourceCommit, `QQ-dsh HEAD = ${String(manifest.bundle.sourceCommit).slice(0, 8)}…`)
|
|
}
|
|
check(qqComponents.length === components.length, `QQ-dsh vendors ${components.length} components`)
|
|
check(qqPkg.version === manifest.bundle?.version, `QQ-dsh bundle version = ${manifest.bundle?.version}`)
|
|
for (const component of components) {
|
|
const vendored = qqComponents.find((item) => item.id === component.id)
|
|
check(vendored !== undefined, `QQ-dsh has component ${component.id}`)
|
|
if (vendored === undefined) continue
|
|
check(vendored.package === component.package, `QQ-dsh package ${component.id} = ${component.package}`)
|
|
check(vendored.version === component.version, `QQ-dsh version ${component.id} = ${component.version}`)
|
|
check(vendored.sourceCommit === component.sourceCommit, `QQ-dsh commit ${component.id} = ${String(component.sourceCommit).slice(0, 8)}…`)
|
|
const vendorPkg = join(QQ, vendored.vendorPath, 'package.json')
|
|
check(existsSync(vendorPkg), `QQ-dsh vendored package exists: ${vendored.vendorPath}`)
|
|
if (existsSync(vendorPkg)) {
|
|
const pkg = readJson(vendorPkg)
|
|
check(pkg.name === component.package && pkg.version === component.version, `QQ-dsh vendored ${component.id} version matches`)
|
|
}
|
|
}
|
|
// Optional: verify the source checkouts actually contain the pinned commits
|
|
// and declared package versions (run with --sources /path/to/dsh-org-fixes).
|
|
if (SOURCES !== null) {
|
|
for (const component of components) {
|
|
const dir = join(SOURCES, component.repo)
|
|
check(existsSync(join(dir, 'package.json')), `source checkout exists: ${component.repo}`)
|
|
if (!existsSync(join(dir, 'package.json'))) continue
|
|
const pkg = readJson(join(dir, 'package.json'))
|
|
check(pkg.name === component.package && pkg.version === component.version, `source package ${component.repo} = ${component.package} ${component.version}`)
|
|
check(gitHead(dir) === component.sourceCommit, `source HEAD ${component.repo} = ${String(component.sourceCommit).slice(0, 8)}…`)
|
|
}
|
|
}
|
|
// Build artifacts both channels install must be present.
|
|
for (const artifact of [
|
|
join(QQ, 'vendor', 'dsh-sansheng-liubu', 'workbench', 'panel', 'lib', 'client.js'),
|
|
join(QQ, 'vendor', 'dsh-brain', 'lib', 'index.js'),
|
|
join(QQ, 'vendor', 'dsh-brain', 'client', 'index.js'),
|
|
join(QQ, 'vendor', 'workspace-groups-remote', 'lib', 'client.js'),
|
|
join(QQ, 'vendor', 'workspace-groups-remote', 'lib', 'remote-ssh', 'index.js'),
|
|
join(QQ, 'vendor', 'dsh-better-chat', 'lib', 'client.js'),
|
|
]) {
|
|
check(existsSync(artifact), `artifact present: ${artifact.slice(QQ.length + 1)}`)
|
|
}
|
|
}
|
|
|
|
console.log(`\nverify-release: ${checks - failures}/${checks} checks passed`)
|
|
process.exit(failures === 0 ? 0 : 1)
|