Files
deepseek-harness/scripts/release/process.ts
T
winewill 1b6451a647 fix(desktop): follow the documented release version rules
Review found that `apps/desktop/README.md#release-versions` and the
2026-09-16 version-derivation note already specify this convention, and
that three of their requirements were reversed without saying so. The
rules themselves are right; what was wrong was leaving them undocumented
and rejecting one of the forms they prescribe.

A stable base takes `-test.YYYYMMDD.index`, which validation refused
because such a version ranks below its base. That ordering is the point:
the form belongs to a test feed that never serves the production
release. Both READMEs, the older note, and a new note now record which
requirements this change reverses and why.

Three defects the review found, each reproducible:

- `afterPack` compared the bundled runtime against the product version,
  which broke installed-update qualification: that flow passes a runtime
  whose version was deliberately rewritten. The expected version is now
  a parameter the preparer supplies, and `verifyDesktopRuntime` says
  "bundled X is not the expected Y" rather than naming Electron.
- Upload could only learn the published version from a shell variable,
  conflicting with "release fields come only from the target file". It
  reads the completion record packaging wrote, and a mismatch now prints
  the version that record holds.
- Automatic numbering read one listing page and one fixed directory. It
  now follows every page, discards a listing it could not finish rather
  than reusing an index that would overwrite a published installer,
  bounds the request through the client's own timeout, and reads the
  directory an unsigned build actually writes.

Also: `npm run` and `yarn run` set `npm_execpath` too, so the pnpm
resolution checks the path names pnpm; the argument separator can arrive
after a run script's preset arguments, not only first; and the toolchain
probe, parser, build commit, and tarball readers now have specs.
2026-09-21 16:04:08 +08:00

125 lines
5.3 KiB
TypeScript

/**
* Process helpers shared by the release scripts: the release steps drive `git`,
* `pnpm`, `npm`, and `tar`, and each needs one of three failure behaviours.
*/
import { spawn, spawnSync } from 'node:child_process'
import { existsSync, realpathSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
/** Where and with what environment a release step runs a command. */
export interface RunOptions {
readonly cwd?: string
readonly env?: NodeJS.ProcessEnv
}
/** What a command produced, for a caller that decides what a failure means. */
export interface CommandResult {
/** Exit status, or null when a signal ended the process. */
readonly status: number | null
readonly stdout: string
readonly stderr: string
}
/**
* Run a command and capture its output without judging the exit status.
* @param command - executable name.
* @param args - command arguments.
* @param options - working directory and environment.
* @returns The exit status and captured streams.
*/
export function attempt(command: string, args: readonly string[], options: RunOptions = {}): CommandResult {
const result = spawnSync(command, [...args], { cwd: options.cwd, env: options.env, encoding: 'utf8' })
if (result.error !== undefined) throw result.error
return { status: result.status, stdout: result.stdout, stderr: result.stderr }
}
/**
* Run a command, then echo and return its captured output. Output is buffered
* until exit and stdout precedes stderr.
* @param command - executable name.
* @param args - command arguments.
* @param options - working directory and environment.
* @returns The exit status and captured streams.
*/
export function attemptEchoed(command: string, args: readonly string[], options: RunOptions = {}): CommandResult {
const result = spawnSync(command, [...args], {
cwd: options.cwd,
env: options.env,
encoding: 'utf8',
stdio: ['inherit', 'pipe', 'pipe'],
})
if (result.error !== undefined) throw result.error
if (result.stdout !== '') process.stdout.write(result.stdout)
if (result.stderr !== '') process.stderr.write(result.stderr)
return { status: result.status, stdout: result.stdout, stderr: result.stderr }
}
/**
* Run a command, capture its standard output, and fail on a non-zero exit.
* @param command - executable name.
* @param args - command arguments.
* @param options - working directory and environment.
* @returns The trimmed standard output.
*/
export function capture(command: string, args: readonly string[], options: RunOptions = {}): string {
const result = attempt(command, args, options)
if (result.status !== 0) {
throw new Error(`${command} ${args.join(' ')} exited with ${String(result.status)}:\n${result.stdout}\n${result.stderr}`)
}
return result.stdout.trim()
}
/**
* Run a command with inherited streams without blocking the event loop, so a
* caller can hold several commands in flight, and fail on a non-zero exit.
* Concurrent children interleave their output at line granularity.
* @param command - executable name.
* @param args - command arguments.
* @param options - working directory and environment.
* @returns Resolves when the command exits with status zero.
*/
export function runConcurrent(command: string, args: readonly string[], options: RunOptions = {}): Promise<void> {
return new Promise((resolveRun, rejectRun) => {
const child = spawn(command, [...args], { cwd: options.cwd, env: options.env, stdio: 'inherit' })
child.once('error', rejectRun)
child.once('close', (status, signal) => {
if (status === 0) resolveRun()
else rejectRun(new Error(`${command} ${args.join(' ')} exited with ${String(status ?? signal)}`))
})
})
}
/**
* Return whether Node started the given module as the process entry point.
* @param moduleUrl - the caller's `import.meta.url`.
* @returns True when Node started this module.
*/
export function isEntry(moduleUrl: string): boolean {
const invoked = process.argv[1]
if (invoked === undefined) return false
return realpathSync(invoked) === realpathSync(fileURLToPath(moduleUrl))
}
/**
* Resolve pnpm as a command prefix that spawns without a shell. On Windows the
* `pnpm` shim is a `.cmd` batch file, which `spawnSync` refuses to run unless a
* shell interprets it, so the prefix runs pnpm's JavaScript entry with the
* current Node instead: the entry that launched this script when a run-script
* did, or the workspace's own pnpm dependency otherwise. pnpm's manifest does
* not export its bin entry, so the dependency is located on disk rather than
* through module resolution.
* @returns Command and leading arguments to prepend before pnpm's arguments.
*/
export function pnpmCommand(): readonly [command: string, ...args: string[]] {
const execpath = process.env.npm_execpath
// `npm run` and `yarn run` set this too, and handing pnpm's arguments to either would write a different lockfile.
if (execpath !== undefined && /[\\/]pnpm[\\/]/u.test(execpath) && /\.[cm]?js$/u.test(execpath)) return [process.execPath, execpath]
for (let directory = dirname(fileURLToPath(import.meta.url)); ; directory = dirname(directory)) {
const entry = join(directory, 'node_modules', 'pnpm', 'bin', 'pnpm.cjs')
if (existsSync(entry)) return [process.execPath, entry]
if (dirname(directory) === directory) return ['pnpm']
}
}