Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,9 @@ jobs:
if: github.event_name == 'push' || github.event.inputs.platform == 'both' || github.event.inputs.platform == 'windows'
runs-on: windows-2025
timeout-minutes: 60
permissions:
actions: read
contents: read
outputs:
installer-sha256: ${{ steps.verify.outputs.installer-sha256 }}
payload-sha256: ${{ steps.verify.outputs.payload-sha256 }}
Expand Down Expand Up @@ -693,6 +696,7 @@ jobs:
"payload-sha256=$($checked.PayloadSha256)" >> $env:GITHUB_OUTPUT

- name: Upload verified NSIS artifact
id: upload-nsis
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: filament-manager-windows-nsis-${{ github.run_id }}
Expand All @@ -704,10 +708,16 @@ jobs:
retention-days: 14

- name: Download release NSIS candidate
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: filament-manager-windows-nsis-${{ github.run_id }}
path: ${{ runner.temp }}/filament-manager-windows-release-candidate
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
ARTIFACT_ID: ${{ steps.upload-nsis.outputs.artifact-id }}
ARTIFACT_SHA256: ${{ steps.upload-nsis.outputs.artifact-digest }}
run: |
$archive = Join-Path $env:RUNNER_TEMP "filament-manager-windows-release.zip"
node ./scripts/download-windows-release-artifact.mjs "$archive"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Expand-Archive -LiteralPath $archive -DestinationPath (Join-Path $env:RUNNER_TEMP "filament-manager-windows-release-candidate")

- name: Verify downloaded NSIS candidate
id: candidate
Expand Down
34 changes: 34 additions & 0 deletions scripts/download-windows-release-artifact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { createHash } from "node:crypto";
import { writeFile } from "node:fs/promises";
import { setTimeout as delay } from "node:timers/promises";

export async function downloadWindowsReleaseArtifact(env, request = fetch, wait = delay) {
const { ARTIFACT_ID, ARTIFACT_SHA256, GITHUB_API_URL, GITHUB_REPOSITORY, GH_TOKEN } = env;
if (!/^\d+$/.test(ARTIFACT_ID) || !/^[a-f\d]{64}$/i.test(ARTIFACT_SHA256) || !GH_TOKEN) {
throw new Error("Missing artifact ID, upload digest or Actions token.");
}
const url = `${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/actions/artifacts/${ARTIFACT_ID}/zip`;
for (let attempt = 1; ; attempt++) {
const response = await request(url, {
headers: { Authorization: `Bearer ${GH_TOKEN}` },
signal: AbortSignal.timeout(120_000),
});
if (response.status === 404 && attempt < 5) {
await response.body?.cancel();
const seconds = 2 ** attempt;
console.warn(`Artifact ${ARTIFACT_ID} not found (attempt ${attempt}/5). Retrying in ${seconds}s.`);
await wait(seconds * 1000);
continue;
}
if (!response.ok) throw new Error(`Artifact ${ARTIFACT_ID} download failed (HTTP ${response.status}).`);
const archive = Buffer.from(await response.arrayBuffer());
if (createHash("sha256").update(archive).digest("hex") !== ARTIFACT_SHA256.toLowerCase()) {
throw new Error(`Artifact ${ARTIFACT_ID} does not match the uploaded archive SHA-256.`);
}
return archive;
}
}

if (import.meta.main) {
await writeFile(process.argv[2], await downloadWindowsReleaseArtifact(process.env), { flag: "wx" });
}
45 changes: 42 additions & 3 deletions scripts/release-workflow-contract.test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import assert from "node:assert/strict";
import { existsSync, readFileSync } from "node:fs";
import test from "node:test";
import { createHash } from "node:crypto";
import { downloadWindowsReleaseArtifact } from "./download-windows-release-artifact.mjs";

