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.
This commit is contained in:
salman committed 2026-10-30 09:22:59 +01:00
1 parent 33d6306c99
commit 12ecbf4f7d
13 files changed
+344 -97

No files matched your search

+2 -1
View File
@@ -128,9 +128,10 @@ jobs:
PACKAGES_TOKEN: ${{ secrets.PACKAGES_TOKEN || secrets.GITEA_TOKEN }}
run: node scripts/ci-publish-packages.js artifacts
- name: Create draft Release for version tag
- name: Create draft Release when both platforms are ready
env:
GITEA_SERVER_URL: ${{ gitea.server_url }}
GITEA_REPOSITORY: ${{ gitea.repository }}
RELEASES_TOKEN: ${{ secrets.RELEASES_TOKEN || secrets.GITEA_TOKEN }}
PACKAGES_TOKEN: ${{ secrets.PACKAGES_TOKEN || secrets.GITEA_TOKEN }}
run: node scripts/ci-release.js draft artifacts
+35 -5
View File
@@ -1,7 +1,9 @@
name: Build Windows installer
# Keep manual until NSIS installation and WSLg are verified on a clean Windows PC.
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
runtime_run_id:
@@ -9,12 +11,13 @@ on:
required: false
permissions:
contents: read
contents: write
actions: read
packages: read
packages: write
jobs:
build-windows:
if: ${{ gitea.event_name != 'push' || gitea.event.deleted != true }}
runs-on: ubuntu-latest-full
timeout-minutes: 240
defaults:
@@ -26,6 +29,10 @@ jobs:
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' }}
PACKAGE_PLATFORM: windows
PACKAGE_RUN_ID: ${{ gitea.run_id }}
GITEA_EVENT_NAME: ${{ gitea.event_name }}
GITEA_REF: ${{ gitea.ref }}
steps:
- name: Check out muSRFlow
uses: https://github.com/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -38,8 +45,13 @@ jobs:
with:
node-version: '22.23.2'
- name: Validate release identity
run: node scripts/ci-release.js prepare
- name: Select runtime
run: node scripts/ci-runtime-registry.js select packaging/runtime/runtime-source.json
run: |
node scripts/ci-runtime-registry.js select packaging/runtime/runtime-source.json
echo "Windows packaging run ID for Publish packages: $PACKAGE_RUN_ID"
- name: Download selected runtime artifact
if: ${{ env.RUNTIME_SOURCE == 'artifact' }}
@@ -99,7 +111,8 @@ jobs:
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/
cp build-logs/windows-build-source.txt dist/windows-ci/build-source.txt
cp .ci-release-context.json dist/windows-ci/release-context.json
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
@@ -112,6 +125,23 @@ jobs:
compression-level: 0
retention-days: 30
# Save the installer before registry/API calls so a publication failure
# can be retried without rebuilding ROOT, the WSL rootfs, or the installer.
- name: Publish and link Windows packages
env:
GITEA_SERVER_URL: ${{ gitea.server_url }}
GITEA_REPOSITORY: ${{ gitea.repository }}
PACKAGES_TOKEN: ${{ secrets.PACKAGES_TOKEN || secrets.GITEA_TOKEN }}
run: node scripts/ci-publish-packages.js dist/windows-ci
- name: Create draft Release when both platforms are ready
env:
GITEA_SERVER_URL: ${{ gitea.server_url }}
GITEA_REPOSITORY: ${{ gitea.repository }}
RELEASES_TOKEN: ${{ secrets.RELEASES_TOKEN || secrets.GITEA_TOKEN }}
PACKAGES_TOKEN: ${{ secrets.PACKAGES_TOKEN || secrets.GITEA_TOKEN }}
run: node scripts/ci-release.js draft dist/windows-ci
- name: Upload Windows build diagnostics
if: ${{ always() }}
uses: https://github.com/actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
+19 -2
View File
@@ -4,8 +4,12 @@ on:
workflow_dispatch:
inputs:
package_run_id:
description: 'Build and package workflow run ID with an uploaded package artifact (also retries failed publication)'
description: 'Linux or Windows packaging workflow run ID with an uploaded artifact (also retries failed publication)'
required: true
platform:
description: 'Package platform: linux or windows (must match the selected run)'
required: true
default: linux
permissions:
contents: write
@@ -23,6 +27,7 @@ jobs:
GITEA_SERVER_URL: ${{ gitea.server_url }}
GITEA_REPOSITORY: ${{ gitea.repository }}
PACKAGE_RUN_ID: ${{ inputs.package_run_id }}
PACKAGE_PLATFORM: ${{ inputs.platform || 'linux' }}
steps:
- name: Check out publisher
uses: https://github.com/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -40,7 +45,8 @@ jobs:
ACTIONS_TOKEN: ${{ secrets.GITEA_TOKEN }}
run: node scripts/ci-check-package-run.js
- name: Download existing packages
- name: Download existing Linux packages
if: ${{ env.PACKAGE_PLATFORM == 'linux' }}
uses: https://github.com/actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: musrflow-linux-packages
@@ -49,6 +55,16 @@ jobs:
repository: ${{ gitea.repository }}
github-token: ${{ secrets.GITEA_TOKEN }}
- name: Download existing Windows packages
if: ${{ env.PACKAGE_PLATFORM == 'windows' }}
uses: https://github.com/actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: musrflow-windows-x64
path: artifacts
run-id: ${{ inputs.package_run_id }}
repository: ${{ gitea.repository }}
github-token: ${{ secrets.GITEA_TOKEN }}
- name: Publish and link packages to repository
env:
# Optional fallback for servers that restrict registry access by job tokens.
@@ -60,4 +76,5 @@ jobs:
- name: Create or preserve draft Release
env:
RELEASES_TOKEN: ${{ secrets.RELEASES_TOKEN || secrets.GITEA_TOKEN }}
PACKAGES_TOKEN: ${{ secrets.PACKAGES_TOKEN || secrets.GITEA_TOKEN }}
run: node scripts/ci-release.js draft artifacts
+57 -39
View File
@@ -167,9 +167,10 @@ The old `build_runtime=false` option is removed: skipping a build does not
supply a runtime on a fresh runner. The two workflow files are
[build-runtime.yml](../.gitea/workflows/build-runtime.yml) and
[build-and-package.yml](../.gitea/workflows/build-and-package.yml).
The latter currently builds **Linux packages only**. Windows/WSL packaging is
a separate next step. The standalone publisher
remains available for recovery as described below.
The latter builds **Linux packages**; [build-windows.yml](../.gitea/workflows/build-windows.yml)
builds the Windows installer with its bundled WSL runtime. Both run on version
tags and support manual builds. The standalone publisher remains available
for recovery as described below.
Both workflows use pinned artifact actions. PSI's runner must support their
Gitea adaptation and artifact storage. An upload preflight failure must be
@@ -183,32 +184,40 @@ download does not require a personal token; PSI registry publication uses the
**Prerequisites:** commit an approved runtime pin (or, during migration, set
**MUSRFLOW_RUNTIME_RUN_ID** to an unexpired artifact) and keep **PACKAGES_TOKEN**
configured. The tagged commit must
contain this workflow. Restrict who can push `v*` tags: those pushes publish
contain both packaging workflows. Restrict who can push `v*` tags: those pushes publish
packages using repository secrets.
1. Update `package.json` and `package-lock.json` together, for example with
`npm version 1.0.0-rc.6 --no-git-tag-version`. Update release notes/version
`npm version 1.0.0-rc.7 --no-git-tag-version`. Update release notes/version
references as needed, test, and commit the version changes.
2. Create an annotated tag matching the package version exactly and push it to
Gitea. For example, after committing version `1.0.0-rc.6`:
Gitea. For example, after committing a new version `1.0.0-rc.7`:
```bash
git tag -a v1.0.0-rc.6 -m "muSRFlow 1.0.0-rc.6"
git tag -a v1.0.0-rc.7 -m "muSRFlow 1.0.0-rc.7"
git push gitea master
git push gitea v1.0.0-rc.6
git push gitea v1.0.0-rc.7
```
3. **Build and package** starts automatically. It rejects mismatched tags
before downloading the runtime, then validates, tests, builds, archives,
and publishes the Linux application and runtime packages.
4. Open **Packages**: tag `v1.0.0-rc.6` publishes registry version
**1.0.0-rc.6**, without a build-ID suffix. Existing different files are never
3. **Build and package** and **Build Windows installer** start automatically.
Both reject mismatched tags before downloading the runtime, then validate,
test, build, archive, and publish their platform's packages.
4. Open **Packages**: tag `v1.0.0-rc.7` publishes registry version
**1.0.0-rc.7**, without a build-ID suffix. Existing different files are never
overwritten; do not move a released tag to rebuild different contents.
5. Open **Releases** and review the newly created **draft**. It contains direct
registry download links for all four RPM/AppImage files, SHA-256 values and
checksum links, source commit, packaging run ID, and runtime manifest link.
5. Once both platforms are published, open **Releases** and review the new
**draft**. It contains direct registry download links for all four Linux
RPM/AppImage files and the Windows `.exe`, SHA-256 values and checksum links,
source commit, both packaging run IDs, and the runtime manifest link.
Smoke-test the downloads, edit the release notes, then publish the draft.
The first finished workflow reports **Release pending** if the other platform
is still missing. The last publisher creates the shared draft, after checking
that all package records refer to the same version, tag, and source commit.
If one build fails, its counterpart can still publish packages, but no incomplete
draft is created. Recover the failed build/publication; do not retag an existing
release. The existing `v1.0.0-rc.6` tag predates this automation and must not move.
Release-candidate/beta versions are marked as prereleases; stable versions are
not. The Release remains a draft in either case. Package files are already in
the registry, whose visibility follows Gitea's package access policy; a draft
@@ -236,7 +245,7 @@ comment when editing release notes if you want future retries to recognize it.
### Retry publication without rebuilding
**Build and package** now publishes automatically. Use the standalone
**Build and package** and **Build Windows installer** publish automatically. Use the standalone
**Publish packages** workflow only for older builds or to retry a registry or
draft-creation failure. A combined run may be marked failed even though its complete package
artifact was uploaded successfully. The recovery workflow verifies that it
@@ -245,8 +254,9 @@ run, missing artifact, or unfinished run is rejected with a clear error.
1. Push the workflow changes, then open **Actions -> Publish packages -> Run
workflow** on the updated branch.
2. Enter **package_run_id**, the workflow run ID of the **Build and package**
run whose **Upload packages** step succeeded. This is **not** the runtime
2. Select **platform** (`linux` or `windows`) and enter **package_run_id**, the
matching **Build and package** or **Build Windows installer** workflow run
whose installer artifact upload succeeded. This is **not** the runtime
run ID or a job/task ID. New
packaging runs print it in **Check runtime selection** as `Packaging run ID
for Publish packages`. Older upload logs also print an **Artifact download
@@ -257,15 +267,17 @@ run, missing artifact, or unfinished run is rejected with a clear error.
its `id` field. Do not confuse that with `run_number` or assume that the
browser URL's number is the API run ID. Private repositories may require
authenticated API access rather than a browser session.
3. The publisher downloads the existing **musrflow-linux-packages** artifact,
checks every RPM/AppImage against its SHA-256 and MD5 sidecars, uploads the
3. The publisher downloads **musrflow-linux-packages** or **musrflow-windows-x64**,
checks every installer against its SHA-256 and MD5 sidecars, uploads the
files, and links the packages to this repository.
4. Open the repository's **Packages** tab. There are two Generic packages:
4. Open the repository's **Packages** tab. There are three installer packages:
**musrflow** (application RPM/AppImage) and **musrflow-runtime** (runtime
RPM/AppImage). Each includes checksums and build-source information; the
runtime also includes its manifest.
5. For tagged artifacts, the final step creates the missing draft Release or
preserves an already recognized Release. For manual/older artifacts it does
RPM/AppImage), plus **musrflow-windows** (unsigned x64 NSIS installer with
bundled WSL runtime). Each includes checksums and build-source information;
the runtime and Windows packages also include a runtime manifest. Separate
namespaces prevent Linux and Windows build metadata from colliding.
5. For tagged artifacts, the final step creates the missing draft once both
platforms are published, or preserves an already recognized Release. For manual/older artifacts it does
nothing. Retry from the updated default branch to use publisher fixes while
retaining the original release version.
@@ -279,8 +291,11 @@ Gitea repository links apply to every version of a package. If linking returns
HTTP 400 because a link already exists, the publisher verifies the package's
repository metadata and continues only when it matches this repository. It
never silently ignores that error or moves a package from another repository.
Publication is not atomic: a failed upload may leave a partial package. Rerun
**Publish packages** with the same ID to complete it.
Publication is not atomic: a failed upload may leave a partial package. The
publisher writes each package's release context last to mark upload completion.
Rerun **Publish packages** with the same platform and ID to complete it. If all
packages are present but draft creation failed, retry either platform's tagged
run. Concurrent draft creation is handled without overwriting release notes.
Both publishing paths request `packages: write` for the built-in job token.
PSI rejected that token for registry uploads (HTTP 401); the tested setup uses a
@@ -288,8 +303,9 @@ repository **Actions secret** named **PACKAGES_TOKEN** with a token owned by
the package owner and scoped to **write:package**. If it is already configured,
no additional secret is needed for the combined workflow. Do not put tokens in files
or workflow inputs. Also ensure the repository's Packages feature is enabled.
The secret is passed only to the registry publishing step; artifact download
still uses the job token. Other Gitea servers may allow the built-in token
The secret is used for registry downloads/publication and reading package
metadata when assembling the draft, never passed into build containers. Actions
artifact download still uses the job token. Other Gitea servers may allow the built-in token
fallback, but do not remove the working PSI secret.
This uses Gitea's [Generic Package Registry](https://docs.gitea.com/usage/packages/generic/),
@@ -299,13 +315,14 @@ It never creates a Git tag; the final step creates a draft Release only for a
validated tagged artifact. Registry files are independent
of the 30-day Actions artifact retention, but remain subject to server package
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.
is published separately by **Build runtime** / **Publish runtime**. The installer
publisher exposes Linux RPM/AppImage files and the Windows `.exe`.
### 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
The Windows installer has passed installation, runtime setup, data download,
Fit/Plot, and multi-run smoke tests. **Build Windows installer** now runs on
version tags as well as manually. It uses 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
@@ -323,6 +340,9 @@ Podman; it does not depend on the old Windows runner or nested WSL support.
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**.
6. The workflow publishes the installer as **musrflow-windows** in **Packages**.
Manual builds use `<version>-build.<run-ID>`; tag builds use `<version>` and
participate in the shared Linux/Windows draft Release described above.
The builder defaults to `docker.io/electronuserland/builder:wine`, resolves it
to an immutable digest before building, and records that digest. To approve a
@@ -334,16 +354,14 @@ The actual package script refuses an unpinned image. See
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
test**. New releases should still be smoke-tested on a 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
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
+11 -8
View File
@@ -17,15 +17,18 @@ Before you start
* Windows 11 is recommended. Windows 10 requires build 19044 or newer for
WSLg, which displays the musrview spectrum windows.
* Administrator access is needed to enable the Windows virtualization features.
* Obtain the Windows installer, named ``muSRFlow-<version>-x64.exe``. The
verified Windows build described below is ``1.0.0-rc.5``. The rc.6 automated
release workflow produces Linux packages only, not a new Windows installer.
* Obtain the Windows installer, named ``muSRFlow-<version>-x64.exe``, from
the project's `Releases <https://gitea.psi.ch/salman/muSRFlow/releases>`_
or the **musrflow-windows** package in
`Packages <https://gitea.psi.ch/salman/muSRFlow/packages>`_. Verify its
SHA-256 checksum against the accompanying ``.sha256`` file.
* For a test build that has not been published yet, download the
**musrflow-windows-x64** artifact from a successful **Build Windows
installer** workflow run and extract the installer.
**Use the refreshed Windows build.** Earlier rc.5 installers have the same
filename but lack the WSL fixes. Obtain a build containing commit ``a6981c4``
or later. In the development workspace, the verified replacement is
``dist/windows-runtime-fix/muSRFlow-1.0.0-rc.5-x64.exe``; this is a local build
output, not a public download address.
**Avoid old rc.5 installers.** Early builds lack the WSL fixes. The current
runner-built installer includes them and has passed Windows installation,
runtime setup, data download, Fit/Plot, and multi-run smoke tests.
See `Microsoft's WSL GUI requirements
<https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps>`_ for the
+7 -4
View File
@@ -104,8 +104,11 @@ 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.
The workflow also runs on version-tag pushes and publishes **musrflow-windows**
in Gitea Packages. Tagged builds contribute to one draft Release after both Linux
and Windows packages are ready. Manual builds publish a build-specific version
without creating a Release. Use **Publish packages** with platform `windows`
and the original packaging run ID to retry publication without rebuilding.
See the [runner instructions and checks](../../docs/DESKTOP_DEPLOYMENT.md#build-the-windowswsl-installer-on-a-runner).
### Local builds
@@ -120,8 +123,8 @@ npm run dist:win
```
The installer is written to `dist/muSRFlow-<version>-x64.exe`, using the version
in `package.json`. Windows installers are built separately; the automated
tag workflow currently produces Linux packages only. Build the rootfs first: `dist:win` packages the
in `package.json`. Windows and Linux installers are built by separate workflows
on the same version tag. For a local build, build the rootfs first: `dist:win` packages the
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.
+9 -5
View File
@@ -18,21 +18,25 @@ async function checkPackageRun(env = process.env, request = fetch) {
if (!response.ok) throw new Error(`Cannot inspect packaging run: HTTP ${response.status}`);
const run = await response.json();
const workflow = String(run.path || '').split('@')[0].split('/').pop();
if (workflow !== 'build-and-package.yml') {
throw new Error(`Run ${PACKAGE_RUN_ID} is not Build and package (${run.path || 'unknown workflow'}). Use the packaging run ID, not the runtime run ID`);
const platform = env.PACKAGE_PLATFORM || 'linux';
if (!['linux', 'windows'].includes(platform)) throw new Error('Expected linux or windows package platform');
const expectedWorkflow = platform === 'windows' ? 'build-windows.yml' : 'build-and-package.yml';
const artifactName = platform === 'windows' ? 'musrflow-windows-x64' : 'musrflow-linux-packages';
if (workflow !== expectedWorkflow) {
throw new Error(`Run ${PACKAGE_RUN_ID} is not ${platform === 'windows' ? 'Build Windows installer' : 'Build and package'} (${run.path || 'unknown workflow'}). Select the matching platform and packaging run ID, not the runtime run ID`);
}
if (!['success', 'failure'].includes(run.conclusion)) {
throw new Error('The packaging run must finish before publishing its artifacts');
}
// A registry failure marks the whole combined run failed, but its package
// artifact was uploaded only after tests, builds, and collection succeeded.
const artifactResponse = await request(`${base}/artifacts?name=musrflow-linux-packages`, {
const artifactResponse = await request(`${base}/artifacts?name=${artifactName}`, {
headers, redirect: 'error', signal: AbortSignal.timeout(60000)
});
if (!artifactResponse.ok) throw new Error(`Cannot inspect package artifacts: HTTP ${artifactResponse.status}`);
const listing = await artifactResponse.json();
const matches = (listing.artifacts || []).filter(artifact => artifact.name === 'musrflow-linux-packages');
if (matches.length !== 1) throw new Error(`Run ${PACKAGE_RUN_ID} must contain one musrflow-linux-packages artifact; check its Upload packages step`);
const matches = (listing.artifacts || []).filter(artifact => artifact.name === artifactName);
if (matches.length !== 1) throw new Error(`Run ${PACKAGE_RUN_ID} must contain one ${artifactName} artifact; check its upload step`);
const artifact = matches[0];
if (artifact.expired || (artifact.expires_at && Date.parse(artifact.expires_at) <= Date.now())) {
throw new Error(`The package artifact for run ${PACKAGE_RUN_ID} has expired`);
+22 -8
View File
@@ -15,18 +15,22 @@ async function publishPackages(directory, env = process.env, request = fetch) {
if (server.protocol !== 'https:' || server.username || server.password || server.search || server.hash) {
throw new Error('Gitea must use an HTTPS server URL without credentials, query, or fragment');
}
const base = server.href.replace(/\/$/, '');
const [owner, repository] = GITEA_REPOSITORY.split('/').map(encodeURIComponent);
const files = fs.readdirSync(directory);
const platform = env.PACKAGE_PLATFORM || 'linux';
if (!['linux', 'windows'].includes(platform)) throw new Error('Expected linux or windows package platform');
const application = files.filter(name => /^musrflow-.+-x86_64\.rpm$/.test(name) && !name.startsWith('musrflow-runtime-'));
if (application.length !== 1) throw new Error('Expected exactly one application RPM');
const windows = files.filter(name => /^muSRFlow-.+-x64\.exe$/.test(name));
if (platform === 'linux' && application.length !== 1) throw new Error('Expected exactly one application RPM');
if (platform === 'windows' && windows.length !== 1) throw new Error('Expected exactly one Windows installer');
// Read the version from the selected artifact, not the publisher checkout.
const version = application[0].slice('musrflow-'.length, -'-x86_64.rpm'.length);
const version = platform === 'windows'
? windows[0].slice('muSRFlow-'.length, -'-x64.exe'.length)
: application[0].slice('musrflow-'.length, -'-x86_64.rpm'.length);
if (!/^[\w.+-]+$/.test(version)) throw new Error('Invalid package version');
const release = readReleaseContext(directory, PACKAGE_RUN_ID);
if (release && release.version !== version) throw new Error('Artifact filenames do not match the recorded release version');
const registryVersion = release?.tag ? version : `${version}-build.${PACKAGE_RUN_ID}`;
const groups = {
const groups = platform === 'windows' ? { 'musrflow-windows': [windows[0]] } : {
musrflow: [application[0], `muSRFlow-${version}-x86_64.AppImage`],
'musrflow-runtime': [`musrflow-runtime-${version}-x86_64.rpm`, `musrflow-runtime-${version}-x86_64.AppImage`]
};
@@ -48,10 +52,20 @@ async function publishPackages(directory, env = process.env, request = fetch) {
names.push(sidecar);
}
}
names.push('build-source.txt');
if (release) names.push('release-context.json');
// The first manual Windows builds used a platform-specific filename.
names.push(platform === 'windows' && !release && !files.includes('build-source.txt')
? 'windows-build-source.txt' : 'build-source.txt');
}
if (platform === 'windows') {
groups['musrflow-windows'].push('runtime-manifest.json', 'wsl-rootfs.sha256');
} else {
groups['musrflow-runtime'].push('runtime-manifest.json');
}
// Publish provenance last in each package. Release aggregation uses its
// presence as the completion marker, never an installer still uploading.
if (release) {
for (const names of Object.values(groups)) names.push('release-context.json');
}
groups['musrflow-runtime'].push('runtime-manifest.json');
for (const names of Object.values(groups)) {
for (const name of names) {
const stat = fs.lstatSync(path.join(directory, name));
+54 -5
View File
@@ -84,26 +84,59 @@ async function createDraftRelease(directory, env = process.env, request = fetch)
if (existing.status !== 404) throw new Error(`Cannot inspect existing Release: HTTP ${existing.status}`);
const owner = GITEA_REPOSITORY.split('/')[0];
if (!env.PACKAGES_TOKEN) throw new Error('A package read token is required to assemble the cross-platform Release');
const packageHeaders = { Authorization: `token ${env.PACKAGES_TOKEN}` };
const registry = `${base}/api/packages/${owner}/generic`;
const contexts = {};
// Either build may finish first. Only assemble a draft after all three
// package groups have published their final provenance file.
for (const name of ['musrflow', 'musrflow-runtime', 'musrflow-windows']) {
const response = await request(`${registry}/${name}/${encodeURIComponent(context.version)}/release-context.json`, {
headers: packageHeaders, redirect: 'error', signal: AbortSignal.timeout(60000)
});
if (response.status === 404) {
if (response.body) await response.body.cancel();
console.log(`Release pending: ${name}/${context.version} is not published yet. The other build will finish the draft; retry Publish packages if needed.`);
return null;
}
if (response.status !== 200) throw new Error(`Cannot inspect ${name} release context: HTTP ${response.status}`);
const remote = await response.json();
if (remote.schema !== 1 || remote.tag !== context.tag || remote.version !== context.version
|| remote.commit !== context.commit || !/^[1-9][0-9]*$/.test(remote.runId || '')) {
throw new Error(`${name} does not match the release tag and source commit`);
}
contexts[name] = remote;
}
if (contexts.musrflow.runId !== contexts['musrflow-runtime'].runId) {
throw new Error('Linux application and runtime came from different packaging runs');
}
const downloads = [
['musrflow', `musrflow-${context.version}-x86_64.rpm`],
['musrflow', `muSRFlow-${context.version}-x86_64.AppImage`],
['musrflow-runtime', `musrflow-runtime-${context.version}-x86_64.rpm`],
['musrflow-runtime', `musrflow-runtime-${context.version}-x86_64.AppImage`]
['musrflow-runtime', `musrflow-runtime-${context.version}-x86_64.AppImage`],
['musrflow-windows', `muSRFlow-${context.version}-x64.exe`]
];
const lines = [marker, '', `# muSRFlow ${context.version}`, '',
'Linux x86_64 packages. Install the application; install the separate runtime only if you need ROOT/musrfit.', '',
'Windows x64: the unsigned installer includes the WSL2 runtime. WSL2/virtualization and WSLg must be available.', '',
'Review and smoke-test these downloads before publishing this draft.', '',
'| Download | SHA-256 |', '| --- | --- |'];
for (const [name, file] of downloads) {
const checksum = fs.readFileSync(path.join(directory, `${file}.sha256`), 'utf8').trim();
const url = `${registry}/${name}/${encodeURIComponent(context.version)}/${encodeURIComponent(file)}`;
const checksumResponse = await request(`${url}.sha256`, {
headers: packageHeaders, redirect: 'error', signal: AbortSignal.timeout(60000)
});
if (checksumResponse.status !== 200) throw new Error(`Cannot read checksum for ${file}: HTTP ${checksumResponse.status}`);
const checksum = (await checksumResponse.text()).trim();
if (!/^[a-f0-9]{64} /.test(checksum) || checksum.slice(66) !== file) throw new Error(`Invalid checksum sidecar for ${file}`);
const url = `${base}/api/packages/${owner}/generic/${name}/${encodeURIComponent(context.version)}/${encodeURIComponent(file)}`;
lines.push(`| [${file}](${url}) | \`${checksum.slice(0, 64)}\` ([checksum](${url}.sha256)) |`);
}
lines.push('', `Source commit: [${context.commit}](${base}/${GITEA_REPOSITORY}/commit/${context.commit})`,
'', `Packaging workflow run ID: ${context.runId}.`, '',
'', `Linux packaging workflow run ID: ${contexts.musrflow.runId}.`,
`Windows packaging workflow run ID: ${contexts['musrflow-windows'].runId}.`, '',
`[Runtime manifest](${base}/api/packages/${owner}/generic/musrflow-runtime/${encodeURIComponent(context.version)}/runtime-manifest.json)`,
'', 'Windows/macOS installers are not produced by this workflow.');
'', 'macOS installers are not produced by these workflows.');
const response = await request(`${api}/releases`, {
method: 'POST', headers: { ...headers, 'Content-Type': 'application/json' },
redirect: 'error', signal: AbortSignal.timeout(60000),
@@ -111,6 +144,22 @@ async function createDraftRelease(directory, env = process.env, request = fetch)
name: `muSRFlow ${context.version}`, body: lines.join('\n'), draft: true,
prerelease: context.version.split('+')[0].includes('-') })
});
// Both platforms may observe a missing draft at the same time. The loser
// of that create race may only accept a Release with matching provenance.
if ([409, 422].includes(response.status)) {
if (response.body) await response.body.cancel();
const concurrent = await request(`${api}/releases/tags/${encodeURIComponent(context.tag)}`, {
headers, redirect: 'error', signal: AbortSignal.timeout(60000)
});
if (concurrent.status === 200) {
const release = await concurrent.json();
if (release.tag_name === context.tag && String(release.body || '').includes(marker)) {
console.log(`Release created by the other workflow; preserving it: ${release.html_url}`);
return release;
}
}
throw new Error('Concurrent Release could not be verified; retry Publish packages without rebuilding');
}
if (response.status !== 201) throw new Error(`Create draft Release: HTTP ${response.status}. Check release write permission; retry Publish packages without rebuilding`);
const release = await response.json();
console.log(`Draft Release created: ${release.html_url}`);
+50 -1
View File
@@ -53,7 +53,7 @@ async function main() {
assert.strictEqual(options.headers.Authorization, 'token actions-token');
assert.strictEqual(options.redirect, 'error');
assert(url.startsWith('https://gitea.example.test/api/v1/repos/owner/muSRFlow/actions/runs/123'));
return Response.json(url.endsWith('/artifacts?name=musrflow-linux-packages') ? { artifacts } : run);
return Response.json(url.includes('/artifacts?name=') ? { artifacts } : run);
}
assert.strictEqual((await checkPackageRun(runEnv, actionsApi)).id, 456);
run.conclusion = 'failure';
@@ -89,6 +89,17 @@ async function main() {
await assert.rejects(checkPackageRun({ ...runEnv, GITEA_SERVER_URL: 'http://example.test' }, actionsApi), /HTTPS/);
assert.strictEqual(apiCalls.length, callCount);
run = { path: '.gitea/workflows/build-windows.yml', conclusion: 'success' };
artifacts = [{ id: 789, name: 'musrflow-windows-x64', expired: false }];
assert.strictEqual((await checkPackageRun({ ...runEnv, PACKAGE_PLATFORM: 'windows' }, actionsApi)).id, 789);
assert(apiCalls.at(-1).endsWith('/artifacts?name=musrflow-windows-x64'));
run.conclusion = 'failure';
assert.strictEqual((await checkPackageRun({ ...runEnv, PACKAGE_PLATFORM: 'windows' }, actionsApi)).id, 789);
await assert.rejects(checkPackageRun(runEnv, actionsApi), /not Build and package/);
run.path = '.gitea/workflows/build-and-package.yml';
await assert.rejects(checkPackageRun({ ...runEnv, PACKAGE_PLATFORM: 'windows' }, actionsApi), /not Build Windows installer/);
await assert.rejects(checkPackageRun({ ...runEnv, PACKAGE_PLATFORM: 'macos' }, actionsApi), /package platform/);
const names = ['musrflow-9.8.7-x86_64.rpm', 'muSRFlow-9.8.7-x86_64.AppImage',
'musrflow-runtime-9.8.7-x86_64.rpm', 'musrflow-runtime-9.8.7-x86_64.AppImage'];
for (const name of names) {
@@ -166,6 +177,44 @@ async function main() {
assert.strictEqual(calls.length, beforeInvalid);
fs.writeFileSync(contextFile, JSON.stringify({ ...context, tag: null, runId: '125' }));
assert.strictEqual(await publishPackages(directory, { ...env, PACKAGE_RUN_ID: '125' }, registry), '9.8.7-build.125');
const windowsDirectory = path.join(directory, 'windows');
fs.mkdirSync(windowsDirectory);
const installer = 'muSRFlow-9.8.7-x64.exe';
fs.writeFileSync(path.join(windowsDirectory, installer), 'MZinstaller');
for (const algorithm of ['md5', 'sha256']) {
const sum = crypto.createHash(algorithm).update('MZinstaller').digest('hex');
fs.writeFileSync(path.join(windowsDirectory, `${installer}.${algorithm}`), `${sum} ${installer}\n`);
}
fs.writeFileSync(path.join(windowsDirectory, 'build-source.txt'), `muSRFlow=${context.commit}\n`);
fs.writeFileSync(path.join(windowsDirectory, 'runtime-manifest.json'), '{}\n');
fs.writeFileSync(path.join(windowsDirectory, 'wsl-rootfs.sha256'), `${'a'.repeat(64)} muSRFlow-runtime-rootfs.tar.gz\n`);
const windowsEnv = { ...env, PACKAGE_PLATFORM: 'windows' };
assert.strictEqual(await publishPackages(windowsDirectory, windowsEnv, registry), '9.8.7-build.123');
const windowsContext = path.join(windowsDirectory, 'release-context.json');
fs.writeFileSync(windowsContext, JSON.stringify(context));
const beforeWindows = calls.length;
assert.strictEqual(await publishPackages(windowsDirectory, windowsEnv, registry), '9.8.7');
const uploads = calls.slice(beforeWindows).filter(call => call.method === 'PUT');
assert.strictEqual(uploads.length, 7);
assert(uploads.every(call => call.url.includes('/generic/musrflow-windows/9.8.7/')));
assert(uploads.at(-1).url.endsWith('/release-context.json'), 'provenance marks completed publication');
await publishPackages(windowsDirectory, windowsEnv, registry);
const beforeCorrupt = calls.length;
fs.appendFileSync(path.join(windowsDirectory, installer), 'corrupted');
await assert.rejects(publishPackages(windowsDirectory, windowsEnv, registry), /Checksum mismatch/);
assert.strictEqual(calls.length, beforeCorrupt, 'validate before uploading');
fs.writeFileSync(path.join(windowsDirectory, installer), 'MZinstaller');
fs.writeFileSync(windowsContext, JSON.stringify({ ...context, tag: 'v9.8.8', version: '9.8.8' }));
await assert.rejects(publishPackages(windowsDirectory, windowsEnv, registry), /filenames do not match/);
fs.unlinkSync(windowsContext);
// The previously tested manual installer remains recoverable too.
fs.renameSync(path.join(windowsDirectory, 'build-source.txt'), path.join(windowsDirectory, 'windows-build-source.txt'));
assert.strictEqual(await publishPackages(windowsDirectory, { ...windowsEnv, PACKAGE_RUN_ID: '126' }, registry), '9.8.7-build.126');
fs.unlinkSync(path.join(windowsDirectory, 'wsl-rootfs.sha256'));
const beforeMissing = calls.length;
await assert.rejects(publishPackages(windowsDirectory, windowsEnv, registry), /ENOENT/);
assert.strictEqual(calls.length, beforeMissing);
console.log('Gitea package publishing tests passed');
} finally {
fs.rmSync(directory, { recursive: true, force: true });
+65 -16
View File
@@ -19,7 +19,8 @@ async function main() {
execFileSync('git', [...identity, 'commit', '-m', 'Fixture'], gitOptions);
execFileSync('git', [...identity, 'tag', '-a', 'v2.3.4-rc.1', '-m', 'Annotated fixture'], gitOptions);
const env = { PACKAGE_RUN_ID: '456', GITEA_EVENT_NAME: 'push', GITEA_REF: 'refs/tags/v2.3.4-rc.1',
GITEA_SERVER_URL: 'https://gitea.example.test', GITEA_REPOSITORY: 'owner/muSRFlow', RELEASES_TOKEN: 'release-token' };
GITEA_SERVER_URL: 'https://gitea.example.test', GITEA_REPOSITORY: 'owner/muSRFlow',
RELEASES_TOKEN: 'release-token', PACKAGES_TOKEN: 'package-token' };
const context = prepareRelease(directory, env);
assert.strictEqual(context.tag, 'v2.3.4-rc.1');
execFileSync('git', ['tag', '-d', context.tag], gitOptions);
@@ -48,26 +49,42 @@ async function main() {
}
fs.writeFileSync(contextFile, JSON.stringify(context));
for (const file of [`musrflow-${context.version}-x86_64.rpm`, `muSRFlow-${context.version}-x86_64.AppImage`,
`musrflow-runtime-${context.version}-x86_64.rpm`, `musrflow-runtime-${context.version}-x86_64.AppImage`]) {
fs.writeFileSync(path.join(directory, `${file}.sha256`), `${'a'.repeat(64)} ${file}\n`);
}
let existing = null;
let tagCommit = context.commit;
let tagStatus = 200;
let createStatus = 201;
let missingPackage = '';
let packageStatus = 200;
let remoteChange = {};
let badChecksum = false;
let concurrentRelease = null;
const writes = [];
async function api(url, options) {
assert.strictEqual(options.headers.Authorization, 'token release-token');
assert.strictEqual(options.redirect, 'error');
if (url.includes('/api/packages/')) {
assert.strictEqual(options.headers.Authorization, 'token package-token');
const [name, version, file] = url.split('/generic/')[1].split('/').map(decodeURIComponent);
const remoteContext = JSON.parse(fs.readFileSync(contextFile, 'utf8'));
assert.strictEqual(version, remoteContext.version);
if (name === missingPackage) return new Response(null, { status: 404 });
if (packageStatus !== 200) return new Response(null, { status: packageStatus });
if (file === 'release-context.json') {
return Response.json({ ...remoteContext,
runId: name === 'musrflow-windows' ? '789' : '456', ...remoteChange[name] });
}
assert(file.endsWith('.sha256'));
return new Response(badChecksum ? 'invalid' : `${'a'.repeat(64)} ${file.slice(0, -7)}\n`);
}
assert.strictEqual(options.headers.Authorization, 'token release-token');
if (options.method === 'POST') {
assert(url.endsWith('/releases'));
const payload = JSON.parse(options.body);
writes.push(payload);
if (concurrentRelease) existing = concurrentRelease;
return Response.json({ ...payload, id: 10, html_url: 'https://gitea.example.test/draft' }, { status: createStatus });
}
if (url.includes('/releases/tags/')) return existing ? Response.json(existing) : new Response(null, { status: 404 });
assert(url.endsWith(`/tags/${context.tag}`));
assert(url.endsWith(`/tags/${JSON.parse(fs.readFileSync(contextFile, 'utf8')).tag}`));
return Response.json({ commit: { sha: tagCommit } }, { status: tagStatus });
}
const draft = await createDraftRelease(directory, env, api);
@@ -77,8 +94,10 @@ async function main() {
assert.strictEqual(draft.target_commitish, context.commit);
assert(draft.body.includes('/generic/musrflow/2.3.4-rc.1/'));
assert(draft.body.includes('/generic/musrflow-runtime/2.3.4-rc.1/'));
assert(draft.body.includes('/generic/musrflow-windows/2.3.4-rc.1/muSRFlow-2.3.4-rc.1-x64.exe'));
assert(draft.body.includes('a'.repeat(64)));
assert(draft.body.includes('Packaging workflow run ID: 456'));
assert(draft.body.includes('Linux packaging workflow run ID: 456'));
assert(draft.body.includes('Windows packaging workflow run ID: 789'));
existing = { ...draft, body: draft.body + '\nUser-written notes', draft: false };
assert.deepStrictEqual(await createDraftRelease(directory, env, api), existing);
assert.strictEqual(writes.length, 1, 'do not edit or unpublish an existing Release');
@@ -92,21 +111,51 @@ async function main() {
assert.strictEqual(writes.length, 1, 'never create a missing tag');
tagStatus = 200;
existing = null;
// First platform waits; the last completed platform assembles the same
// five downloads regardless of which workflow reaches this step last.
for (const name of ['musrflow', 'musrflow-runtime', 'musrflow-windows']) {
missingPackage = name;
assert.strictEqual(await createDraftRelease(directory, env, api), null);
}
missingPackage = '';
packageStatus = 403;
await assert.rejects(createDraftRelease(directory, env, api), /release context: HTTP 403/);
packageStatus = 200;
for (const change of [{ commit: 'b'.repeat(40) }, { tag: 'v9.9.9' }, { version: '9.9.9' }, { schema: 2 }, { runId: 'invalid' }]) {
remoteChange = { 'musrflow-windows': change };
await assert.rejects(createDraftRelease(directory, env, api), /does not match the release/);
}
remoteChange = { 'musrflow-runtime': { runId: '999' } };
await assert.rejects(createDraftRelease(directory, env, api), /different packaging runs/);
remoteChange = {};
badChecksum = true;
await assert.rejects(createDraftRelease(directory, env, api), /Invalid checksum/);
badChecksum = false;
await assert.rejects(createDraftRelease(directory, { ...env, PACKAGES_TOKEN: '' }, api), /package read token/);
assert.strictEqual(writes.length, 1, 'incomplete or mismatched builds must not create a draft');
for (const status of [409, 422]) {
createStatus = status;
concurrentRelease = { ...draft, draft: false, body: draft.body + '\nReviewed notes' };
assert.deepStrictEqual(await createDraftRelease(directory, env, api), concurrentRelease);
existing = null;
}
concurrentRelease = { ...draft, body: 'Unrelated concurrent release' };
await assert.rejects(createDraftRelease(directory, env, api), /Concurrent Release could not be verified/);
concurrentRelease = null;
existing = null;
createStatus = 403;
await assert.rejects(createDraftRelease(directory, env, api), /Create draft Release: HTTP 403/);
await assert.rejects(createDraftRelease(directory, { ...env, RELEASES_TOKEN: '' }, api), /write token/);
// Stable versions are not marked as prereleases.
const stable = { ...context, tag: 'v2.3.4', version: '2.3.4' };
fs.writeFileSync(contextFile, JSON.stringify(stable));
for (const name of fs.readdirSync(directory).filter(name => name.endsWith('.sha256'))) {
fs.writeFileSync(path.join(directory, name.replace('-rc.1', '')), fs.readFileSync(path.join(directory, name), 'utf8').replace('-rc.1', ''));
}
const stableDraft = await createDraftRelease(directory, env, async (url, options) => {
if (options.method === 'POST') return Response.json({ ...JSON.parse(options.body), html_url: 'https://gitea.example.test/stable-draft' }, { status: 201 });
if (url.includes('/releases/tags/')) return new Response(null, { status: 404 });
return Response.json({ commit: { sha: context.commit } });
});
createStatus = 201;
const stableDraft = await createDraftRelease(directory, env, api);
assert.strictEqual(stableDraft.prerelease, false);
// Simulate a Windows artifact arriving last, with its own run ID.
fs.writeFileSync(contextFile, JSON.stringify({ ...context, runId: '789' }));
const windowsDraft = await createDraftRelease(directory, { ...env, PACKAGE_RUN_ID: '789' }, api);
assert.strictEqual(windowsDraft.body, draft.body);
fs.writeFileSync(contextFile, JSON.stringify({ ...context, tag: null }));
assert.strictEqual(await createDraftRelease(directory, env, async () => { throw new Error('Manual builds must not call the API'); }), null);
fs.unlinkSync(contextFile);
+4 -1
View File
@@ -114,7 +114,10 @@ const publishWorkflow = fs.readFileSync(path.join(root, '.gitea/workflows/publis
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 packages'));
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'));
+9 -2
View File
@@ -122,11 +122,18 @@ esac
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("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('ci-publish-packages.js'), 'do not publish untested Windows installers as releases');
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 });