Automate WSL rootfs and Windows installer packaging on Linux runners
This commit is contained in:
1 parent
eb46a39fb3
commit
dc9b4023ed
7 files changed
+421
-14
No files matched your search
@@ -0,0 +1,122 @@
|
||||
name: Build Windows installer
|
||||
|
||||
# Keep manual until NSIS installation and WSLg are verified on a clean Windows PC.
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
runtime_run_id:
|
||||
description: 'Optional Actions runtime override; otherwise use the approved registry pin'
|
||||
required: false
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
actions: read
|
||||
packages: read
|
||||
|
||||
jobs:
|
||||
build-windows:
|
||||
runs-on: ubuntu-latest-full
|
||||
timeout-minutes: 240
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
env:
|
||||
ENGINE: podman
|
||||
ELECTRON_SKIP_BINARY_DOWNLOAD: '1'
|
||||
RUNTIME_RUN_OVERRIDE: ${{ inputs.runtime_run_id }}
|
||||
LEGACY_RUNTIME_RUN_ID: ${{ vars.MUSRFLOW_RUNTIME_RUN_ID }}
|
||||
BUILDER_IMAGE_REQUEST: ${{ vars.MUSRFLOW_WINDOWS_BUILDER_IMAGE || 'docker.io/electronuserland/builder:wine' }}
|
||||
steps:
|
||||
- name: Check out muSRFlow
|
||||
uses: https://github.com/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
with:
|
||||
github-server-url: ${{ gitea.server_url }}
|
||||
persist-credentials: false
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: https://github.com/actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||
with:
|
||||
node-version: '22.23.2'
|
||||
|
||||
- name: Select runtime
|
||||
run: node scripts/ci-runtime-registry.js select packaging/runtime/runtime-source.json
|
||||
|
||||
- name: Download selected runtime artifact
|
||||
if: ${{ env.RUNTIME_SOURCE == 'artifact' }}
|
||||
uses: https://github.com/actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
|
||||
with:
|
||||
name: musrflow-runtime-linux-x64
|
||||
path: runtime-download
|
||||
run-id: ${{ env.RUNTIME_RUN_ID }}
|
||||
repository: ${{ gitea.repository }}
|
||||
github-token: ${{ secrets.GITEA_TOKEN }}
|
||||
|
||||
- name: Download pinned registry runtime
|
||||
if: ${{ env.RUNTIME_SOURCE == 'registry' }}
|
||||
env:
|
||||
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
||||
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||
RUNTIME_TOKEN: ${{ secrets.PACKAGES_TOKEN || secrets.GITEA_TOKEN }}
|
||||
run: node scripts/ci-runtime-registry.js download packaging/runtime/runtime-source.json runtime-download
|
||||
|
||||
- name: Restore and test
|
||||
run: |
|
||||
npm ci --no-audit --no-fund
|
||||
node scripts/ci-restore-runtime.js runtime-download .ci-runtime
|
||||
npm run test:electron
|
||||
|
||||
- name: Validate runtime tools
|
||||
run: bash packaging/runtime/validate-runtime.sh "$RUNTIME_DIR" --arch x64
|
||||
|
||||
- name: Resolve container images
|
||||
run: |
|
||||
set -euo pipefail
|
||||
mkdir -p build-logs
|
||||
timeout --kill-after=5s 30s podman info
|
||||
df -h .
|
||||
# Use the runtime's recorded base, not a newer incompatible distro.
|
||||
base=$(node -p 'require(process.env.RUNTIME_DIR + "/runtime-manifest.json").build.baseImage')
|
||||
[[ "$base" =~ @sha256:[0-9a-f]{64}$ ]] || { echo 'Runtime manifest needs a digest-pinned base image' >&2; exit 1; }
|
||||
timeout --kill-after=10s 900s podman pull "$base"
|
||||
timeout --kill-after=10s 900s podman pull "$BUILDER_IMAGE_REQUEST"
|
||||
builder=$(podman image inspect --format '{{index .RepoDigests 0}}' "$BUILDER_IMAGE_REQUEST")
|
||||
[[ "$builder" =~ @sha256:[0-9a-f]{64}$ ]]
|
||||
echo "BASE_IMAGE=$base" >> "$GITHUB_ENV"
|
||||
echo "WINDOWS_BUILDER_IMAGE=$builder" >> "$GITHUB_ENV"
|
||||
printf 'muSRFlow=%s\nruntime_source=%s\nruntime_run=%s\nwsl_base=%s\nwindows_builder=%s\n' \
|
||||
"$(git rev-parse HEAD)" "$RUNTIME_SOURCE" "$RUNTIME_RUN_ID" "$base" "$builder" > build-logs/windows-build-source.txt
|
||||
|
||||
- name: Build and validate WSL rootfs
|
||||
env:
|
||||
ALLOW_RUNTIME_BUILD: '0'
|
||||
run: |
|
||||
set -euo pipefail
|
||||
timeout --kill-after=30s 60m bash packaging/wsl2/build-wsl2.sh 2>&1 | tee build-logs/wsl-rootfs.log
|
||||
|
||||
- name: Build Windows NSIS installer
|
||||
run: |
|
||||
set -euo pipefail
|
||||
export WSL_ROOTFS="$PWD/packaging/wsl2/out/muSRFlow-runtime-rootfs.tar.gz"
|
||||
timeout --kill-after=30s 90m bash packaging/wsl2/build-windows-ci.sh 2>&1 | tee build-logs/windows-installer.log
|
||||
cp "$RUNTIME_DIR/runtime-manifest.json" dist/windows-ci/
|
||||
cp build-logs/windows-build-source.txt dist/windows-ci/
|
||||
if [ "$RUNTIME_SOURCE" = registry ]; then cp packaging/runtime/runtime-source.json dist/windows-ci/; fi
|
||||
(cd packaging/wsl2/out && sha256sum muSRFlow-runtime-rootfs.tar.gz) > dist/windows-ci/wsl-rootfs.sha256
|
||||
|
||||
- name: Upload Windows installer
|
||||
uses: https://github.com/actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: musrflow-windows-x64
|
||||
path: dist/windows-ci/
|
||||
if-no-files-found: error
|
||||
compression-level: 0
|
||||
retention-days: 30
|
||||
|
||||
- name: Upload Windows build diagnostics
|
||||
if: ${{ always() }}
|
||||
uses: https://github.com/actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
with:
|
||||
name: windows-build-logs
|
||||
path: build-logs/
|
||||
if-no-files-found: warn
|
||||
retention-days: 14
|
||||
@@ -302,9 +302,53 @@ cleanup policies. The offline runtime `.tar.gz`/`runtime-download.json` bundle
|
||||
remains in the original Actions artifact; this first publisher exposes the
|
||||
Linux RPM/AppImage installers only.
|
||||
|
||||
Do not run the current WSL builder concurrently against a shared container
|
||||
engine: it still uses a fixed staging-container name. The native runtime CI
|
||||
build now uses unique image/container names and scoped cleanup.
|
||||
### Build the Windows/WSL installer on a runner
|
||||
|
||||
The **Build Windows installer** workflow is manual while its first Windows
|
||||
smoke test is pending. It runs on PSI's Linux `ubuntu-latest-full` runner with
|
||||
Podman; it does not depend on the old Windows runner or nested WSL support.
|
||||
|
||||
1. Push the workflow commit. Open **Actions -> Build Windows installer -> Run
|
||||
workflow** on the desired source branch.
|
||||
2. Leave `runtime_run_id` empty to use the approved registry pin, or supply
|
||||
`403788` (or another approved, unexpired runtime run) during migration.
|
||||
3. The job verifies/restores the same Linux runtime, runs the regression tests,
|
||||
and stages it into a WSL rootfs. The base image is taken from the runtime's
|
||||
recorded digest. Tool startup and ROOT's `PMusrCanvas.h` header loading must
|
||||
succeed inside that rootfs before it is exported.
|
||||
4. A separate Wine-enabled container runs electron-builder 26.15.3 to produce
|
||||
the unsigned x64 NSIS installer. Only committed application files and the
|
||||
required runtime payload are staged into it; Git credentials and workflow
|
||||
secrets are not passed to the build container.
|
||||
5. Download **musrflow-windows-x64** from the run. It contains the `.exe`, MD5
|
||||
and SHA-256 sidecars, runtime manifest, rootfs checksum, and build provenance.
|
||||
Failure logs are available as **windows-build-logs**.
|
||||
|
||||
The builder defaults to `docker.io/electronuserland/builder:wine`, resolves it
|
||||
to an immutable digest before building, and records that digest. To approve a
|
||||
specific builder permanently, set repository variable
|
||||
**MUSRFLOW_WINDOWS_BUILDER_IMAGE** to the recorded `...@sha256:...` reference.
|
||||
The actual package script refuses an unpinned image. See
|
||||
[electron-builder's Windows-on-Linux guidance](https://www.electron.build/v26/docs/features/multi-platform-build/).
|
||||
|
||||
The workflow compares the rootfs and runtime markers in the unpacked Electron
|
||||
application with the validated inputs, checks the installer executable header,
|
||||
and writes checksums. These are packaging checks, **not a Windows installation
|
||||
test**. The first run still needs a clean Windows PC with WSL2/WSLg: install the
|
||||
application, let it import its runtime, then verify Preferences, data download,
|
||||
Fit, and interactive Plot. Also test updating an existing installation, whose
|
||||
already imported WSL distribution is intentionally retained. The installer is
|
||||
unsigned, so Windows may show its normal unsigned-publisher warnings.
|
||||
|
||||
Windows output is not yet published to the package registry or added to tag
|
||||
Releases. Once the smoke test passes, it can be promoted into the release flow
|
||||
without altering the verified Linux path. This preserves the existing Windows
|
||||
model: one installer with a bundled WSL rootfs, not a new native Windows ROOT
|
||||
runtime or a separate optional Windows runtime installer.
|
||||
|
||||
Both container build scripts now use unique names and remove only containers
|
||||
they created. WSL exports are written to a temporary file and replace the
|
||||
previous rootfs only after successful export and gzip validation.
|
||||
|
||||
## musrfit sources and compilation
|
||||
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
"checksums:md5": "sh -c 'd=dist; [ -d \"$d\" ] || exit 0; for f in \"$d\"/*; do [ -f \"$f\" ] || continue; case \"$f\" in *.rpm|*.AppImage) base=$(basename \"$f\"); (cd \"$d\" && md5sum \"$base\" > \"$base.md5\");; esac; done'",
|
||||
"checksums:sha256": "sh -c 'd=dist; [ -d \"$d\" ] || exit 0; for f in \"$d\"/*; do [ -f \"$f\" ] || continue; case \"$f\" in *.rpm|*.AppImage) base=$(basename \"$f\"); (cd \"$d\" && sha256sum \"$base\" > \"$base.sha256\");; esac; done'",
|
||||
"checksums": "npm run checksums:md5 && npm run checksums:sha256",
|
||||
"test:electron": "node tests/log-highlighting.test.js && node tests/action-state.test.js && node tests/electron-missing-data.test.js && node tests/electron-run-data.test.js && node tests/electron-msr-title.test.js && node tests/electron-musrfit-threads.test.js && node tests/electron-t0-prompt-peak.test.js && node tests/window-layering.test.js && node tests/msr-generation.test.js && node tests/root-plot-clean.test.js && node tests/parameter-plot.test.js && node tests/help-window.test.js && node tests/release-packaging.test.js && node tests/ci-publish-packages.test.js && node tests/ci-release.test.js && node tests/ci-runtime-registry.test.js && node tests/runtime-validation.test.js && node tests/local-runtime.test.js && node tests/addrun.test.js && node tests/fit-statistic.test.js && node tests/series-fit-planner.test.js && node tests/series-fit-result.test.js && node tests/series-fit-inventory.test.js && node tests/series-fit-msr-preparation.test.js && node tests/series-artifact-contract.test.js && node tests/series-global-merge.test.js && node tests/series-fit-staging.test.js && node tests/series-fit-runner.test.js && node tests/series-runner-adapters.test.js && node tests/series-fit-routing.test.js && node tests/series-action-chips.test.js && node tests/singlehist-parity.test.js && node tests/url-parameters.test.js && node tests/run-naming.test.js && node tests/electron-portable-naming.test.js && node tests/shared-configuration.test.js && node tests/session-persistence.test.js && node tests/reference-fixtures.test.js && node tests/electron-bridge.test.js && node tests/electron-bundled-runtime.test.js && node tests/wsl-runtime.test.js"
|
||||
"test:electron": "node tests/log-highlighting.test.js && node tests/action-state.test.js && node tests/electron-missing-data.test.js && node tests/electron-run-data.test.js && node tests/electron-msr-title.test.js && node tests/electron-musrfit-threads.test.js && node tests/electron-t0-prompt-peak.test.js && node tests/window-layering.test.js && node tests/msr-generation.test.js && node tests/root-plot-clean.test.js && node tests/parameter-plot.test.js && node tests/help-window.test.js && node tests/release-packaging.test.js && node tests/ci-publish-packages.test.js && node tests/ci-release.test.js && node tests/ci-runtime-registry.test.js && node tests/runtime-validation.test.js && node tests/local-runtime.test.js && node tests/addrun.test.js && node tests/fit-statistic.test.js && node tests/series-fit-planner.test.js && node tests/series-fit-result.test.js && node tests/series-fit-inventory.test.js && node tests/series-fit-msr-preparation.test.js && node tests/series-artifact-contract.test.js && node tests/series-global-merge.test.js && node tests/series-fit-staging.test.js && node tests/series-fit-runner.test.js && node tests/series-runner-adapters.test.js && node tests/series-fit-routing.test.js && node tests/series-action-chips.test.js && node tests/singlehist-parity.test.js && node tests/url-parameters.test.js && node tests/run-naming.test.js && node tests/electron-portable-naming.test.js && node tests/shared-configuration.test.js && node tests/session-persistence.test.js && node tests/reference-fixtures.test.js && node tests/electron-bridge.test.js && node tests/electron-bundled-runtime.test.js && node tests/wsl-runtime.test.js && node tests/wsl-packaging.test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -96,6 +96,20 @@ The rootfs build checks that ROOT can parse `PMusrCanvas.h`, because
|
||||
|
||||
## Packaging
|
||||
|
||||
### Gitea runner
|
||||
|
||||
Use **Actions -> Build Windows installer -> Run workflow** for Linux-hosted
|
||||
WSL/NSIS packaging. It restores the approved runtime from Gitea Packages (or an
|
||||
explicit runtime run during migration), builds a checked WSL rootfs with Podman,
|
||||
and builds an unsigned Windows installer in a digest-resolved Wine image.
|
||||
Download **musrflow-windows-x64** and **windows-build-logs** from the run.
|
||||
|
||||
This workflow is deliberately manual and does not publish a Windows Release
|
||||
until installation, WSL import, Fit, and Plot have been smoke-tested on Windows.
|
||||
See the [runner instructions and checks](../../docs/DESKTOP_DEPLOYMENT.md#build-the-windowswsl-installer-on-a-runner).
|
||||
|
||||
### Local builds
|
||||
|
||||
The Windows build ships the rootfs through electron-builder. ``win.extraResources``
|
||||
copies the archive into ``resources/wsl-runtime`` and the runtime's ``bin/``
|
||||
markers (plus ``musrfit_startup.xml``) into ``resources/runtime`` so the renderer
|
||||
@@ -112,6 +126,12 @@ existing archive and does not regenerate it. The Windows installer still
|
||||
includes the runtime; the separate offline runtime installer in Preferences
|
||||
currently supports Linux only.
|
||||
|
||||
For CI or an explicitly restored runtime, `build-wsl2.sh` accepts `RUNTIME_DIR`
|
||||
and `OUTPUT`. Set `ALLOW_RUNTIME_BUILD=0` to reject a missing runtime rather
|
||||
than start a local compilation. The default local invocation still builds the
|
||||
default `runtime/` when needed. Container names are unique and failed exports
|
||||
leave any previous rootfs intact.
|
||||
|
||||
## Open items
|
||||
|
||||
- The rootfs is built from `manylinux_2_28` (AlmaLinux 8). Adjust `BASE_IMAGE`
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright (C) 2026 Zaher Salman
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
# Build an unsigned NSIS installer on a Linux runner using a Wine-enabled image.
|
||||
set -euo pipefail
|
||||
|
||||
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source_dir="${SOURCE_DIR:-$(cd "$here/../.." && pwd)}"
|
||||
runtime_dir="${RUNTIME_DIR:?Set RUNTIME_DIR to the verified Linux runtime}"
|
||||
rootfs="${WSL_ROOTFS:?Set WSL_ROOTFS to the validated rootfs archive}"
|
||||
builder="${WINDOWS_BUILDER_IMAGE:?Set WINDOWS_BUILDER_IMAGE to an image digest}"
|
||||
engine="${ENGINE:-podman}"
|
||||
out="${OUT_DIR:-$source_dir/dist/windows-ci}"
|
||||
[[ "$builder" =~ @sha256:[0-9a-f]{64}$ ]] || { echo 'Use a digest-pinned Windows builder image' >&2; exit 1; }
|
||||
test -x "$runtime_dir/bin/musrfit"
|
||||
test -s "$runtime_dir/musrfit_startup.xml"
|
||||
gzip -t "$rootfs"
|
||||
# Archive only the committed source: never mount Git credentials, job secrets,
|
||||
# or host node_modules into the Wine build container.
|
||||
git -C "$source_dir" diff --quiet
|
||||
git -C "$source_dir" diff --cached --quiet
|
||||
mkdir -p "$out"
|
||||
out=$(cd "$out" && pwd)
|
||||
stage=$(mktemp -d "$out/.windows-stage.XXXXXX")
|
||||
container_id=""
|
||||
trap '
|
||||
if [ -n "$container_id" ]; then
|
||||
"$engine" rm -f "$container_id" >/dev/null 2>&1 || true
|
||||
fi
|
||||
rm -rf "$stage"
|
||||
' EXIT
|
||||
git -C "$source_dir" archive HEAD | tar -x -C "$stage"
|
||||
mkdir -p "$stage/runtime" "$stage/packaging/wsl2/out"
|
||||
cp -a "$runtime_dir/bin" "$stage/runtime/"
|
||||
cp "$runtime_dir/musrfit_startup.xml" "$stage/runtime/"
|
||||
cp "$rootfs" "$stage/packaging/wsl2/out/muSRFlow-runtime-rootfs.tar.gz"
|
||||
|
||||
container_id=$("$engine" create --name "musrflow-windows-$$-$RANDOM" \
|
||||
--workdir /project -v "$stage:/project" \
|
||||
-e ELECTRON_SKIP_BINARY_DOWNLOAD=1 -e CSC_IDENTITY_AUTO_DISCOVERY=false \
|
||||
"$builder" bash -c '
|
||||
set -euo pipefail
|
||||
node --version
|
||||
wine --version
|
||||
npm ci --no-audit --no-fund
|
||||
npx --yes electron-builder@26.15.3 --win nsis --x64 --publish never
|
||||
')
|
||||
"$engine" start -a "$container_id"
|
||||
version=$(node -p 'require(process.argv[1]).version' "$stage/package.json")
|
||||
installer="muSRFlow-$version-x64.exe"
|
||||
test -s "$stage/dist/$installer"
|
||||
# Verify the payload electron-builder actually embedded, not just its inputs.
|
||||
cmp "$rootfs" "$stage/dist/win-unpacked/resources/wsl-runtime/muSRFlow-runtime-rootfs.tar.gz"
|
||||
cmp "$runtime_dir/bin/musrfit" "$stage/dist/win-unpacked/resources/runtime/bin/musrfit"
|
||||
cmp "$runtime_dir/musrfit_startup.xml" "$stage/dist/win-unpacked/resources/runtime/musrfit_startup.xml"
|
||||
node - "$stage/dist/$installer" <<'JS'
|
||||
const fs = require('fs');
|
||||
const fd = fs.openSync(process.argv[2], 'r');
|
||||
const signature = Buffer.alloc(2);
|
||||
try {
|
||||
if (fs.readSync(fd, signature, 0, 2, 0) !== 2 || signature.toString() !== 'MZ') throw new Error('Installer is not a Windows executable');
|
||||
} finally {
|
||||
fs.closeSync(fd);
|
||||
}
|
||||
JS
|
||||
(cd "$stage/dist" && sha256sum "$installer" > "$installer.sha256" && md5sum "$installer" > "$installer.md5")
|
||||
cp "$stage/dist/$installer" "$stage/dist/$installer.sha256" "$stage/dist/$installer.md5" "$out/"
|
||||
echo "Windows installer prepared: $out/$installer"
|
||||
echo 'Unsigned build: Windows installation, WSL import, Fit, and Plot still require a Windows smoke test.'
|
||||
@@ -15,8 +15,8 @@ set -euo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO="$(cd "$HERE/../.." && pwd)"
|
||||
RUNTIME_DIR="$REPO/runtime"
|
||||
OUT_DIR="$HERE/out"
|
||||
RUNTIME_DIR="${RUNTIME_DIR:-$REPO/runtime}"
|
||||
OUT_DIR="${OUT_DIR:-$HERE/out}"
|
||||
BASE_IMAGE="${BASE_IMAGE:-quay.io/pypa/manylinux_2_28_x86_64}"
|
||||
DISTRO_NAME="${DISTRO_NAME:-muSRFlow-runtime}"
|
||||
PREFIX="${PREFIX:-/opt/musrfit-runtime}"
|
||||
@@ -38,17 +38,31 @@ fi
|
||||
echo "Using container engine: $ENGINE"
|
||||
|
||||
if [ ! -x "$RUNTIME_DIR/bin/musrfit" ]; then
|
||||
if [ "${ALLOW_RUNTIME_BUILD:-1}" != 1 ] || [ "$RUNTIME_DIR" != "$REPO/runtime" ]; then
|
||||
echo "ERROR: selected runtime is missing; refusing an implicit rebuild: $RUNTIME_DIR" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "runtime/ not built yet; running packaging/runtime/build.sh"
|
||||
"$REPO/packaging/runtime/build.sh"
|
||||
fi
|
||||
|
||||
mkdir -p "$OUT_DIR"
|
||||
CONTAINER="musrflow-wsl2-build"
|
||||
"$ENGINE" rm -f "$CONTAINER" >/dev/null 2>&1 || true
|
||||
trap '"$ENGINE" rm -f "$CONTAINER" >/dev/null 2>&1 || true' EXIT
|
||||
mkdir -p "$(dirname "$OUTPUT")"
|
||||
CONTAINER="${WSL_CONTAINER_NAME:-musrflow-wsl2-$$-$RANDOM}"
|
||||
container_id=""
|
||||
partial=""
|
||||
# Remove only a container this invocation successfully created. Never delete
|
||||
# another build's fixed-name container, even if creation fails on a collision.
|
||||
trap '
|
||||
if [ -n "$container_id" ]; then
|
||||
"$ENGINE" rm -f "$container_id" >/dev/null 2>&1 || true
|
||||
fi
|
||||
if [ -n "$partial" ]; then
|
||||
rm -f "$partial"
|
||||
fi
|
||||
' EXIT
|
||||
|
||||
echo "Staging WSL2 rootfs in $BASE_IMAGE"
|
||||
"$ENGINE" run --name "$CONTAINER" \
|
||||
container_id=$("$ENGINE" create --name "$CONTAINER" \
|
||||
-v "$RUNTIME_DIR:/tmp/runtime:ro" \
|
||||
-v "$REPO/packaging/runtime/validate-runtime.sh:/tmp/validate-runtime.sh:ro" \
|
||||
-v "$REPO/packaging/runtime/runtime-manifest.py:/tmp/runtime-manifest.py:ro" \
|
||||
@@ -77,7 +91,7 @@ echo "Staging WSL2 rootfs in $BASE_IMAGE"
|
||||
# WSL defaults: no systemd in these tarballs, run as root, and keep the
|
||||
# Windows PATH interop so wsl.exe can be launched with translated paths.
|
||||
printf "[user]\ndefault=root\n[interop]\nappendWindowsPath=true\n" > /etc/wsl.conf
|
||||
printf "muSRFlow bundled ROOT + musrfit runtime\n" > /opt/musrfit-runtime/README.txt
|
||||
printf "muSRFlow bundled ROOT + musrfit runtime\n" > "$PREFIX/README.txt"
|
||||
|
||||
# Validate at the installed prefix; a failed check stops the container
|
||||
# and prevents exporting a rootfs that cannot run the required tools.
|
||||
@@ -89,10 +103,15 @@ echo "Staging WSL2 rootfs in $BASE_IMAGE"
|
||||
LD_LIBRARY_PATH="$PREFIX/lib" PATH="$PREFIX/bin:/usr/bin:/bin" \
|
||||
"$PREFIX/bin/root" -l -b -q -e \
|
||||
"if (!gInterpreter->Declare(\"#include <PMusrCanvas.h>\")) gSystem->Exit(1);"
|
||||
'
|
||||
')
|
||||
"$ENGINE" start -a "$container_id"
|
||||
|
||||
echo "Exporting rootfs to $OUTPUT"
|
||||
"$ENGINE" export "$CONTAINER" | gzip -c > "$OUTPUT"
|
||||
partial=$(mktemp "$OUTPUT.partial.XXXXXX")
|
||||
"$ENGINE" export "$container_id" | gzip -n -c > "$partial"
|
||||
gzip -t "$partial"
|
||||
mv -f "$partial" "$OUTPUT"
|
||||
partial=""
|
||||
|
||||
cat <<EOF
|
||||
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
// 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.')));
|
||||
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('\n push:'), 'Windows CI remains manual until smoke-tested');
|
||||
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('ci-publish-packages.js'), 'do not publish untested Windows installers as releases');
|
||||
console.log('WSL rootfs and Windows packaging orchestration tests passed');
|
||||
} finally {
|
||||
fs.rmSync(temporary, { recursive: true, force: true });
|
||||
}
|
||||
Reference in new issue
Block a user