const releaseWorkflow = readFileSync(
".github/workflows/release-build.yml",
Expand Down Expand Up @@ -274,7 +276,11 @@ test("release workflow gates tag and manual installer builds", () => {
assert.match(windowsJob, /\$checked\.PayloadSha256 -cne \$env:NSIS_PAYLOAD_SHA256/);
assert.match(windowsJob, /name: filament-manager-windows-nsis-\$\{\{ github\.run_id \}\}/);
assert.match(windowsJob, /- name: Upload verified NSIS artifact[\s\S]*?if-no-files-found: error\s+overwrite: true\s+retention-days: 14/);
assert.match(windowsJob, /- name: Download release NSIS candidate[\s\S]*?actions\/download-artifact@[a-f0-9]{40} # v8\.\d+\.\d+[\s\S]*?name: filament-manager-windows-nsis-\$\{\{ github\.run_id \}\}[\s\S]*?filament-manager-windows-release-candidate/);
assert.match(windowsJob, /- name: Upload verified NSIS artifact\s+id: upload-nsis/);
const download = readSection(windowsJob, "- name: Download release NSIS candidate", "- name: Verify downloaded NSIS candidate");
assert.match(download, /ARTIFACT_ID: \$\{\{ steps\.upload-nsis\.outputs\.artifact-id \}\}/);
assert.match(download, /ARTIFACT_SHA256: \$\{\{ steps\.upload-nsis\.outputs\.artifact-digest \}\}/);
assert.match(download, /download-windows-release-artifact\.mjs "\$archive"\s+if \(\$LASTEXITCODE -ne 0\) \{ exit \$LASTEXITCODE \}\s+Expand-Archive[^\n]+filament-manager-windows-release-candidate/);
assert.match(windowsJob, /path: \|\s+\$\{\{ runner\.temp \}\}\/filament-manager-windows-release-staging\/\*\.exe\s+\$\{\{ runner\.temp \}\}\/filament-manager-windows-release-staging\/SHA256SUMS-windows\.txt/);
assert.match(windowsJob, /NSIS_INSTALLER: \$\{\{ steps\.candidate\.outputs\.installer \}\}/);
assert.match(windowsJob, /\.\/scripts\/smoke-windows-msi\.ps1/);
Expand Down Expand Up @@ -670,7 +676,7 @@ test("release artifacts remain stable across partial workflow reruns", () => {
);
assert.equal(
countOccurrences(releaseWorkflow, `name: ${windowsArtifactName}`),
5,
4,
);
assert.equal(
countOccurrences(releaseWorkflow, `name: ${sbomArtifactName}`),
Expand Down Expand Up @@ -699,7 +705,7 @@ test("release artifacts remain stable across partial workflow reruns", () => {
);
assert.match(
windowsJob,
/- name: Download release NSIS candidate[\s\S]*?name: filament-manager-windows-nsis-\$\{\{ github\.run_id \}\}/,
/- name: Download release NSIS candidate[\s\S]*?ARTIFACT_ID: \$\{\{ steps\.upload-nsis\.outputs\.artifact-id \}\}/,
);
assert.match(
sbomJob,
Expand Down Expand Up @@ -2101,3 +2107,36 @@ test("partial Host-Client work deletion resumes only through an authorized clean
assert.match(windowsMsiSmoke, /credentialCleanupResult\.process_termination_confirmed -ne \$true/);
assert.match(windowsMsiSmoke, /if \(\$packagedHostClientE2eExitCode -ne 0\) \{\s+throw/);
});

test("Windows release download retries only missing artifacts and checks the upload digest", async () => {
const archive = Buffer.from("release archive");
const env = {
GITHUB_API_URL: "https://api.github.test", GITHUB_REPOSITORY: "owner/repo",
ARTIFACT_ID: "123", GH_TOKEN: "test-token",
ARTIFACT_SHA256: createHash("sha256").update(archive).digest("hex"),
};
async function run(statuses, settings = env) {
const waits = [];
const download = downloadWindowsReleaseArtifact(settings, async (url, options) => {
assert.equal(url, "https://api.github.test/repos/owner/repo/actions/artifacts/123/zip");
assert.equal(options.headers.Authorization, "Bearer test-token");
assert.ok(statuses.length, "unexpected extra download");
return new Response(archive, { status: statuses.shift() });
}, async ms => { waits.push(ms); });
return { download, waits };
}
for (const [statuses, delays] of [[[200], []], [[404, 404, 200], [2000, 4000]]]) {
const { download, waits } = await run(statuses);
assert.deepEqual(await download, archive);
assert.deepEqual(waits, delays);
}
for (const [statuses, digest, error, delays] of [
[[404, 404, 404, 404, 404], env.ARTIFACT_SHA256, /HTTP 404/, [2000, 4000, 8000, 16000]],
[[403], env.ARTIFACT_SHA256, /HTTP 403/, []],
[[200], "0".repeat(64), /SHA-256/, []],
]) {
const { download, waits } = await run(statuses, { ...env, ARTIFACT_SHA256: digest });
await assert.rejects(download, error);
assert.deepEqual(waits, delays);
}
});
Loading