A stable sideload MSIX embedded releases/win32/stable/<bundle> as its MainBundle Uri, an object nothing publishes. Stable promotion points stable.appinstaller at the receipt-bound archive copy, releases/tag/<archive>/<bundle>. Canary was right only because publish_canary_appinstaller keeps its bundle beside the feed. The JS renderer was a second App Installer writer. The header of msix-shared.mjs and the stable-releases guide both give that job to scripts.bundles.release_artifacts. write_embedded_appinstaller now derives both URLs there and calls write_appinstaller. before-build passes it the release facts through HERMES_PYTHON, the same way channelBuildRequest does. The archive is the one the workflow's handoff stage uses: HERMES_ARCHIVE_TAG, else the payload tag. msixBundleName gives stage-msixbundle.mjs and the descriptor one bundle filename. The contract tests check that the embedded bytes match what stable promotion and canary publication write.
245 lines
9.7 KiB
JavaScript
245 lines
9.7 KiB
JavaScript
#!/usr/bin/env node
|
|
// Native Windows adapter: bundle x64 + arm64 MSIX packages and sign the
|
|
// envelope. Every mode stops at the artifact; CI stages it for native smoke
|
|
// before the separate release Python publisher can write an App Installer feed.
|
|
// Usage: node scripts/stage-msixbundle.mjs --tag vX.Y.Z --candidate
|
|
// node scripts/stage-msixbundle.mjs --tag canary.YYYYMMDDTHHMMSSZ-vX.Y.Z
|
|
import { execFileSync } from 'node:child_process'
|
|
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { parseArgs } from 'node:util'
|
|
|
|
import { appIdentity, CANARY_TAG_RE, channelBuildRequest, msixBundleName } from './msix-shared.mjs'
|
|
import { ensureWindowsBundleTools } from '../apps/desktop/scripts/windows-bundle-tools.mjs'
|
|
|
|
|
|
const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
|
|
/**
|
|
* Plan the universal + per-architecture out-of-store MSIX bundle outputs.
|
|
*
|
|
* The universal bundle uses the 4-part Windows version (`-win.msixbundle`, the
|
|
* `<MainBundle>` feed target), while single-arch bundles use the release file
|
|
* version (`-win-x64.msixbundle`, `-win-arm64.msixbundle`) matching direct
|
|
* download naming. All three share the same 4-part `/bv` version, package
|
|
* family, and publisher so in-place `.msixbundle -> .msixbundle` upgrades work.
|
|
*
|
|
* @param {{ releaseDir: string, name: string, version: string, fileVersion: string }} params
|
|
*/
|
|
export function buildBundlePlan({ releaseDir, name, version, fileVersion }) {
|
|
const x64 = path.join(releaseDir, `${name}-${fileVersion}-win-x64.msix`)
|
|
const arm64 = path.join(releaseDir, `${name}-${fileVersion}-win-arm64.msix`)
|
|
return [
|
|
{
|
|
out: path.join(releaseDir, msixBundleName(name, version)),
|
|
inputs: [x64, arm64],
|
|
stagingDir: path.join(releaseDir, '__bundle-staging-universal'),
|
|
},
|
|
{
|
|
out: path.join(releaseDir, `${name}-${fileVersion}-win-x64.msixbundle`),
|
|
inputs: [x64],
|
|
stagingDir: path.join(releaseDir, '__bundle-staging-x64'),
|
|
},
|
|
{
|
|
out: path.join(releaseDir, `${name}-${fileVersion}-win-arm64.msixbundle`),
|
|
inputs: [arm64],
|
|
stagingDir: path.join(releaseDir, '__bundle-staging-arm64'),
|
|
},
|
|
]
|
|
}
|
|
|
|
function stageFile(src, dst) {
|
|
try {
|
|
fs.linkSync(src, dst)
|
|
} catch {
|
|
fs.copyFileSync(src, dst)
|
|
}
|
|
}
|
|
|
|
function signBundle({ bundle, signtool, dlib, metaPath, signEnv, execFile }) {
|
|
// MSIX/appx packages REQUIRE a timestamp — signtool silently exits 3 on
|
|
// a .msixbundle sign without /tr (untimestamped appx is invalid). And
|
|
// the /tr URL must be one the ATS dlib can speak: the dlib handles the
|
|
// RFC3161 exchange itself (@url: form) and cannot parse a third-party
|
|
// server's response ("no content extracted" with digicert). The only
|
|
// known-working timestamp server for the dlib is Microsoft's own
|
|
// timestamp.acs.microsoft.com (electron-builder's default, and what the
|
|
// build legs' .msix sign uses). acs is intermittently flaky, so retry
|
|
// the whole sign — a retried sign beats a failed bundle, and signtool
|
|
// replaces the signature on re-sign so a retry is safe.
|
|
const sign = () =>
|
|
execFile(signtool, [
|
|
'sign', '/fd', 'SHA256', '/td', 'SHA256', '/tr', 'http://timestamp.acs.microsoft.com',
|
|
'/dlib', dlib, '/dmdf', metaPath, bundle,
|
|
], { stdio: 'inherit', env: signEnv })
|
|
let attempt = 0
|
|
for (;;) {
|
|
try {
|
|
sign()
|
|
break
|
|
} catch (err) {
|
|
attempt += 1
|
|
if (attempt >= 3) throw err
|
|
console.warn(`[stage-msixbundle] sign attempt ${attempt} failed for ${path.basename(bundle)}, retrying…`)
|
|
}
|
|
}
|
|
execFile(signtool, ['verify', '/pa', bundle], { stdio: 'inherit' })
|
|
}
|
|
|
|
/**
|
|
* Assemble and optionally sign every planned .msixbundle from isolated staging
|
|
* directories (Store-*.msix must never ride inside out-of-store bundles).
|
|
*/
|
|
export function stageAndSignBundles({
|
|
plan,
|
|
version,
|
|
makeappx,
|
|
signtool,
|
|
dlib,
|
|
metaPath,
|
|
signing,
|
|
signEnv = process.env,
|
|
execFile = execFileSync,
|
|
}) {
|
|
const uniqueInputs = [...new Set(plan.flatMap(spec => spec.inputs))]
|
|
const missing = uniqueInputs.filter(file => !fs.existsSync(file))
|
|
if (missing.length > 0) {
|
|
throw new Error(`[stage-msixbundle] need both per-arch msix to bundle, missing:\n ${missing.join('\n ')}`)
|
|
}
|
|
|
|
const outputs = []
|
|
for (const spec of plan) {
|
|
fs.rmSync(spec.stagingDir, { recursive: true, force: true })
|
|
fs.mkdirSync(spec.stagingDir, { recursive: true })
|
|
try {
|
|
for (const input of spec.inputs) {
|
|
stageFile(input, path.join(spec.stagingDir, path.basename(input)))
|
|
}
|
|
if (fs.existsSync(spec.out)) fs.rmSync(spec.out, { force: true })
|
|
execFile(makeappx, ['bundle', '/o', '/bv', version, '/d', spec.stagingDir, '/p', spec.out], { stdio: 'inherit' })
|
|
} finally {
|
|
fs.rmSync(spec.stagingDir, { recursive: true, force: true })
|
|
}
|
|
if (signing) {
|
|
signBundle({ bundle: spec.out, signtool, dlib, metaPath, signEnv, execFile })
|
|
}
|
|
outputs.push(spec.out)
|
|
}
|
|
return outputs
|
|
}
|
|
|
|
async function main() {
|
|
const { values } = parseArgs({ options: {
|
|
tag: { type: 'string' }, commit: { type: 'string' }, version: { type: 'string' },
|
|
variant: { type: 'string' }, 'no-upload': { type: 'boolean' }, candidate: { type: 'boolean' },
|
|
'channel-request': { type: 'string' },
|
|
} })
|
|
const channelRequest = values['channel-request']
|
|
? channelBuildRequest({ ...process.env, HERMES_DESKTOP_VARIANT: values.variant || 'bundled',
|
|
_HERMES_CHANNEL_REQUEST_JSON: fs.readFileSync(values['channel-request'], 'utf8') }) : null
|
|
const tag = values.tag
|
|
const commitBuild = values.commit || ''
|
|
const commitVersion = values.version || ''
|
|
const noUpload = values['no-upload'] === true
|
|
const candidate = values.candidate === true
|
|
const variant = values.variant || process.env.HERMES_DESKTOP_VARIANT || 'bundled'
|
|
|
|
if (channelRequest && (tag || commitBuild || values.version || candidate || variant !== 'bundled'
|
|
|| process.env.HERMES_PAYLOAD_TAG || process.env.HERMES_BUILD_COMMIT)) {
|
|
throw new Error('Channel requests cannot select tag, commit, Store or candidate inputs')
|
|
}
|
|
if (commitBuild && (tag || process.env.HERMES_PAYLOAD_TAG || candidate)) {
|
|
throw new Error('Commit builds cannot select a release tag or candidate mode')
|
|
}
|
|
if (!commitBuild && !channelRequest && (values.version !== undefined || noUpload)) {
|
|
throw new Error('--version and --no-upload require --commit')
|
|
}
|
|
|
|
// product-identity.cjs keys the app name off HERMES_DESKTOP_VARIANT — the
|
|
// artifact filenames (HermesBundled-*-win-x64.msix) carry the bundled
|
|
// identity, so the env var MUST match the variant or the msix lookup
|
|
// fails. Set it before anything requires the identity.
|
|
process.env.HERMES_DESKTOP_VARIANT = variant
|
|
if (tag) process.env.HERMES_PAYLOAD_TAG = tag
|
|
|
|
if (commitBuild) {
|
|
if (!/^[a-f0-9]{40}$/.test(commitBuild)) {
|
|
console.error('[stage-msixbundle] --commit must be an exact full 40-hex SHA')
|
|
process.exit(1)
|
|
}
|
|
if (!/^\d+\.\d+\.\d+$/.test(commitVersion)) {
|
|
console.error('[stage-msixbundle] --version=X.Y.Z is required with --commit (the target pyproject version)')
|
|
process.exit(1)
|
|
}
|
|
if (!noUpload) {
|
|
console.error('[stage-msixbundle] commit mode must pass --no-upload (commit builds never write a feed)')
|
|
process.exit(1)
|
|
}
|
|
if (tag) {
|
|
console.error('[stage-msixbundle] --commit and --tag are mutually exclusive')
|
|
process.exit(1)
|
|
}
|
|
process.env.HERMES_BUILD_COMMIT = commitBuild
|
|
process.env.HERMES_PAYLOAD_VERSION = commitVersion
|
|
} else if (!tag && !channelRequest) {
|
|
console.error('[stage-msixbundle] --tag=<vX.Y.Z> is required')
|
|
process.exit(1)
|
|
}
|
|
if (!['bundled', 'light'].includes(variant)) {
|
|
console.error(`[stage-msixbundle] --variant must be 'bundled' or 'light', got '${variant}'`)
|
|
process.exit(1)
|
|
}
|
|
if (process.platform !== 'win32') {
|
|
console.error('[stage-msixbundle] this job must run on a Windows runner (makeappx + signtool)')
|
|
process.exit(1)
|
|
}
|
|
|
|
const canary = CANARY_TAG_RE.test(tag || '')
|
|
if (!commitBuild && !channelRequest && !canary && !candidate) throw new Error('Stable bundles must use the staged stable-release workflow')
|
|
|
|
const desktop = path.join(REPO_ROOT, 'apps', 'desktop')
|
|
const releaseDir = path.join(desktop, 'release')
|
|
const { version, name, fileVersion } = channelRequest
|
|
? { version: channelRequest.windowsVersion, name: channelRequest.identity.artifactNamePascal, fileVersion: channelRequest.version }
|
|
: appIdentity(desktop, tag)
|
|
|
|
const signing = Boolean(process.env.AZURE_SIGN_ENDPOINT && process.env.AZURE_SIGN_ACCOUNT && process.env.AZURE_SIGN_PROFILE)
|
|
const { makeappx, signtool, dlib, dotnetRoot } = await ensureWindowsBundleTools({ signing })
|
|
|
|
const plan = buildBundlePlan({ releaseDir, name, version, fileVersion })
|
|
const metaPath = path.join(releaseDir, 'msixbundle-sign.json')
|
|
const signEnv = { ...process.env }
|
|
if (signing) {
|
|
fs.writeFileSync(metaPath, JSON.stringify({
|
|
Endpoint: process.env.AZURE_SIGN_ENDPOINT,
|
|
CodeSigningAccountName: process.env.AZURE_SIGN_ACCOUNT,
|
|
CertificateProfileName: process.env.AZURE_SIGN_PROFILE,
|
|
}))
|
|
if (dotnetRoot) signEnv.DOTNET_ROOT = dotnetRoot
|
|
} else {
|
|
console.warn('[stage-msixbundle] AZURE_SIGN_* not set — bundles will be UNSIGNED')
|
|
}
|
|
|
|
const outputs = stageAndSignBundles({
|
|
plan,
|
|
version,
|
|
makeappx,
|
|
signtool,
|
|
dlib,
|
|
metaPath,
|
|
signing,
|
|
signEnv,
|
|
})
|
|
|
|
// Local assembly may be unsigned. CI's native smoke requires a valid signature
|
|
// on the receipt-bound download before any release publication can proceed.
|
|
for (const out of outputs) {
|
|
console.log(`[stage-msixbundle] bundle ready (no upload): ${out}`)
|
|
}
|
|
}
|
|
|
|
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
await main()
|
|
}
|