The Windows build stages git archive output into the Wine container, so the staged tree has no .git directory. write-build-info.js previously called git rev-parse there and aborted the installer build. Pass the source revision and clean-tree state from the host checkout instead, and cover the wiring in the WSL packaging test. Release 1.0.2.
148 lines
7.7 KiB
JavaScript
148 lines
7.7 KiB
JavaScript
// Copyright (C) 2026 Zaher Salman
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const os = require('os');
|
|
const zlib = require('zlib');
|
|
const { spawnSync, execFileSync } = require('child_process');
|
|
|
|
if (process.platform !== 'linux') {
|
|
console.log('Linux-hosted WSL packaging tests skipped');
|
|
process.exit(0);
|
|
}
|
|
const root = path.resolve(__dirname, '..');
|
|
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), 'musrflow-wsl-packaging-'));
|
|
const runtime = path.join(temporary, 'runtime');
|
|
const engine = path.join(temporary, 'engine');
|
|
const log = path.join(temporary, 'engine.log');
|
|
const image = 'example.test/builder@sha256:' + 'a'.repeat(64);
|
|
|
|
function runBuild(script, overrides = {}) {
|
|
const result = spawnSync('bash', [path.join(root, 'packaging/wsl2', script)], {
|
|
env: { ...process.env, ENGINE: engine, RUNTIME_DIR: runtime, ALLOW_RUNTIME_BUILD: '0',
|
|
TEST_LOG: log, TEST_STATE: path.join(temporary, 'state'), TEST_FAIL: '', ...overrides },
|
|
encoding: 'utf8', timeout: 15000
|
|
});
|
|
assert.ifError(result.error);
|
|
return result;
|
|
}
|
|
|
|
try {
|
|
fs.mkdirSync(path.join(runtime, 'bin'), { recursive: true });
|
|
fs.writeFileSync(path.join(runtime, 'bin/musrfit'), '#!/bin/sh\nexit 0\n', { mode: 0o755 });
|
|
fs.writeFileSync(path.join(runtime, 'musrfit_startup.xml'), '<musrfit/>');
|
|
fs.writeFileSync(engine, `#!/bin/bash
|
|
set -eu
|
|
printf '%s\\n' "$*" >> "$TEST_LOG"
|
|
case "$1" in
|
|
create)
|
|
[ "$TEST_FAIL" != create ] || exit 9
|
|
echo owned-container
|
|
;;
|
|
start) [ "$TEST_FAIL" != start ] || exit 9 ;;
|
|
export)
|
|
printf 'rootfs archive fixture'
|
|
[ "$TEST_FAIL" != export ] || exit 9
|
|
;;
|
|
rm) [ "$3" = owned-container ] ;;
|
|
*) exit 99 ;;
|
|
esac
|
|
`, { mode: 0o755 });
|
|
const output = path.join(temporary, 'out/rootfs.tar.gz');
|
|
const built = runBuild('build-wsl2.sh', { OUTPUT: output });
|
|
assert.strictEqual(built.status, 0, built.stderr);
|
|
assert.strictEqual(zlib.gunzipSync(fs.readFileSync(output)).toString(), 'rootfs archive fixture');
|
|
const previous = fs.readFileSync(output);
|
|
for (const phase of ['create', 'start', 'export']) {
|
|
fs.writeFileSync(log, '');
|
|
const failed = runBuild('build-wsl2.sh', { OUTPUT: output, TEST_FAIL: phase });
|
|
assert.notStrictEqual(failed.status, 0);
|
|
assert(fs.readFileSync(output).equals(previous), 'failed exports must preserve the previous archive');
|
|
assert(!fs.readdirSync(path.dirname(output)).some(name => name.includes('.partial.')));
|
|
const calls = fs.readFileSync(log, 'utf8');
|
|
assert.strictEqual(calls.includes('rm -f owned-container'), phase !== 'create');
|
|
assert(!calls.includes('rm -f musrflow-wsl2'), 'never remove another named container');
|
|
}
|
|
assert.notStrictEqual(runBuild('build-wsl2.sh', { RUNTIME_DIR: path.join(temporary, 'missing'), OUTPUT: output }).status, 0);
|
|
|
|
const source = path.join(temporary, 'source');
|
|
fs.mkdirSync(source);
|
|
fs.writeFileSync(path.join(source, 'package.json'), JSON.stringify({ version: '9.8.7' }));
|
|
const options = { cwd: source, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] };
|
|
execFileSync('git', ['init'], options);
|
|
execFileSync('git', ['add', 'package.json'], options);
|
|
execFileSync('git', ['-c', 'user.name=Tests', '-c', 'user.email=tests@example.test', '-c', 'commit.gpgsign=false', 'commit', '-m', 'Fixture'], options);
|
|
fs.writeFileSync(path.join(source, '.untracked-secret'), 'not for the container');
|
|
fs.writeFileSync(engine, `#!/bin/bash
|
|
set -eu
|
|
printf '%s\\n' "$*" >> "$TEST_LOG"
|
|
case "$1" in
|
|
create)
|
|
[ "$TEST_FAIL" != create ] || exit 9
|
|
while [ "$#" -gt 0 ]; do
|
|
if [ "$1" = -v ]; then printf '%s' "$2" | sed 's|:/project$||' > "$TEST_STATE"; fi
|
|
shift
|
|
done
|
|
echo owned-container
|
|
;;
|
|
start)
|
|
[ "$TEST_FAIL" != start ] || exit 9
|
|
stage=$(cat "$TEST_STATE")
|
|
[ ! -e "$stage/.git" ]
|
|
[ ! -e "$stage/.untracked-secret" ]
|
|
mkdir -p "$stage/dist/win-unpacked/resources/wsl-runtime"
|
|
cp -a "$stage/runtime" "$stage/dist/win-unpacked/resources/"
|
|
cp "$stage/packaging/wsl2/out/muSRFlow-runtime-rootfs.tar.gz" "$stage/dist/win-unpacked/resources/wsl-runtime/"
|
|
if [ "$TEST_FAIL" = payload ]; then echo bad > "$stage/dist/win-unpacked/resources/runtime/bin/musrfit"; fi
|
|
if [ "$TEST_FAIL" = signature ]; then printf 'bad'; else printf 'MZinstaller'; fi > "$stage/dist/muSRFlow-9.8.7-x64.exe"
|
|
;;
|
|
rm) [ "$3" = owned-container ] ;;
|
|
*) exit 99 ;;
|
|
esac
|
|
`, { mode: 0o755 });
|
|
const windowsOut = path.join(temporary, 'windows');
|
|
const windowsEnv = { SOURCE_DIR: source, OUT_DIR: windowsOut, WSL_ROOTFS: output, WINDOWS_BUILDER_IMAGE: image };
|
|
const windows = runBuild('build-windows-ci.sh', windowsEnv);
|
|
assert.strictEqual(windows.status, 0, windows.stderr);
|
|
const installer = path.join(windowsOut, 'muSRFlow-9.8.7-x64.exe');
|
|
assert.strictEqual(fs.readFileSync(installer, 'utf8'), 'MZinstaller');
|
|
assert(fs.existsSync(installer + '.sha256'));
|
|
assert(fs.existsSync(installer + '.md5'));
|
|
assert(!fs.readdirSync(windowsOut).some(name => name.startsWith('.windows-stage.')));
|
|
const sourceRevision = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: source, encoding: 'utf8' }).trim();
|
|
const createCall = fs.readFileSync(log, 'utf8').split('\n')
|
|
.find(line => line.startsWith('create ') && line.includes('musrflow-windows-'));
|
|
// The staged tree has no .git; write-build-info.js must receive provenance
|
|
// through the environment instead of running Git inside the container.
|
|
assert(createCall.includes(`MUSRFLOW_BUILD_REVISION=${sourceRevision}`), createCall);
|
|
assert(createCall.includes('MUSRFLOW_BUILD_MODIFIED=0'), createCall);
|
|
for (const phase of ['create', 'start', 'payload', 'signature']) {
|
|
fs.writeFileSync(log, '');
|
|
const failed = runBuild('build-windows-ci.sh', { ...windowsEnv, TEST_FAIL: phase });
|
|
assert.notStrictEqual(failed.status, 0, phase);
|
|
assert.strictEqual(fs.readFileSync(installer, 'utf8'), 'MZinstaller');
|
|
assert(!fs.readdirSync(windowsOut).some(name => name.startsWith('.windows-stage.')));
|
|
assert.strictEqual(fs.readFileSync(log, 'utf8').includes('rm -f owned-container'), phase !== 'create');
|
|
}
|
|
assert.notStrictEqual(runBuild('build-windows-ci.sh', { ...windowsEnv, WINDOWS_BUILDER_IMAGE: 'builder:wine' }).status, 0);
|
|
const workflow = fs.readFileSync(path.join(root, '.gitea/workflows/build-windows.yml'), 'utf8');
|
|
assert(workflow.includes('workflow_dispatch:'));
|
|
assert(workflow.includes("tags:\n - 'v*'"));
|
|
assert(workflow.includes('gitea.event.deleted != true'));
|
|
assert(workflow.includes('node scripts/ci-runtime-registry.js download'));
|
|
assert(workflow.includes('ALLOW_RUNTIME_BUILD: \'0\''));
|
|
assert(workflow.includes('name: musrflow-windows-x64'));
|
|
assert(workflow.includes('PACKAGE_PLATFORM: windows'));
|
|
assert(workflow.indexOf('ci-release.js prepare') < workflow.indexOf('name: Select runtime'));
|
|
assert(workflow.includes('cp .ci-release-context.json dist/windows-ci/release-context.json'));
|
|
assert(workflow.includes('cp build-logs/windows-build-source.txt dist/windows-ci/build-source.txt'));
|
|
assert(workflow.indexOf('name: Upload Windows installer') < workflow.indexOf('ci-publish-packages.js dist/windows-ci'));
|
|
assert(workflow.indexOf('ci-publish-packages.js dist/windows-ci') < workflow.indexOf('ci-release.js draft dist/windows-ci'));
|
|
assert(workflow.includes('PACKAGES_TOKEN: ${{ secrets.PACKAGES_TOKEN || secrets.GITEA_TOKEN }}'));
|
|
console.log('WSL rootfs and Windows packaging orchestration tests passed');
|
|
} finally {
|
|
fs.rmSync(temporary, { recursive: true, force: true });
|
|
}
|