release macos|linux: --commit <ref> builds an exact commit (its submodule pointers included), the artifact version comes from that commit

This commit is contained in:
CRTkafa 2026-09-30 23:33:11 +07:00
parent cffbe8946f
commit 581e77b22d
3 changed files with 44 additions and 26 deletions

View file

@ -50,13 +50,13 @@ export const RELEASE_USAGE = `Usage:
waybetter release macos --dmg <file.dmg> --updater <file.app.tar.gz> [--arch universal] [--config <file>]
Signs the updater bundle of a universal macOS build here, copies both into <outDir>/upload and
adds darwin-aarch64 and darwin-x86_64 to latest.json (run the Windows step first).
waybetter release macos --remote <user@host> [--ssh-key <file>] [--remote-dir <dir>] [--build-only]
Builds the COMMITTED state (HEAD and the submodules at their recorded commits, exported with
waybetter release macos --remote <user@host> [--ssh-key <file>] [--remote-dir <dir>] [--commit <ref>] [--build-only]
Builds the COMMITTED state (HEAD, or --commit <ref>, and the submodules at their recorded commits, exported with
git archive, never the working tree) on a Mac over SSH, universal and ad-hoc signed, without
a build path in it; brings the .dmg and .app.tar.gz to <outDir>/build/macos, scans them here,
then (unless --build-only) continues as above. The built .app stays in the remote work
folder (<remote-dir>/out); nothing is installed or replaced on the Mac. Env: WAYBETTER_MAC_SSH (user@host), WAYBETTER_MAC_SSH_KEY.
waybetter release linux --wsl [<distro>] [--remote-dir <dir>] [--build-only]
waybetter release linux --wsl [<distro>] [--remote-dir <dir>] [--commit <ref>] [--build-only]
Builds the committed state in WSL (default distro Ubuntu-22.04, or WAYBETTER_WSL_DISTRO): the
AppImage and the .deb in <outDir>/build/linux, scanned here; then (unless --build-only) the
same as \`release linux --appimage\`.
@ -324,14 +324,15 @@ function signFile(config, file, version, env) {
/** `waybetter release macos`: adds a universal macOS build (built unsigned on the Mac) to the release. */
export async function releaseMacos(config, args, { env = process.env, log = console.log } = {}) {
const version = JSON.parse(readFileSync(join(config.root, 'package.json'), 'utf8')).version;
let version = JSON.parse(readFileSync(join(config.root, 'package.json'), 'utf8')).version;
let dmg = option(args, '--dmg');
let updater = option(args, '--updater');
const target = option(args, '--remote') ?? (dmg ? undefined : env.WAYBETTER_MAC_SSH);
if (target) {
const built = buildMacRemote({ config, target, key: option(args, '--ssh-key') ?? env.WAYBETTER_MAC_SSH_KEY, remoteDir: option(args, '--remote-dir'), env, log });
const built = buildMacRemote({ config, target, key: option(args, '--ssh-key') ?? env.WAYBETTER_MAC_SSH_KEY, remoteDir: option(args, '--remote-dir'), ref: option(args, '--commit'), env, log });
scanBuilt(config, [built.dmg, built.updater], { env, log });
if (built.version !== version) fail(`the committed version is ${built.version} but the working tree says ${version}: commit or sync first`);
if (option(args, '--commit')) version = built.version;
else if (built.version !== version) fail(`the committed version is ${built.version} but the working tree says ${version}: commit or sync first`);
if (args.includes('--build-only')) {
log(`release-macos: built ${built.sha.slice(0, 12)} in ${relative(config.root, built.dir).replaceAll('\\', '/')} (scanned, not signed)`);
return { version, dir: built.dir, files: [built.dmg, built.updater] };
@ -378,15 +379,16 @@ then publish latest.json the same way (tmp file, then mv), and verify
/** `waybetter release linux`: adds the AppImage (signed here: it is the update payload) and the .deb. */
export async function releaseLinux(config, args, { env = process.env, log = console.log } = {}) {
const version = JSON.parse(readFileSync(join(config.root, 'package.json'), 'utf8')).version;
let version = JSON.parse(readFileSync(join(config.root, 'package.json'), 'utf8')).version;
let appimage = option(args, '--appimage');
let deb = option(args, '--deb');
if (args.includes('--wsl')) {
const next = args[args.indexOf('--wsl') + 1];
const distro = next && !next.startsWith('--') ? next : env.WAYBETTER_WSL_DISTRO;
const built = buildLinuxWsl({ config, distro, remoteDir: option(args, '--remote-dir'), env, log });
const built = buildLinuxWsl({ config, distro, remoteDir: option(args, '--remote-dir'), ref: option(args, '--commit'), env, log });
scanBuilt(config, [built.appimage, built.deb], { env, log });
if (built.version !== version) fail(`the committed version is ${built.version} but the working tree says ${version}: commit or sync first`);
if (option(args, '--commit')) version = built.version;
else if (built.version !== version) fail(`the committed version is ${built.version} but the working tree says ${version}: commit or sync first`);
if (args.includes('--build-only')) {
log(`release-linux: built ${built.sha.slice(0, 12)} in ${relative(config.root, built.dir).replaceAll('\\', '/')} (scanned, not signed)`);
return { version, dir: built.dir, files: [built.appimage, built.deb] };

View file

@ -38,12 +38,12 @@ function git(root, args, options) {
return result.stdout ?? '';
}
/** A file of the committed state (`git show HEAD:<path>`), for the version and product name. */
export const committedFile = (root, path) => git(root, ['show', `HEAD:${path}`]);
/** A file of the committed state (`git show <ref>:<path>`), for the version and product name. */
export const committedFile = (root, path, ref = 'HEAD') => git(root, ['show', `${ref}:${path}`]);
/** The submodules HEAD records: [{ path, sha }]. */
export function committedSubmodules(root) {
return git(root, ['ls-tree', '-r', 'HEAD'])
/** The submodules `ref` (default HEAD) records: [{ path, sha }]. */
export function committedSubmodules(root, ref = 'HEAD') {
return git(root, ['ls-tree', '-r', ref])
.split('\n')
.map(line => /^160000 commit ([0-9a-f]{40})\t(.+)$/.exec(line))
.filter(Boolean)
@ -55,13 +55,13 @@ export function committedSubmodules(root) {
* `.tar.gz` at `file`. Returns `{ sha, submodules, file, bytes, dirty }`; `dirty` lists tracked
* files changed in the working tree, which the export ignores by design.
*/
export function exportCommitted({ root, file, exclude = [], log = () => {} }) {
const sha = git(root, ['rev-parse', 'HEAD']).trim();
const submodules = committedSubmodules(root);
export function exportCommitted({ root, file, ref = 'HEAD', exclude = [], log = () => {} }) {
const sha = git(root, ['rev-parse', `${ref}^{commit}`]).trim();
const submodules = committedSubmodules(root, sha);
const dirty = git(root, ['status', '--porcelain', '--untracked-files=no']).split('\n').filter(Boolean).length;
const staging = mkdtempSync(join(tmpdir(), 'wb-export-'));
try {
const parts = [{ repo: root, ref: 'HEAD', prefix: '' }, ...submodules.map(({ path, sha: ref }) => ({ repo: join(root, path), ref, prefix: `${path}/`, path }))];
const parts = [{ repo: root, ref: sha, prefix: '' }, ...submodules.map(({ path, sha: ref }) => ({ repo: join(root, path), ref, prefix: `${path}/`, path }))];
for (const [index, part] of parts.entries()) {
if (part.path && !existsSync(join(part.repo, '.git'))) fail(`submodule ${part.path} is not checked out here (needed for commit ${part.ref.slice(0, 12)})`);
const tarName = `part-${index}.tar`;
@ -188,18 +188,18 @@ function stream(command, args, { log, label }) {
* Builds the committed state of the app on a Mac over SSH and brings the .dmg and the .app.tar.gz
* back to `<outDir>/build/macos`. Returns `{ version, sha, dir, dmg, updater }`.
*/
export function buildMacRemote({ config, target, key, remoteDir, env = process.env, log = console.log }) {
export function buildMacRemote({ config, target, key, remoteDir, ref = 'HEAD', env = process.env, log = console.log }) {
if (!target || !/^[A-Za-z0-9._-]+@[A-Za-z0-9._:-]+$/.test(target)) fail('a Mac needs --remote user@host (or WAYBETTER_MAC_SSH)');
const { root } = config;
const version = JSON.parse(committedFile(root, 'package.json')).version;
const productName = JSON.parse(committedFile(root, relTauri(config, 'tauri.conf.json'))).productName;
const version = JSON.parse(committedFile(root, 'package.json', ref)).version;
const productName = JSON.parse(committedFile(root, relTauri(config, 'tauri.conf.json'), ref)).productName;
const workDir = workDirOf(remoteDir, config.artifact);
const dir = join(config.outDir, 'build', 'macos');
mkdirSync(dir, { recursive: true });
for (const name of readdirSync(dir)) rmSync(join(dir, name), { force: true, recursive: true });
const scratch = mkdtempSync(join(tmpdir(), 'wb-mac-'));
try {
const exported = exportCommitted({ root, file: join(scratch, 'source.tgz'), exclude: config.exportExclude, log });
const exported = exportCommitted({ root, file: join(scratch, 'source.tgz'), ref, exclude: config.exportExclude, log });
const short = exported.sha.slice(0, 12);
const script = macBuildScript({ workDir, sha: exported.sha, artifact: config.artifact, productName, version, desktopDir: relative(root, config.desktopDir).replaceAll('\\', '/'), prepareCommand: config.prepareCommand });
writeFileSync(join(scratch, 'build.sh'), script.replaceAll('\r\n', '\n'));
@ -222,18 +222,18 @@ export function buildMacRemote({ config, target, key, remoteDir, env = process.e
* Builds the committed state of the app in a WSL distro (Ubuntu 22.04: the glibc floor) and puts
* the AppImage and the .deb in `<outDir>/build/linux`. Returns `{ version, sha, dir, appimage, deb }`.
*/
export function buildLinuxWsl({ config, distro = 'Ubuntu-22.04', remoteDir, env = process.env, log = console.log }) {
export function buildLinuxWsl({ config, distro = 'Ubuntu-22.04', remoteDir, ref = 'HEAD', env = process.env, log = console.log }) {
if (process.platform !== 'win32') fail('--wsl runs from Windows; on Linux run the build on the machine itself');
if (!/^[A-Za-z0-9._-]+$/.test(distro)) fail('bad WSL distro name');
const { root } = config;
const version = JSON.parse(committedFile(root, 'package.json')).version;
const version = JSON.parse(committedFile(root, 'package.json', ref)).version;
const workDir = workDirOf(remoteDir, config.artifact);
const dir = join(config.outDir, 'build', 'linux');
mkdirSync(dir, { recursive: true });
for (const name of readdirSync(dir)) rmSync(join(dir, name), { force: true, recursive: true });
const scratch = mkdtempSync(join(tmpdir(), 'wb-linux-'));
try {
const exported = exportCommitted({ root, file: join(scratch, 'source.tgz'), exclude: config.exportExclude, log });
const exported = exportCommitted({ root, file: join(scratch, 'source.tgz'), ref, exclude: config.exportExclude, log });
const script = linuxBuildScript({ workDir, sha: exported.sha, artifact: config.artifact, version, desktopDir: relative(root, config.desktopDir).replaceAll('\\', '/'), prepareCommand: config.prepareCommand, tarball: join(scratch, 'source.tgz'), outDir: dir });
writeFileSync(join(scratch, 'build.sh'), script.replaceAll('\r\n', '\n'));
const started = Date.now();

View file

@ -5,7 +5,7 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import test from 'node:test';
import { committedSubmodules, exportCommitted, linuxBuildScript, macBuildScript, shq } from '../cli/remote.mjs';
import { committedFile, committedSubmodules, exportCommitted, linuxBuildScript, macBuildScript, shq } from '../cli/remote.mjs';
import { releaseCommand } from '../cli/release.mjs';
const git = (cwd, ...args) => execFileSync('git', ['-c', 'commit.gpgsign=false', '-c', 'core.hooksPath=NUL', '-c', 'user.name=t', '-c', 'user.email=t@example.test', '-c', 'protocol.file.allow=always', ...args], { cwd, encoding: 'utf8', stdio: 'pipe' }).trim();
@ -116,3 +116,19 @@ test('linux release: usage errors and the missing-manifest order', async () => {
await assert.rejects(releaseCommand(['linux', '--appimage', join(root, 'a.AppImage'), '--deb', join(root, 'a.zip')], { cwd: root, log: () => {} }), /\.deb/);
assert.ok(!existsSync(join(root, 'releases')));
});
test('export: --commit exports that commit, not HEAD, with its own submodule pointer', () => {
const { root, pointer } = repo();
const first = git(root, 'rev-parse', 'HEAD');
writeFileSync(join(root, 'app.txt'), 'second commit\n');
git(root, 'add', 'app.txt');
git(root, 'commit', '-q', '-m', 'second');
const file = join(root, '..', `x-${Date.now()}-d`, 'x.tgz');
const out = exportCommitted({ root, file, ref: first });
assert.equal(out.sha, first);
assert.equal(extract(file, 'app.txt'), 'committed app\n');
assert.equal(extract(file, 'fw/lib.txt'), 'framework at the pointer\n');
assert.equal(out.submodules[0].sha, pointer);
assert.equal(committedFile(root, 'app.txt', first), 'committed app\n');
assert.equal(committedFile(root, 'app.txt'), 'second commit\n');
});