Skip to content

The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.

fix(ci): decouple release cache keys from platform labels (#3251)

kekxy10d17a2bcd9a
diff --git a/.github/actions/release-build-cache/action.yml b/.github/actions/release-build-cache/action.yml
index cd03997cc..00109a2df 100644
--- a/.github/actions/release-build-cache/action.yml
+++ b/.github/actions/release-build-cache/action.yml
@@ -8,48 +8,67 @@ inputs:
dependency: { description: Local input file whose digest must match, default: '' }
manifest: { description: Published OCI manifest hex digest, default: '' }
outputs:
- key:
- description: Digest-bound key recorded by the successful build job
- value: ${{ steps.pack.outputs.key }}
+ record:
+ description: JSON provenance recorded in the successful build job
+ value: ${{ steps.pack.outputs.record }}
hit:
description: All files and the optional input digest matched
value: ${{ steps.verify.outputs.hit == 'true' && (inputs.registry-ref == '' || steps.registry.outputs.hit == 'true') }}
runs:
using: composite
steps:
+ - id: select
+ if: inputs.mode == 'restore'
+ uses: actions/github-script@v8
+ env:
+ PLAN: ${{ inputs.plan }}
+ UNIT: ${{ inputs.unit }}
+ with:
+ script: |
+ const plan = JSON.parse(process.env.PLAN)
+ const unit = process.env.UNIT
+ if (plan.attempt !== Number(process.env.GITHUB_RUN_ATTEMPT) || !Object.hasOwn(plan.sources, unit)) return
+ const { key, receipt, manifest } = plan.sources[unit]
+ core.setOutput('key', key)
+ core.setOutput('receipt', receipt)
+ core.setOutput('manifest', manifest)
- id: restore
- if: inputs.mode == 'restore' && fromJSON(inputs.plan).attempt == github.run_attempt && fromJSON(inputs.plan).sources[inputs.unit] != ''
+ if: steps.select.outputs.key != ''
continue-on-error: true
uses: actions/cache/restore@v4
with:
- key: ${{ fromJSON(inputs.plan).sources[inputs.unit] }}
+ key: ${{ steps.select.outputs.key }}
path: .release-build-cache
- id: verify
if: inputs.mode == 'restore' && steps.restore.outputs.cache-hit == 'true'
uses: actions/github-script@v8
env:
- SOURCE: ${{ fromJSON(inputs.plan).sources[inputs.unit] }}
+ RECEIPT: ${{ steps.select.outputs.receipt }}
UNIT: ${{ inputs.unit }}
DEPENDENCY: ${{ inputs.dependency }}
ACTION_DIR: ${{ github.action_path }}
with:
script: |
const { restoreFiles } = await import(require('node:url').pathToFileURL(process.env.ACTION_DIR + '/files.mjs').href)
- const { UNIT, SOURCE, DEPENDENCY, GITHUB_WORKSPACE } = process.env
- const hit = await restoreFiles({ root: GITHUB_WORKSPACE, unit: UNIT, dependency: DEPENDENCY, digest: SOURCE.split('.')[4] })
+ const { UNIT, RECEIPT, DEPENDENCY, GITHUB_WORKSPACE } = process.env
+ const hit = await restoreFiles({ root: GITHUB_WORKSPACE, unit: UNIT, dependency: DEPENDENCY, digest: RECEIPT })
core.setOutput('hit', hit)
+ - uses: oras-project/setup-oras@5e2f2482b30b0cb3e14e67f89a80c88c659a7c63 # v2.0.3
+ if: steps.verify.outputs.hit == 'true' && inputs.registry-ref != ''
+ with:
+ version: 1.3.6
- id: registry
if: steps.verify.outputs.hit == 'true' && inputs.registry-ref != ''
shell: bash
env:
REGISTRY_REF: ${{ inputs.registry-ref }}
- SOURCE: ${{ fromJSON(inputs.plan).sources[inputs.unit] }}
+ MANIFEST: ${{ steps.select.outputs.manifest }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
config="$RUNNER_TEMP/verify-ghcr-cache.json"
printf '%s' "$GH_TOKEN" | oras login ghcr.io --username "$GITHUB_ACTOR" --password-stdin --registry-config "$config"
- expected="sha256:${SOURCE##*.}"
+ expected="sha256:$MANIFEST"
if current=$(oras resolve --registry-config "$config" "$REGISTRY_REF") && [[ "$current" == "$expected" ]]; then
echo "hit=true" >> "$GITHUB_OUTPUT"
else
@@ -59,7 +78,7 @@ runs:
if: inputs.mode == 'save'
uses: actions/github-script@v8
env:
- PREFIX: ${{ fromJSON(inputs.plan).key }}
+ PLAN: ${{ inputs.plan }}
CHECK_ID: ${{ job.check_run_id }}
MANIFEST: ${{ inputs.manifest }}
UNIT: ${{ inputs.unit }}
@@ -70,7 +89,11 @@ runs:
const { saveFiles } = await import(require('node:url').pathToFileURL(process.env.ACTION_DIR + '/files.mjs').href)
const { UNIT, DEPENDENCY, GITHUB_WORKSPACE } = process.env
const receipt = await saveFiles({ root: GITHUB_WORKSPACE, unit: UNIT, dependency: DEPENDENCY })
- core.setOutput('key', [process.env.PREFIX, UNIT, process.env.GITHUB_RUN_ATTEMPT, process.env.CHECK_ID, receipt, process.env.MANIFEST].join('.'))
+ const { cacheKey } = await import(require('node:url').pathToFileURL(process.env.ACTION_DIR + '/record.mjs').href)
+ const record = JSON.stringify({ scope: JSON.parse(process.env.PLAN).key, unit: UNIT, attempt: Number(process.env.GITHUB_RUN_ATTEMPT),
+ check: process.env.CHECK_ID, receipt, manifest: process.env.MANIFEST })
+ core.setOutput('record', record)
+ core.setOutput('key', cacheKey(record))
- if: inputs.mode == 'save'
uses: actions/cache/save@v4
with:
diff --git a/.github/actions/release-build-cache/files.mjs b/.github/actions/release-build-cache/files.mjs
index d68b5e206..22a35c9dd 100644
--- a/.github/actions/release-build-cache/files.mjs
+++ b/.github/actions/release-build-cache/files.mjs
@@ -5,17 +5,21 @@ import { createHash } from 'node:crypto'
import { constants, createReadStream, globSync } from 'node:fs'
import { copyFile, lstat, mkdir, readFile, realpath, rm, writeFile } from 'node:fs/promises'
import { dirname, join, resolve } from 'node:path'
+import { validUnit } from './record.mjs'
function members(unit) {
+ assert.ok(validUnit(unit), 'Unknown build cache unit: ' + unit)
if (unit === 'runner') return ['boxlite-runner-*-linux-amd64.tar.gz', 'boxlite-runner-*-linux-amd64.tar.gz.sha256', 'producer.json']
if (unit === 'ghcr-runner') return ['runner.json', 'producer.json']
- if (/^ghcr-[a-z][a-z0-9-]*$/.test(unit)) return ['image.json', 'producer.json']
- const [, component, target] = /^(runtime|c|wheels|node)-([a-z0-9-]+)$/.exec(unit) || []
+ if (unit.startsWith('ghcr-')) return ['image.json', 'producer.json']
+ const separator = unit.indexOf('-')
+ const component = unit.slice(0, separator)
+ const target = unit.slice(separator + 1)
switch (component) {
- case 'runtime': return ['boxlite-runtime-*-' + target + '.tar.gz', 'boxlite-cli-*.tar.gz', 'producer.json']
- case 'c': return ['boxlite-c-*-' + target + '.tar.gz', 'producer.json']
+ case 'runtime': return [{ pattern: 'boxlite-runtime-*.tar.gz', suffix: '-' + target + '.tar.gz' }, 'boxlite-cli-*.tar.gz', 'producer.json']
+ case 'c': return [{ pattern: 'boxlite-c-*.tar.gz', suffix: '-' + target + '.tar.gz' }, 'producer.json']
case 'wheels': return ['wheelhouse/*.whl', 'wheelhouse/producer.json']
- case 'node': return ['sdks/node/artifacts-' + target + '.tar', 'sdks/node/packages/*.tgz', 'sdks/node/packages/producer.json']
+ case 'node': return [{ file: 'sdks/node/artifacts-' + target + '.tar' }, 'sdks/node/packages/*.tgz', 'sdks/node/packages/producer.json']
default: throw new Error('Unknown build cache unit: ' + unit)
}
}
@@ -28,9 +32,11 @@ async function digest(file) {
async function inventory(root, unit) {
const files = {}
- for (const pattern of members(unit)) {
- const names = globSync(pattern, { cwd: root }).sort()
- assert.ok(names.length, 'Missing build output: ' + pattern)
+ for (const member of members(unit)) {
+ const pattern = member.pattern ?? member
+ const names = member.file ? [member.file] : globSync(pattern, { cwd: root })
+ .filter(name => !member.suffix || name.endsWith(member.suffix)).sort()
+ assert.ok(names.length, 'Missing build output: ' + pattern + (member.suffix ?? ''))
for (const name of names) {
const path = join(root, name)
assert.equal(await realpath(path), resolve(await realpath(root), name))
diff --git a/.github/actions/release-build-cache/record.mjs b/.github/actions/release-build-cache/record.mjs
new file mode 100644
index 000000000..b0b0c8635
--- /dev/null
+++ b/.github/actions/release-build-cache/record.mjs
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 BoxLite AI
+import { createHash } from 'node:crypto'
+
+export function cacheKey(record) {
+ return 'release-output-v2-' + createHash('sha256').update(record).digest('hex')
+}
+
+export function validUnit(unit) {
+ if (unit === 'runner') return true
+ if (typeof unit !== 'string' || /[/\\\p{Cc}]/u.test(unit)) return false
+ const match = /^(?:runtime|c|wheels|node|ghcr)-(.+)$/su.exec(unit)
+ return Boolean(match && match[1] !== '.' && match[1] !== '..')
+}
diff --git a/.github/workflows/build-c.yml b/.github/workflows/build-c.yml
index 02218615d..15158204d 100644
--- a/.github/workflows/build-c.yml
+++ b/.github/workflows/build-c.yml
@@ -165,9 +165,11 @@ jobs:
- name: Package C SDK archive
if: steps.cache.outputs.hit != 'true'
+ env:
+ TARGET: ${{ matrix.target }}
run: |
VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
- ARCHIVE_DIR="boxlite-c-v${VERSION}-${{ matrix.target }}"
+ ARCHIVE_DIR="boxlite-c-v${VERSION}-$TARGET"
mkdir -p "${ARCHIVE_DIR}/lib" "${ARCHIVE_DIR}/include"
cp target/release/libboxlite.a "${ARCHIVE_DIR}/lib/"
@@ -190,15 +192,23 @@ jobs:
jq -n --arg sha "$(git rev-parse HEAD)" --argjson run "$GITHUB_RUN_ID" --argjson attempt "$GITHUB_RUN_ATTEMPT" \
'{sha: $sha, run: $run, attempt: $attempt}' > producer.json
+ - name: Stage archive for C SDK upload
+ env:
+ TARGET: ${{ matrix.target }}
+ run: |
+ set -euo pipefail
+ archives=(boxlite-c-v*-"$TARGET".tar.gz)
+ [[ ${#archives[@]} == 1 ]]
+ mkdir c-sdk-upload
+ ln "${archives[0]}" producer.json c-sdk-upload/
+
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
overwrite: true
if-no-files-found: error
name: c-sdk-${{ matrix.target }}
- path: |
- boxlite-c-v*-${{ matrix.target }}.tar.gz
- ./producer.json
+ path: c-sdk-upload/
retention-days: ${{ needs.resolve-ref.outputs.artifact-retention-days }}
- name: Save release build cache
@@ -210,6 +220,6 @@ jobs:
unit: c-${{ matrix.target }}
plan: ${{ inputs.build_plan }}
- - name: Build cache receipt ${{ steps.saved.outputs.key }}
- if: steps.saved.outputs.key != ''
+ - name: Build cache receipt ${{ steps.saved.outputs.record }}
+ if: steps.saved.outputs.record != ''
run: echo 'Recorded build output digests for whole-run retries.'
diff --git a/.github/workflows/build-node.yml b/.github/workflows/build-node.yml
index 612feab25..3ee2e81ae 100644
--- a/.github/workflows/build-node.yml
+++ b/.github/workflows/build-node.yml
@@ -130,7 +130,16 @@ jobs:
# See: https://github.com/actions/upload-artifact/issues/38
- name: Create artifact tarball
if: steps.cache.outputs.hit != 'true'
- run: tar -cvf sdks/node/artifacts-${{ matrix.target }}.tar -C sdks/node native/boxlite.js npm/
+ env:
+ TARGET: ${{ matrix.target }}
+ run: tar -cvf "sdks/node/artifacts-$TARGET.tar" -C sdks/node native/boxlite.js npm/
+
+ - name: Stage archive for Node upload
+ env:
+ TARGET: ${{ matrix.target }}
+ run: |
+ mkdir node-upload
+ ln "sdks/node/artifacts-$TARGET.tar" node-upload/
- name: Upload artifacts
uses: actions/upload-artifact@v4
@@ -138,7 +147,7 @@ jobs:
overwrite: true
if-no-files-found: error
name: artifacts-${{ matrix.target }}
- path: sdks/node/artifacts-${{ matrix.target }}.tar
+ path: node-upload/
retention-days: ${{ needs.config.outputs.artifact-retention-days }}
- name: Pack the native package and the Linux acceptance clients
@@ -184,8 +193,8 @@ jobs:
unit: node-${{ matrix.target }}
plan: ${{ inputs.build_plan }}
- - name: Build cache receipt ${{ steps.saved.outputs.key }}
- if: steps.saved.outputs.key != ''
+ - name: Build cache receipt ${{ steps.saved.outputs.record }}
+ if: steps.saved.outputs.record != ''
run: echo 'Recorded build output digests for whole-run retries.'
# ============================================================================
@@ -242,7 +251,9 @@ jobs:
# Extract tar to restore file permissions (see build job comment)
- name: Extract artifacts
- run: tar -xvf sdks/node/artifacts-${{ matrix.platform.target }}.tar -C sdks/node
+ env:
+ TARGET: ${{ matrix.platform.target }}
+ run: tar -xvf "sdks/node/artifacts-$TARGET.tar" -C sdks/node
- name: Test package
run: |
diff --git a/.github/workflows/build-runner-binary.yml b/.github/workflows/build-runner-binary.yml
index 70566512f..70f026dff 100644
--- a/.github/workflows/build-runner-binary.yml
+++ b/.github/workflows/build-runner-binary.yml
@@ -230,6 +230,6 @@ jobs:
plan: ${{ inputs.build_plan }}
dependency: sdks/go/libboxlite.a
- - name: Build cache receipt ${{ steps.saved.outputs.key }}
- if: steps.saved.outputs.key != ''
+ - name: Build cache receipt ${{ steps.saved.outputs.record }}
+ if: steps.saved.outputs.record != ''
run: echo 'Recorded build output digests for whole-run retries.'
diff --git a/.github/workflows/build-runtime.yml b/.github/workflows/build-runtime.yml
index a24ecb224..c1c3244c5 100644
--- a/.github/workflows/build-runtime.yml
+++ b/.github/workflows/build-runtime.yml
@@ -106,22 +106,34 @@ jobs:
bash scripts/build/package-runtime.sh "$BOXLITE_CI_TARGET"
command -v sccache &>/dev/null && sccache --show-stats || true
+ - name: Stage archive for runtime upload
+ env:
+ TARGET: ${{ matrix.target }}
+ run: |
+ set -euo pipefail
+ archives=(boxlite-runtime-v*-"$TARGET".tar.gz)
+ [[ ${#archives[@]} == 1 ]]
+ mkdir runtime-upload
+ ln "${archives[0]}" runtime-upload/
+
- name: Upload runtime artifact
uses: actions/upload-artifact@v4
with:
overwrite: true
if-no-files-found: error
name: runtime-${{ matrix.target }}
- path: boxlite-runtime-v*-${{ matrix.target }}.tar.gz
+ path: runtime-upload/
retention-days: 7
- name: Package CLI binary
if: steps.cache.outputs.hit != 'true'
+ env:
+ RUST_TARGET: ${{ matrix.rust_target }}
run: |
VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
CLI_BIN="target/release/boxlite"
[ -f "$CLI_BIN" ] || { echo "ERROR: CLI binary not found at $CLI_BIN"; exit 1; }
- tar czf "boxlite-cli-v${VERSION}-${{ matrix.rust_target }}.tar.gz" -C target/release boxlite
+ tar czf "boxlite-cli-v${VERSION}-$RUST_TARGET.tar.gz" -C target/release boxlite
- name: Record CLI build origin
if: steps.cache.outputs.hit != 'true' && (inputs.tag && (inputs.build_plan || matrix.target == 'linux-x64-gnu'))
@@ -129,15 +141,25 @@ jobs:
jq -n --arg sha "$(git rev-parse HEAD)" --argjson run "$GITHUB_RUN_ID" --argjson attempt "$GITHUB_RUN_ATTEMPT" \
'{sha:$sha,run:$run,attempt:$attempt}' > producer.json
+ - name: Stage archive for CLI upload
+ env:
+ RUST_TARGET: ${{ matrix.rust_target }}
+ REQUIRE_ORIGIN: ${{ inputs.tag != '' && (inputs.build_plan != '' || matrix.target == 'linux-x64-gnu') }}
+ run: |
+ set -euo pipefail
+ archives=(boxlite-cli-v*-"$RUST_TARGET".tar.gz)
+ [[ ${#archives[@]} == 1 ]]
+ mkdir cli-upload
+ ln "${archives[0]}" cli-upload/
+ if [[ "$REQUIRE_ORIGIN" == true ]]; then ln producer.json cli-upload/; fi
+
- name: Upload CLI artifact
uses: actions/upload-artifact@v4
with:
overwrite: true
if-no-files-found: error
name: cli-${{ matrix.target }}
- path: |
- boxlite-cli-v*-${{ matrix.rust_target }}.tar.gz
- producer.json
+ path: cli-upload/
retention-days: 7
- name: Save release build cache
@@ -149,8 +171,8 @@ jobs:
unit: runtime-${{ matrix.target }}
plan: ${{ inputs.build_plan }}
- - name: Build cache receipt ${{ steps.saved.outputs.key }}
- if: steps.saved.outputs.key != ''
+ - name: Build cache receipt ${{ steps.saved.outputs.record }}
+ if: steps.saved.outputs.record != ''
run: echo 'Recorded build output digests for whole-run retries.'
package:
diff --git a/.github/workflows/build-wheels.yml b/.github/workflows/build-wheels.yml
index 084b074d8..ddf95d4af 100644
--- a/.github/workflows/build-wheels.yml
+++ b/.github/workflows/build-wheels.yml
@@ -65,7 +65,7 @@ jobs:
uses: ./.release-ci/.github/actions/release-build-cache
with:
mode: restore
- unit: wheels-${{ matrix.os }}
+ unit: wheels-${{ matrix.target }}
plan: ${{ inputs.build_plan }}
- name: Set up the Python interpreter used by cibuildwheel
@@ -127,9 +127,9 @@ jobs:
uses: ./.release-ci/.github/actions/release-build-cache
with:
mode: save
- unit: wheels-${{ matrix.os }}
+ unit: wheels-${{ matrix.target }}
plan: ${{ inputs.build_plan }}
- - name: Build cache receipt ${{ steps.saved.outputs.key }}
- if: steps.saved.outputs.key != ''
+ - name: Build cache receipt ${{ steps.saved.outputs.record }}
+ if: steps.saved.outputs.record != ''
run: echo 'Recorded build output digests for whole-run retries.'
diff --git a/.github/workflows/mbuild-release.yml b/.github/workflows/mbuild-release.yml
index 7d76c9b75..3e3e0d54c 100644
--- a/.github/workflows/mbuild-release.yml
+++ b/.github/workflows/mbuild-release.yml
@@ -283,12 +283,6 @@ jobs:
- uses: actions/checkout@v5
with:
persist-credentials: false
- - uses: oras-project/setup-oras@5e2f2482b30b0cb3e14e67f89a80c88c659a7c63 # v2.0.3
- if: >-
- fromJSON(needs.resolve.outputs.build_plan || '{}').attempt == github.run_attempt &&
- fromJSON(needs.resolve.outputs.build_plan || '{}').sources[format('ghcr-{0}', matrix.artifact)] != ''
- with:
- version: 1.3.6
- name: Restore release build cache
id: cache
if: needs.resolve.outputs.build_plan != ''
@@ -353,8 +347,8 @@ jobs:
plan: ${{ needs.resolve.outputs.build_plan }}
manifest: ${{ steps.built.outputs.manifest }}
- - name: Build cache receipt ${{ steps.saved.outputs.key }}
- if: steps.saved.outputs.key != ''
+ - name: Build cache receipt ${{ steps.saved.outputs.record }}
+ if: steps.saved.outputs.record != ''
run: echo 'Recorded build output digests for whole-run retries.'
- name: Report
@@ -413,9 +407,6 @@ jobs:
sparse-checkout: .github/actions/release-build-cache
persist-credentials: false
- - uses: oras-project/setup-oras@5e2f2482b30b0cb3e14e67f89a80c88c659a7c63 # v2.0.3
- with:
- version: 1.3.6
- name: Restore release build cache
id: cache
if: needs.resolve.outputs.build_plan != ''
@@ -427,6 +418,10 @@ jobs:
registry-ref: ghcr.io/${{ github.repository }}/runner:${{ inputs.tag }}-${{ needs.resolve.outputs.sha }}
dependency: boxlite-runner-${{ inputs.tag }}-linux-amd64.tar.gz
+ - uses: oras-project/setup-oras@5e2f2482b30b0cb3e14e67f89a80c88c659a7c63 # v2.0.3
+ if: steps.cache.outputs.hit != 'true'
+ with:
+ version: 1.3.6
- name: Push the exact Runner archive
if: steps.cache.outputs.hit != 'true'
id: built
@@ -491,8 +486,8 @@ jobs:
dependency: boxlite-runner-${{ inputs.tag }}-linux-amd64.tar.gz
manifest: ${{ steps.built.outputs.manifest }}
- - name: Build cache receipt ${{ steps.saved.outputs.key }}
- if: steps.saved.outputs.key != ''
+ - name: Build cache receipt ${{ steps.saved.outputs.record }}
+ if: steps.saved.outputs.record != ''
run: echo 'Recorded build output digests for whole-run retries.'
draft-runtime:
diff --git a/apps/infra/docs/release.md b/apps/infra/docs/release.md
index aea7f0b84..3de772b46 100644
--- a/apps/infra/docs/release.md
+++ b/apps/infra/docs/release.md
@@ -44,6 +44,10 @@ A new failure artifact needs its own approval. Standalone E2E runs keep their no
**Re-run all jobs** checks the original producer's successful job record for this run, tag and source commit. Each platform restores its files from Actions Cache, verifies the recorded file set and SHA-256 digests, and uploads fresh Actions Artifacts for this attempt. A missing cache, changed file or failed producer rebuilds that platform.
+Each successful producer records its release scope, platform, attempt, check ID and digests as JSON. Retry selection matches the unit name case-sensitively and uses the SHA-256 of that record as its cache key. The ARM64 wheel uses the cache unit `wheels-linux-arm64-gnu` and uploads the Actions Artifact `wheels-ubuntu-24.04-arm`.
+
+The C SDK upload stages the exact archive and its `producer.json` together. A missing file fails the job before upload, including on a cache hit.
+
A partial rerun can copy an earlier job’s execution timeline under a new check ID. The planner keeps the original receipt, while a later build or failure supersedes it.
The Runner build also checks the input C library digest. Each GHCR publisher checks the live tag against the cached manifest while holding its publication lock. Before uploading Runner pins, it resolves the tag anonymously, reads the manifest, and downloads and hashes the blob against this run’s archive. Packaging, draft attachment and dev acceptance use the current attempt's uploads even when every platform reused its build.
diff --git a/apps/infra/scripts/release-build-plan.mjs b/apps/infra/scripts/release-build-plan.mjs
index 2a4c236d7..a17a03a8a 100644
--- a/apps/infra/scripts/release-build-plan.mjs
+++ b/apps/infra/scripts/release-build-plan.mjs
@@ -5,12 +5,13 @@ import { execFileSync } from 'node:child_process'
import { createHash } from 'node:crypto'
import { appendFileSync } from 'node:fs'
import { pathToFileURL } from 'node:url'
+import { cacheKey, validUnit } from '../../../.github/actions/release-build-cache/record.mjs'
export function buildKey(tag, sha, run) {
assert.match(tag, /^v\d+\.\d+\.\d+$/)
assert.match(sha, /^[0-9a-f]{40}$/)
assert.match(String(run), /^[1-9]\d*$/)
- return 'release-output-v1-' + createHash('sha256').update([tag, sha, run].join('@')).digest('base64url')
+ return createHash('sha256').update([tag, sha, run].join('@')).digest('base64url')
}
const hash = /^[0-9a-f]{64}$/
@@ -37,11 +38,18 @@ export function planBuilds({ key, attempt, jobs }) {
if (job.conclusion !== 'success' || !saved) continue
// The receipt digest comes from the original job's GitHub timeline, outside the mutable cache service.
const source = saved.name.slice('Build cache receipt '.length)
- const [prefix, unit, origin, check, receipt, manifest, ...extra] = source.split('.')
- if (prefix !== key || !hash.test(receipt) || extra.length || !/^[a-z][a-z0-9-]*$/.test(unit)) continue
- if (job.run_attempt !== Number(origin) || check !== job.check_run_url?.split('/').pop()) continue
- if (unit.startsWith('ghcr-') && !hash.test(manifest)) continue
- sources[unit] = source
+ let record
+ try {
+ record = JSON.parse(source)
+ } catch {
+ continue
+ }
+ if (!record || record.scope !== key || !validUnit(record.unit)) continue
+ const { unit, attempt: origin, check, receipt, manifest } = record
+ if (job.run_attempt !== origin || typeof check !== 'string' || !/^[1-9]\d*$/.test(check) || check !== job.check_run_url?.split('/').pop()) continue
+ if (typeof receipt !== 'string' || !hash.test(receipt)) continue
+ if (unit.startsWith('ghcr-') ? typeof manifest !== 'string' || !hash.test(manifest) : manifest !== '') continue
+ sources[unit] = { key: cacheKey(source), receipt, manifest }
}
return { key, attempt, sources }
}
diff --git a/apps/infra/scripts/release-build-plan.test.mjs b/apps/infra/scripts/release-build-plan.test.mjs
index 3c6195d29..c0f62f4ac 100644
--- a/apps/infra/scripts/release-build-plan.test.mjs
+++ b/apps/infra/scripts/release-build-plan.test.mjs
@@ -2,6 +2,7 @@ import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import { load } from 'js-yaml'
+import { cacheKey } from '../../../.github/actions/release-build-cache/record.mjs'
import { buildKey, planBuilds } from './release-build-plan.mjs'
const sha = '1'.repeat(40)
@@ -9,14 +10,14 @@ const receipt = '2'.repeat(64)
const manifest = '3'.repeat(64)
const key = buildKey('v1.2.3', sha, 10)
const workflow = load(readFileSync(new URL('../../../.github/workflows/mbuild-release.yml', import.meta.url)))
-const receiptStep = workflow.jobs.publish.steps.find(step => step.name?.includes('steps.saved.outputs.key')).name
+const receiptStep = workflow.jobs.publish.steps.find(step => step.name?.includes('steps.saved.outputs.record')).name
function producer(unit, attempt, check, published = '') {
- const source = [key, unit, attempt, check, receipt, published].join('.')
+ const source = JSON.stringify({ scope: key, unit, attempt, check: String(check), receipt, manifest: published })
return {
name: unit, run_attempt: attempt, check_run_url: 'https://api.github.com/repos/boxlite-ai/boxlite/check-runs/' + check,
conclusion: 'success',
- steps: [{ name: receiptStep.replace('${{ steps.saved.outputs.key }}', source), conclusion: 'success' }],
+ steps: [{ name: receiptStep.replace('${{ steps.saved.outputs.record }}', source), conclusion: 'success' }],
}
}
const select = (jobs, options) => planBuilds({ key, attempt: 4, jobs, ...options }).sources
@@ -24,7 +25,8 @@ const select = (jobs, options) => planBuilds({ key, attempt: 4, jobs, ...options
test('resolve uses the completed producer receipt even after GitHub removes all previous artifacts', () => {
const job = producer('wheels-ubuntu-latest', 1, 123)
const previousHit = { ...job, run_attempt: 2, steps: [{ name: 'Save release build cache', conclusion: 'skipped' }] }
- assert.equal(select([previousHit, job])[job.name], [key, job.name, 1, 123, receipt, ''].join('.'))
+ const keyFor = job => cacheKey(job.steps[0].name.slice('Build cache receipt '.length))
+ assert.deepEqual(select([previousHit, job])[job.name], { key: keyFor(job), receipt, manifest: '' })
for (const wrongKey of [buildKey('v1.2.4', sha, 10), buildKey('v1.2.3', 'a'.repeat(40), 10), buildKey('v1.2.3', sha, 11)])
assert.deepEqual(select([job], { key: wrongKey }), {})
assert.deepEqual(select([{ ...job, check_run_url: 'checks/124' }]), {})
@@ -34,7 +36,7 @@ test('resolve uses the completed producer receipt even after GitHub removes all
assert.deepEqual(select([job, { ...previousHit, conclusion }]), {})
assert.deepEqual(select([job, { ...previousHit, steps: [] }]), {}, 'unknown later output invalidates the old receipt')
const rebuilt = producer(job.name, 3, 456)
- assert.equal(select([rebuilt, previousHit, job])[job.name], [key, job.name, 3, 456, receipt, ''].join('.'))
+ assert.equal(select([rebuilt, previousHit, job])[job.name].key, keyFor(rebuilt))
})
test('only well-formed GHCR receipt digests reach publisher jobs', () => {
diff --git a/apps/infra/scripts/release-cache-units.test.mjs b/apps/infra/scripts/release-cache-units.test.mjs
new file mode 100644
index 000000000..8b7ef7385
--- /dev/null
+++ b/apps/infra/scripts/release-cache-units.test.mjs
@@ -0,0 +1,157 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 BoxLite AI
+import assert from 'node:assert/strict'
+import { globSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
+import { spawnSync } from 'node:child_process'
+import { data, Evaluator, Lexer, Parser } from '@actions/expressions'
+import { createRequire } from 'node:module'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+import { fileURLToPath } from 'node:url'
+import test from 'node:test'
+import { load } from 'js-yaml'
+import { buildKey, planBuilds } from './release-build-plan.mjs'
+import { saveFiles } from '../../../.github/actions/release-build-cache/files.mjs'
+
+const root = new URL('../../../', import.meta.url)
+const actionDir = fileURLToPath(new URL('.github/actions/release-build-cache/', root))
+const action = load(readFileSync(join(actionDir, 'action.yml'), 'utf8'))
+const workflow = load(readFileSync(new URL('.github/workflows/build-wheels.yml', root), 'utf8'))
+const platforms = JSON.parse(readFileSync(new URL('.github/ci-config.json', root))).platforms
+const scope = buildKey('v0.16.1', 'a'.repeat(40), 10)
+
+async function runScript(id, env) {
+ const script = action.runs.steps.find(step => step.id === id).with.script
+ const outputs = {}
+ const execute = new Function('core', 'process', 'require', 'return (async () => {' + script + '})()')
+ await execute({ setOutput: (name, value) => { outputs[name] = value } }, { env }, createRequire(import.meta.url))
+ return outputs
+}
+
+test('wheel cache receipts survive save, retry planning and verified restore for every platform and literal label', async t => {
+ const steps = workflow.jobs.build_wheels.steps
+ const unitFor = (id, platform) => steps.find(step => step.id === id).with.unit
+ .replace(/\$\{\{ matrix\.(\w+) \}\}/g, (_, field) => platform[field])
+ const units = platforms.map(platform => {
+ assert.equal(unitFor('cache', platform), unitFor('saved', platform))
+ return unitFor('saved', platform)
+ })
+ assert.equal(new Set(units).size, platforms.length)
+ for (const unit of new Set(['wheels-ubuntu-24.04-arm', ...units, 'wheels-平台 +_[]?,(v2)'])) {
+ const dir = mkdtempSync(join(tmpdir(), 'wheel-cache-'))
+ t.after(() => rmSync(dir, { recursive: true, force: true }))
+ const output = join(dir, 'wheelhouse')
+ mkdirSync(output)
+ writeFileSync(join(output, 'boxlite.whl'), unit)
+ writeFileSync(join(output, 'producer.json'), '{}')
+ const env = { ACTION_DIR: actionDir, GITHUB_WORKSPACE: dir, UNIT: unit, PLAN: JSON.stringify({key: scope}), CHECK_ID: '123', GITHUB_RUN_ATTEMPT: '1', MANIFEST: '' }
+ const saved = await runScript('pack', env)
+ const job = { name: 'Build wheels', run_attempt: 1, check_run_url: 'checks/123', conclusion: 'success',
+ steps: [{ name: 'Build cache receipt ' + saved.record, conclusion: 'success' }] }
+ const source = planBuilds({ key: scope, attempt: 2, jobs: [job] }).sources[unit]
+ assert.match(saved.key, /^release-output-v2-[a-f0-9]{64}$/)
+ assert.equal(source.key, saved.key)
+ rmSync(output, { recursive: true })
+ const restored = await runScript('verify', { ...env, RECEIPT: source.receipt })
+ assert.equal(restored.hit, true)
+ assert.equal(readFileSync(join(output, 'boxlite.whl'), 'utf8'), unit)
+ }
+})
+
+test('cache inventory matches target punctuation literally and rejects path components', async t => {
+ const dir = mkdtempSync(join(tmpdir(), 'release-cache-path-'))
+ t.after(() => rmSync(dir, { recursive: true, force: true }))
+ writeFileSync(join(dir, 'producer.json'), '{}')
+ const target = 'linux.[ab]+_x64'
+ const name = 'boxlite-c-v1-' + target + '.tar.gz'
+ writeFileSync(join(dir, name), 'literal')
+ writeFileSync(join(dir, 'boxlite-c-v1-linux.a+_x64.tar.gz'), 'other target')
+ await saveFiles({ root: dir, unit: 'c-' + target })
+ const { files } = JSON.parse(readFileSync(join(dir, '.release-build-cache/receipt.json')))
+ assert.deepEqual(Object.keys(files).sort(), [name, 'producer.json'])
+ for (const suffix of ['', '.', '..', 'x/y', 'x\\y', 'x\ny']) {
+ await assert.rejects(saveFiles({ root: dir, unit: 'wheels-' + suffix }), /cache unit/i)
+ }
+})
+
+function expression(input, context) {
+ const ast = new Parser(new Lexer(input.replace(/^\$\{\{\s*|\s*\}\}$/g, '')).lex().tokens, Object.keys(context), []).parse()
+ return new Evaluator(ast, JSON.parse(JSON.stringify(context), data.reviver)).evaluate().coerceString()
+}
+
+test('restore selects the exact case-sensitive unit from the actual retry plan', async () => {
+ const units = ['wheels-linux-A', 'wheels-linux-a']
+ const jobs = units.map((unit, i) => {
+ const check = String(123 + i), receipt = String(3 + i).repeat(64)
+ const record = JSON.stringify({ scope, unit, attempt: 1, check, receipt, manifest: '' })
+ return { name: unit, conclusion: 'success', run_attempt: 1, check_run_url: 'checks/' + check,
+ steps: [{ name: 'Build cache receipt ' + record, conclusion: 'success' }] }
+ })
+ const plan = planBuilds({ key: scope, attempt: 2, jobs })
+ const restore = action.runs.steps.find(step => step.id === 'restore')
+ const select = action.runs.steps.find(step => step.id === 'select')
+ assert.equal(select.env.PLAN, '${{ inputs.plan }}')
+ assert.equal(select.env.UNIT, '${{ inputs.unit }}')
+ for (const unit of [...units, 'wheels-LINUX-a']) {
+ const inputs = { mode: 'restore', plan: JSON.stringify(plan), unit }
+ const context = { inputs, github: { run_attempt: 2 }, steps: {} }
+ context.steps.select = { outputs: await runScript('select', { PLAN: inputs.plan, UNIT: unit, GITHUB_RUN_ATTEMPT: '2' }) }
+ assert.equal(expression(restore.with.key, context), plan.sources[unit]?.key ?? '', unit)
+ assert.equal(expression(restore.if, context), String(Object.hasOwn(plan.sources, unit)))
+ for (const [id, field] of [['verify', 'receipt'], ['registry', 'manifest']]) {
+ const step = action.runs.steps.find(item => item.id === id)
+ assert.equal(expression(step.env[field.toUpperCase()], context), plan.sources[unit]?.[field] ?? '')
+ }
+ }
+ for (const [attempt, sources] of [[3, plan.sources], [1, {}]]) {
+ const selected = await runScript('select', { PLAN: JSON.stringify({ ...plan, sources }), UNIT: units[0], GITHUB_RUN_ATTEMPT: String(attempt) })
+ assert.deepEqual(selected, {}, 'a stale plan cannot restore a previous build')
+ }
+})
+
+test('platform artifact uploads select the literal archive with its required origin', async t => {
+ const target = 'linux.[ab]+_x64'
+ const cases = [
+ ['c', 'Upload artifact', 'boxlite-c-v1.2.3-' + target + '.tar.gz', true],
+ ['runtime', 'Upload runtime artifact', 'boxlite-runtime-v1.2.3-' + target + '.tar.gz', false],
+ ['runtime', 'Upload CLI artifact', 'boxlite-cli-v1.2.3-' + target + '.tar.gz', true],
+ ['node', 'Upload artifacts', 'sdks/node/artifacts-' + target + '.tar', false],
+ ]
+ for (const [component, stepName, archive, origin] of cases) {
+ await t.test(stepName + ' in ' + component, () => {
+ const dir = mkdtempSync(join(tmpdir(), 'release-upload-'))
+ t.after(() => rmSync(dir, { recursive: true, force: true }))
+ mkdirSync(join(dir, 'sdks/node'), { recursive: true })
+ writeFileSync(join(dir, archive), 'archive')
+ writeFileSync(join(dir, 'producer.json'), '{}')
+ writeFileSync(join(dir, 'Cargo.toml'), 'version = "1.2.3"\n')
+ const job = load(readFileSync(new URL('.github/workflows/build-' + component + '.yml', root))).jobs.build
+ const index = job.steps.findIndex(step => step.name === stepName)
+ const upload = job.steps[index]
+ const stage = job.steps[index - 1]
+ const env = { ...process.env, TARGET: target, RUST_TARGET: target, REQUIRE_ORIGIN: 'true' }
+ const prepare = () => spawnSync('bash', ['-e', '-c', stage.run], { cwd: dir, env, encoding: 'utf8' })
+ assert.match(stage.name, /^Stage archive for /)
+ const result = prepare()
+ assert.equal(result.status, 0, result.stderr)
+ const paths = upload.with.path.trim().replace(/\$\{\{ matrix\.(?:rust_)?target \}\}/g, target).split('\n')
+ const files = paths.flatMap(pattern => globSync(pattern, { cwd: dir })).flatMap(item =>
+ statSync(join(dir, item)).isDirectory() ? readdirSync(join(dir, item)) : [item.split('/').pop()])
+ assert.deepEqual(files.sort(), [archive.split('/').pop(), ...(origin ? ['producer.json'] : [])].sort())
+ rmSync(join(dir, paths[0]), { recursive: true })
+ if (origin) {
+ rmSync(join(dir, 'producer.json'))
+ assert.notEqual(prepare().status, 0, 'a missing required origin must stop the upload')
+ rmSync(join(dir, paths[0]), { recursive: true })
+ if (component === 'runtime') {
+ env.REQUIRE_ORIGIN = 'false'
+ assert.equal(prepare().status, 0, 'standalone CLI archives can omit origin')
+ rmSync(join(dir, paths[0]), { recursive: true })
+ }
+ writeFileSync(join(dir, 'producer.json'), '{}')
+ }
+ rmSync(join(dir, archive))
+ assert.notEqual(prepare().status, 0, 'a missing archive must stop the upload')
+ })
+ }
+})
diff --git a/apps/infra/scripts/release-registry-retry.test.mjs b/apps/infra/scripts/release-registry-retry.test.mjs
index f3f8041f9..e19cb3ea4 100644
--- a/apps/infra/scripts/release-registry-retry.test.mjs
+++ b/apps/infra/scripts/release-registry-retry.test.mjs
@@ -10,6 +10,7 @@ import { fileURLToPath } from 'node:url'
import test from 'node:test'
import { data, Evaluator, Lexer, Parser } from '@actions/expressions'
import { load } from 'js-yaml'
+import { cacheKey } from '../../../.github/actions/release-build-cache/record.mjs'
import { buildKey } from './release-build-plan.mjs'
const root = fileURLToPath(new URL('../../../', import.meta.url))
@@ -20,7 +21,6 @@ const tag = 'v1.2.3'
const sha = '1'.repeat(40)
const manifest = 'sha256:' + hash('manifest')
const blob = 'sha256:' + hash('runner bytes')
-const source = [buildKey(tag, sha, 10), 'ghcr-runner', 1, 123, hash('receipt'), manifest.slice(7)].join('.')
function evaluate(expression, context) {
const raw = expression.replace(/^\$\{\{\s*|\s*\}\}$/g, '')
@@ -60,7 +60,7 @@ esac
test('resolve still plans a full retry when registry login is unavailable', t => {
const { dir, env } = fixture(t)
- const wheel = [buildKey(tag, sha, 10), 'wheels-macos-15', 1, 321, hash('wheel'), ''].join('.')
+ const wheel = JSON.stringify({ scope: buildKey(tag, sha, 10), unit: 'wheels-darwin-arm64', attempt: 1, check: '321', receipt: hash('wheel'), manifest: '' })
const producer = { name: 'build wheels on macOS', conclusion: 'success', run_attempt: 1,
check_run_url: 'checks/321', steps: [{ name: 'Build cache receipt ' + wheel, conclusion: 'success' }] }
writeFileSync(join(dir, 'jobs.json'), JSON.stringify([{ jobs: [producer] }]))
@@ -68,7 +68,7 @@ test('resolve still plans a full retry when registry login is unavailable', t =>
const step = jobs.resolve.steps.find(step => step.id === 'retry')
const result = spawnSync('bash', ['-c', step.run], { cwd: root, env: { ...env, DENY_LOGIN: '1' }, encoding: 'utf8' })
assert.equal(result.status, 0, result.stderr)
- assert.equal(JSON.parse(readFileSync(env.GITHUB_OUTPUT, 'utf8').trim().slice(5)).sources['wheels-macos-15'], wheel)
+ assert.equal(JSON.parse(readFileSync(env.GITHUB_OUTPUT, 'utf8').trim().slice(5)).sources['wheels-darwin-arm64'].key, cacheKey(wheel))
assert.ok(!jobs.resolve.steps.some(step => step.uses?.startsWith('oras-project/')))
})
@@ -79,7 +79,7 @@ test('a tag changed after resolve turns a verified local cache hit into a publis
const outputs = {}
if (check) {
writeFileSync(env.GITHUB_OUTPUT, '')
- const result = spawnSync('bash', ['-c', check.run], { cwd: dir, env: { ...env, REMOTE: remote, SOURCE: source,
+ const result = spawnSync('bash', ['-c', check.run], { cwd: dir, env: { ...env, REMOTE: remote, MANIFEST: manifest.slice(7),
REGISTRY_REF: 'ghcr.io/boxlite-ai/boxlite/runner:' + tag + '-' + sha }, encoding: 'utf8' })
assert.equal(result.status, 0, result.stderr)
for (const line of readFileSync(env.GITHUB_OUTPUT, 'utf8').trim().split('\n')) {
diff --git a/apps/infra/scripts/release-workflow.test.mjs b/apps/infra/scripts/release-workflow.test.mjs
index 1fd06fb64..e04d05895 100644
--- a/apps/infra/scripts/release-workflow.test.mjs
+++ b/apps/infra/scripts/release-workflow.test.mjs
@@ -109,14 +109,8 @@ test('release caller routes the pinned C SDK build to its qualified runner', ()
test('only a full retry can restore, while fresh and selected jobs build and upload', () => {
const action = load(readFileSync(new URL('../../../.github/actions/release-build-cache/action.yml', import.meta.url)))
- const guard = action.runs.steps.find(step => step.id === 'restore').if
- const unit = 'wheels-macos-15'
- const plan = JSON.stringify({ attempt: 2, sources: { [unit]: 'verified-key' } })
- for (const [attempt, buildPlan, expected] of [[2, plan, true], [3, plan, false], [1, '{"attempt":1,"sources":{}}', false]]) {
- const context = { github: { run_attempt: String(attempt) }, inputs: { mode: 'restore', plan: buildPlan, unit } }
- const ast = new Parser(new Lexer(guard).lex().tokens, Object.keys(context), []).parse()
- assert.equal(new Evaluator(ast, JSON.parse(JSON.stringify(context), data.reviver)).evaluate().value, expected)
- }
+ assert.equal(action.runs.steps.find(step => step.id === 'select').if, "inputs.mode == 'restore'")
+ assert.equal(action.runs.steps.find(step => step.id === 'restore').if, "steps.select.outputs.key != ''")
const producers = [
...[['runtime','build'],['node','build'],['c','build'],['wheels','build_wheels'],['runner-binary','build']].map(
([file, id]) => readWorkflow('build-' + file).jobs[id]),