Files
muSRFlow/tests/release-packaging.test.js
T
salman 12ecbf4f7d Automate Windows publication and coordinated cross-platform releases
Build and publish Windows installers on version tags using the tested WSL packaging path. Keep Windows metadata in its own package and support publication recovery from saved Linux or Windows artifacts.

Create one draft Release only after matching Linux and Windows provenance is published. Preserve reviewed release notes and handle concurrent creation safely. Cover publishing, recovery, and coordination with regression tests and update deployment and installation guides.
2026-10-30 09:22:59 +01:00

138 lines
9.0 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 root = path.resolve(__dirname, '..');
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
const lock = JSON.parse(fs.readFileSync(path.join(root, 'package-lock.json'), 'utf8'));
const main = fs.readFileSync(path.join(root, 'main.js'), 'utf8');
// Release numbers change; consistency matters, not a particular candidate.
assert.strictEqual(typeof pkg.version, 'string');
assert(pkg.version.length > 0);
assert.strictEqual(lock.version, pkg.version);
assert.strictEqual(lock.packages[''].version, pkg.version);
assert.strictEqual(pkg.build.appId, 'ch.psi.lmu.musrflow');
assert(pkg.build.linux.target.includes('rpm'));
assert(pkg.build.linux.target.includes('AppImage'));
assert.strictEqual(pkg.build.rpm.artifactName, '${name}-${version}-${arch}.${ext}');
assert(!pkg.build.rpm.artifactName.includes('${productName}'), 'RPM artifact name must be lower case');
assert(pkg.build.rpm.fpm.some(function(arg) { return arg === '--rpm-rpmbuild-define=_build_id_links none'; }), 'RPM must not package build-id links');
assert(pkg.scripts['dist:rpm'].includes('electron-builder@26.15.3'));
assert(pkg.scripts['dist:appimage'].includes('electron-builder@26.15.3'));
assert(pkg.scripts['checksums:md5'].includes('md5sum'));
assert(pkg.scripts['checksums:sha256'].includes('sha256sum'));
assert.strictEqual(pkg.scripts.checksums, 'npm run checksums:md5 && npm run checksums:sha256');
assert(main.includes('app.getVersion()'), 'About dialog should report the package version');
assert(main.includes('Author: Zaher Salman'), 'About dialog should report the author');
assert(main.includes('Copyright (C) 2026 Zaher Salman'), 'About dialog should report copyright');
assert.strictEqual(pkg.build.linux.icon, 'assets/musrflow-icon.png');
assert.strictEqual(pkg.build.win.icon, 'assets/musrflow-icon.png');
// electron-builder converts this shared PNG to ICO for the executable and NSIS.
const windowsIcon = fs.readFileSync(path.join(root, pkg.build.win.icon));
assert(windowsIcon.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])),
'Windows icon must be a PNG');
assert.strictEqual(windowsIcon.toString('ascii', 12, 16), 'IHDR');
assert.strictEqual(windowsIcon.readUInt32BE(16), windowsIcon.readUInt32BE(20),
'Windows icon must be square');
assert(windowsIcon.readUInt32BE(16) >= 256, 'Windows icon must be at least 256 pixels');
assert(pkg.build.files.includes('assets/**/*'));
assert(pkg.build.files.includes('local-runtime.js'));
assert.strictEqual(pkg.dependencies.tar, '7.5.22');
assert(fs.existsSync(path.join(root, 'assets', 'musrflow-icon.png')));
assert(fs.existsSync(path.join(root, 'assets', 'musrflow-favicon.png')));
// Linux app packages are lean: the ROOT + musrfit runtime ships as its own
// artifact (musrflow-runtime rpm and the portable muSRFlow-runtime AppImage)
// rather than inside the app package.
assert.strictEqual(
pkg.build.linux.extraResources,
undefined,
'Linux app packages must not bundle the runtime');
assert(
pkg.build.win.extraResources.some(function(entry) { return entry.to === 'wsl-runtime'; }),
'the Windows build still ships the WSL2 rootfs');
assert(pkg.scripts['dist:rpm'].includes('packaging/runtime/build-runtime-rpm.sh'));
assert(pkg.scripts['dist:appimage'].includes('packaging/runtime/build-runtime-appimage.sh'));
assert(pkg.scripts['dist:linux'].includes('packaging/runtime/build-runtime-appimage.sh'));
assert(pkg.scripts['dist:linux'].includes('packaging/runtime/build-runtime-rpm.sh'));
for (const target of ['dist:linux', 'dist:rpm', 'dist:appimage', 'dist:runtime', 'dist:runtime:archive']) {
assert(pkg.scripts[target].includes('packaging/runtime/build-runtime-archive.sh'));
}
for (const script of [
'packaging/runtime/build-runtime-appimage.sh',
'packaging/runtime/build-runtime-rpm.sh',
'packaging/runtime/build-runtime-archive.sh',
'packaging/runtime/build-runtime-archive.py',
'packaging/runtime/runtime-appimage/AppRun',
'packaging/runtime/runtime-appimage/musrflow-runtime.desktop'
]) {
assert(fs.existsSync(path.join(root, script)), `runtime packaging file is missing: ${script}`);
}
for (const file of pkg.build.files) {
if (file.includes('*') || file === 'package.json') continue;
assert(fs.existsSync(path.join(root, file)), `packaged file is missing: ${file}`);
}
// CI packages must consume a selected artifact rather than assume that a
// previous runner's ignored runtime directory survives a fresh checkout.
const runtimeWorkflow = fs.readFileSync(path.join(root, '.gitea/workflows/build-runtime.yml'), 'utf8');
const packageWorkflow = fs.readFileSync(path.join(root, '.gitea/workflows/build-and-package.yml'), 'utf8');
assert(runtimeWorkflow.includes('bae5d89d42aa79208062609a7ba3a9dbeaf253e2'));
assert(runtimeWorkflow.includes('git -C sources/musrfit fetch --depth=1 origin "$MUSRFIT_REVISION"'));
assert(runtimeWorkflow.includes('name: musrflow-runtime-linux-x64'));
assert(runtimeWorkflow.includes('actions/upload-artifact@'));
assert(!runtimeWorkflow.includes('build-runtime-rpm.sh'));
assert(!runtimeWorkflow.includes('build-runtime-appimage.sh'));
assert(packageWorkflow.includes('runtime_run_id:'));
assert(packageWorkflow.includes('actions/download-artifact@'));
assert(packageWorkflow.includes('actions/upload-artifact@'));
assert(!packageWorkflow.includes('build_runtime:'));
assert(packageWorkflow.includes('--publish never'));
assert(packageWorkflow.indexOf('node scripts/ci-restore-runtime.js') < packageWorkflow.indexOf('npx --yes electron-builder'));
assert(packageWorkflow.includes('cp "dist/$file" "dist/$file.md5" "dist/$file.sha256" artifacts/'));
assert(!packageWorkflow.includes('|| true'));
assert(packageWorkflow.includes('RUNTIME_RUN_OVERRIDE: ${{ inputs.runtime_run_id }}'));
assert(packageWorkflow.includes('LEGACY_RUNTIME_RUN_ID: ${{ vars.MUSRFLOW_RUNTIME_RUN_ID }}'));
assert(packageWorkflow.includes('node scripts/ci-runtime-registry.js select packaging/runtime/runtime-source.json'));
assert(packageWorkflow.includes('node scripts/ci-runtime-registry.js download packaging/runtime/runtime-source.json runtime-download'));
assert(runtimeWorkflow.includes('node scripts/ci-runtime-registry.js publish dist/runtime-downloads runtime-source.json'));
assert(packageWorkflow.includes('run-id: ${{ env.RUNTIME_RUN_ID }}'));
assert(packageWorkflow.includes('packages: write'));
assert(packageWorkflow.includes('PACKAGE_RUN_ID: ${{ gitea.run_id }}'));
assert(packageWorkflow.includes('PACKAGES_TOKEN: ${{ secrets.PACKAGES_TOKEN || secrets.GITEA_TOKEN }}'));
assert(packageWorkflow.indexOf('name: Upload packages') < packageWorkflow.indexOf('node scripts/ci-publish-packages.js artifacts'));
assert(packageWorkflow.indexOf('name: Run tests') < packageWorkflow.indexOf('name: Upload packages'));
assert(packageWorkflow.indexOf('name: Collect complete package set') < packageWorkflow.indexOf('name: Upload packages'));
assert(!packageWorkflow.includes('if: always()'), 'publication must not run after a failed build or upload');
const publishWorkflow = fs.readFileSync(path.join(root, '.gitea/workflows/publish-packages.yml'), 'utf8');
assert(publishWorkflow.includes('package_run_id:'));
assert(publishWorkflow.includes('packages: write'));
assert(publishWorkflow.includes('node scripts/ci-check-package-run.js'));
assert(publishWorkflow.indexOf('node scripts/ci-check-package-run.js') < publishWorkflow.indexOf('name: Download existing Linux packages'));
assert(publishWorkflow.includes('name: musrflow-windows-x64'));
assert(publishWorkflow.includes("if: ${{ env.PACKAGE_PLATFORM == 'windows' }}"));
assert(publishWorkflow.includes("PACKAGE_PLATFORM: ${{ inputs.platform || 'linux' }}"));
assert(publishWorkflow.includes('name: musrflow-linux-packages'));
assert(publishWorkflow.includes('node scripts/ci-publish-packages.js artifacts'));
assert(!publishWorkflow.includes('electron-builder'));
assert(!publishWorkflow.includes('npm ci'));
assert(packageWorkflow.includes('Packaging run ID for Publish packages:'));
assert(packageWorkflow.includes("tags:\n - 'v*'"));
assert(!packageWorkflow.includes('\n release:'), 'do not build twice for a tag and its Release');
assert(packageWorkflow.includes("gitea.event.deleted != true"));
assert(packageWorkflow.includes('contents: write'));
assert(packageWorkflow.indexOf('node scripts/ci-release.js prepare') < packageWorkflow.indexOf('name: Download selected runtime'));
assert(packageWorkflow.includes('cp .ci-release-context.json artifacts/release-context.json'));
assert(packageWorkflow.indexOf('node scripts/ci-publish-packages.js artifacts') < packageWorkflow.indexOf('node scripts/ci-release.js draft artifacts'));
assert(publishWorkflow.indexOf('node scripts/ci-publish-packages.js artifacts') < publishWorkflow.indexOf('node scripts/ci-release.js draft artifacts'));
assert(publishWorkflow.includes('contents: write'));
assert(publishWorkflow.includes('RELEASES_TOKEN: ${{ secrets.RELEASES_TOKEN || secrets.GITEA_TOKEN }}'));
console.log('release packaging tests passed');