The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.
fix(ci): skip existing package versions during release publication (#3280)
kekxy547cd9a0354d
diff --git a/.github/workflows/mbuild-release.yml b/.github/workflows/mbuild-release.ymlindex e9b58891a..1c9ffcead 100644--- a/.github/workflows/mbuild-release.yml+++ b/.github/workflows/mbuild-release.yml@@ -897,7 +897,7 @@ jobs:if: >-${{ github.ref == 'refs/heads/main' && contains(fromJSON('["publish","publish-node","repair-node"]'), inputs.command) &&!cancelled() && needs.attach.result == 'success' }}- name: Publish verified npm packages+ name: Publish npm packagesneeds: [resolve, attach]runs-on: ubuntu-latestpermissions:@@ -926,36 +926,23 @@ jobs:set -euo pipefailcd "$RELEASE_ASSET_DIR"missing_files=()- missing_packages=()- missing_integrities=()for file in boxlite-ai-boxlite-*-"${TAG#v}.tgz" "boxlite-ai-boxlite-${TAG#v}.tgz"; doname=$(tar -xOzf "$file" package/package.json | jq -er .name)version=$(tar -xOzf "$file" package/package.json | jq -er .version)expected=${file#boxlite-ai-}expected=${expected%-"${TAG#v}".tgz}[[ "$name" == "@boxlite-ai/$expected" && "$version" == "${TAG#v}" ]]- integrity="sha512-$(openssl dgst -sha512 -binary "$file" | openssl base64 -A)"package="$name@$version"- if existing=$(npm view "$package" dist.integrity --json 2> "$RUNNER_TEMP/npm-view.log"); then- if [[ "$(jq -r . <<< "$existing")" != "$integrity" ]]; then- echo "Conflicting npm integrity for $package" >&2- exit 1- fi- else- grep -q E404 "$RUNNER_TEMP/npm-view.log" || { cat "$RUNNER_TEMP/npm-view.log" >&2; exit 1; }- missing_files+=("$file")- missing_packages+=("$package")- missing_integrities+=("$integrity")+ if npm view "$package" version dist.integrity --json > "$RUNNER_TEMP/npm-version.json" 2> "$RUNNER_TEMP/npm-view.log"; then+ bash "$GITHUB_WORKSPACE/scripts/release/external-publication.sh" npm "$file" "$package" "$RUNNER_TEMP/npm-version.json"+ continuefi+ grep -q E404 "$RUNNER_TEMP/npm-view.log" || { cat "$RUNNER_TEMP/npm-view.log" >&2; exit 1; }+ missing_files+=("$file")done- for i in "${!missing_files[@]}"; do- npm publish "./${missing_files[i]}" --access public --provenance- published=$(npm view "${missing_packages[i]}" dist.integrity)- if [[ "$published" != "${missing_integrities[i]}" ]]; then- echo "Uploaded npm integrity differs for ${missing_packages[i]}" >&2- exit 1- fi+ for index in "${!missing_files[@]}"; do+ npm publish "./${missing_files[$index]}" --access public --provenancedonepypi:@@ -985,22 +972,17 @@ jobs:tag: ${{ inputs.tag }}sha: ${{ needs.resolve.outputs.sha }}- name: Select accepted wheels- run: mkdir dist && cp "$RELEASE_ASSET_DIR"/*.whl dist/-- - name: Check existing PyPI wheels before uploading+ id: wheelsenv:TAG: ${{ inputs.tag }}- run: bash scripts/release/verify-pypi-wheels.sh before+ run: bash "$GITHUB_WORKSPACE/scripts/release/external-publication.sh" wheels- name: Publish to PyPI+ if: steps.wheels.outputs.has_missing == 'true'uses: pypa/gh-action-pypi-publish@release/v1with:packages-dir: dist/skip-existing: true- - name: Verify PyPI recorded the accepted wheel hashes- env:- TAG: ${{ inputs.tag }}- run: bash scripts/release/verify-pypi-wheels.sh aftertag-go-module:concurrency:@@ -1022,15 +1004,10 @@ jobs:with:fetch-depth: 0- - name: Verify public C SDK downloads- env:- TAG: ${{ inputs.tag }}- RELEASE_ID: ${{ needs.resolve.outputs.release_id }}- run: node apps/infra/scripts/release-candidate.mjs verify-public-c-- name: Create Go module tagshell: bashenv:+ RELEASE_ID: ${{ needs.resolve.outputs.release_id }}C_SHA: ${{ needs.resolve.outputs.sha }}RELEASE_TAG: ${{ inputs.tag }}run: |@@ -1038,20 +1015,14 @@ jobs:product_ref="refs/tags/$RELEASE_TAG"go_ref="refs/tags/sdks/go/$RELEASE_TAG"- # Fetch the current remote ref because the tag could have moved during the matrix.- git fetch --no-tags origin "$product_ref"- if [[ "$(git rev-parse --verify 'FETCH_HEAD^{commit}')" != "$C_SHA" ]]; then- echo "Product tag $RELEASE_TAG moved during Go release tests" >&2- exit 1- fi-if git ls-remote --exit-code --refs origin "$go_ref" >/dev/null; then- git fetch --no-tags origin "$go_ref"- if [[ "$(git rev-parse --verify 'FETCH_HEAD^{commit}')" != "$C_SHA" ]]; then- echo "Go tag $go_ref points to a different commit" >&2- exit 1+ if git fetch --no-tags origin "$go_ref" && actual=$(git rev-parse --verify 'FETCH_HEAD^{commit}'); then+ if [[ "$actual" != "$C_SHA" ]]; then+ printf -- '- Skipped %s (different commit). Release %s, existing tag %s.\n' "$go_ref" "$C_SHA" "$actual" >> "$GITHUB_STEP_SUMMARY"+ fi+ else+ printf -- '- Skipped %s (already exists); could not compare commit SHAs.\n' "$go_ref" >> "$GITHUB_STEP_SUMMARY"fi- echo "Go tag $go_ref already points to $C_SHA"exit 0elsestatus=$?@@ -1059,6 +1030,14 @@ jobs:if [[ "$status" != 2 ]]; then exit "$status"; fifi+ TAG="$RELEASE_TAG" node apps/infra/scripts/release-candidate.mjs verify-public-c+ # Downloads can take several minutes. Check the current product commit just before tagging.+ git fetch --no-tags origin "$product_ref"+ if [[ "$(git rev-parse --verify 'FETCH_HEAD^{commit}')" != "$C_SHA" ]]; then+ echo "Product tag $RELEASE_TAG moved before Go module publication" >&2+ exit 1+ fi+git push origin "$C_SHA:$go_ref"publish_crates:@@ -1074,12 +1053,20 @@ jobs:runs-on: ubuntu-latestenv:BOXLITE_DEPS_STUB: "1"+ RELEASE_TAG: ${{ inputs.tag }}steps:- uses: actions/checkout@v4with:ref: ${{ needs.resolve.outputs.sha }}+ - uses: actions/checkout@v5+ with:+ ref: ${{ github.sha }}+ path: .release-ci+ sparse-checkout: scripts/release+ persist-credentials: false+- uses: ./.github/actions/setup-rust- name: Install protoc@@ -1091,23 +1078,7 @@ jobs:run: |set -euo pipefail- publish_crate() {- local crate="$1"- shift- local extra_args="$*"- echo "::group::Publishing $crate"- if cargo publish -p "$crate" $extra_args 2>&1 | tee /tmp/publish-"$crate".log; then- echo "$crate published successfully"- else- if grep -q "already uploaded" /tmp/publish-"$crate".log; then- echo "$crate already on crates.io, skipping"- else- echo "::error::Failed to publish $crate"- exit 1- fi- fi- echo "::endgroup::"- }+ publish_crate() { bash .release-ci/scripts/release/external-publication.sh crate "$@"; }# Pure-Rust crate verifies normallypublish_crate boxlite-shared@@ -1134,20 +1105,7 @@ jobs:- name: Publish boxlite (Tier 2)env:CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}- run: |- set -euo pipefail- echo "::group::Publishing boxlite"- if cargo publish -p boxlite --no-verify 2>&1 | tee /tmp/publish-boxlite.log; then- echo "boxlite published successfully"- else- if grep -q "already uploaded" /tmp/publish-boxlite.log; then- echo "boxlite already on crates.io, skipping"- else- echo "::error::Failed to publish boxlite"- exit 1- fi- fi- echo "::endgroup::"+ run: bash .release-ci/scripts/release/external-publication.sh crate boxlite --no-verify- name: Wait for boxlite indexingrun: sleep 60@@ -1158,20 +1116,7 @@ jobs:- name: Publish boxlite-cli (Tier 3)env:CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}- run: |- set -euo pipefail- echo "::group::Publishing boxlite-cli"- if cargo publish -p boxlite-cli --no-verify 2>&1 | tee /tmp/publish-boxlite-cli.log; then- echo "boxlite-cli published successfully"- else- if grep -q "already uploaded" /tmp/publish-boxlite-cli.log; then- echo "boxlite-cli already on crates.io, skipping"- else- echo "::error::Failed to publish boxlite-cli"- exit 1- fi- fi- echo "::endgroup::"+ run: bash .release-ci/scripts/release/external-publication.sh crate boxlite-cli --no-verifyfinalize:concurrency:diff --git a/apps/infra/docs/release.md b/apps/infra/docs/release.mdindex 12bba91ec..874bb18c7 100644--- a/apps/infra/docs/release.md+++ b/apps/infra/docs/release.md@@ -58,13 +58,19 @@ The Runner build also checks the input C library digest. Each GHCR publisher cheFor a failed production job, use **Re-run failed jobs** in the original release run. Before requesting approval and after approval, production checks the saved dev acceptance against the run ID, accepted attempt, candidate artifact ID, manifest digest, tag and source commit. A different candidate needs its own dev E2E.-If finalization loses the GitHub response after publishing, retry the failed job. It verifies the published files and their digests without modifying them. PyPI compares existing wheel hashes before it uploads any missing files and verifies the full set afterward.+If finalization loses the GitHub response after publishing, retry the failed job. It verifies the published files and their digests without modifying them.A same-version Runner rebuild changes the pinned manifest. Hosts record the installed manifest and archive digests and reapply when either changes.Each Runtime or CLI tarball sidecar and the installer sidecar `install.sh.sha256` occupies one entry in the release inventory. During a full release, the attachment job checks all existing selected files before uploading missing files. If a digest conflicts, the job stops before its first upload so the operator can inspect the originating run.-The npm publisher checks all existing platform packages and the main package before its first upload. It publishes missing platform packages before the main package and verifies each new registry digest. A retry reuses matching packages.+External publishers first look up the exact npm or crate version, PyPI wheel filename, or Go module tag. Only missing items are published. npm publishes missing platform packages before the main package and finishes each upload when npm accepts the tarball. Until npm indexes the matching platform package, a fresh install of the main package can temporarily lack its native binding.++For an existing item the run compares npm tarball SHA-512 integrity, wheel or crate SHA-256, or the Go tag's target commit. An exact match is silent.++A difference adds the item and both digests or commits to the job summary. If a comparison cannot finish, the summary marks the item as skipped and unverified. Both outcomes allow publication of missing items to continue.++A failed existence lookup or an unsuccessful upload still fails its job.### Roll back to a release that predates the manifest@@ -92,7 +98,7 @@ Run `mbuild-release.yml` from `main` and select an existing product Release tag.| `publish-go` | Builds the C SDK matrix, tests Go, then tags `sdks/go/vX.Y.Z` only after downloading every versioned C SDK archive anonymously from the public Release and verifying its GitHub asset digest. || `publish-runner` | Builds the Linux x64 C SDK and Runner, pushes the Runner to GHCR and attaches its archive and checksum to GitHub Release. |-Single-component publication replaces the selected component's same-name Release attachments, including on a public Release. PyPI and npm still require an existing registry file at that version to match the package being published.+Single-component publication replaces the selected component's same-name Release attachments, including on a public Release. PyPI skips existing wheel files and npm skips existing package versions.The reusable Runtime, wheel, Node, C and Go workflows accept `spec_platform` values `linux-x64`, `except-linux-x64` and `all` (default). In a full release, both groups run concurrently. Dev needs the Linux x64 clients and GHCR pins. The Runtime installer and the npm distribution wait for both groups. Package publication and the Go module tag wait for all required platform tests.@@ -127,7 +133,7 @@ On **Actions → mbuild-release → Run workflow**, select `main`, enter the pub| `repair-node` | Publish the Release's native npm packages, followed by its main npm package. || `repair-runtime` | Restore missing Runtime attachments and publish crates.io packages from the tagged source. || `repair-c` | Restore missing public C SDK archives. |-| `repair-go` | Verify public C SDK downloads and create the Go module tag at the product commit. An existing tag at that commit is accepted. |+| `repair-go` | Skip an existing module tag and report a differing target commit. For a missing tag, verify the public C SDK downloads and recheck the remote product commit immediately before pushing the module tag. |For example, `gh workflow run mbuild-release.yml --ref main -f command=repair-node -f tag=v0.16.1` takes the npm packages already present on the Release. A complete set works without a candidate manifest or a dev receipt.diff --git a/apps/infra/scripts/release-workflow.test.mjs b/apps/infra/scripts/release-workflow.test.mjsindex 022c5b093..ffe10964c 100644--- a/apps/infra/scripts/release-workflow.test.mjs+++ b/apps/infra/scripts/release-workflow.test.mjs@@ -1,9 +1,10 @@import assert from 'node:assert/strict'import { execFileSync, spawnSync } from 'node:child_process'import { createHash } from 'node:crypto'-import { copyFileSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'+import { copyFileSync, mkdtempSync, mkdirSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'import { tmpdir } from 'node:os'import { dirname, join } from 'node:path'+import { fileURLToPath } from 'node:url'import test from 'node:test'import { data, Evaluator, Lexer, Parser } from '@actions/expressions'import { load } from 'js-yaml'@@ -11,6 +12,7 @@ import { selectRelease } from './release-selection.mjs'const readWorkflow = (name) =>load(readFileSync(new URL('../../../.github/workflows/' + name + '.yml', import.meta.url), 'utf8'))+const workspace = fileURLToPath(new URL('../../../', import.meta.url))const release = readWorkflow('mbuild-release')const rollout = readWorkflow('mdeploy-all')@@ -291,7 +293,7 @@ test('prod may retry a previous attempt only with the exact dev acceptance recei}})-test('npm preflights all packages before publishing and verifies missing packages in order', (t) => {+test('npm preflights all packages and publishes in order while new versions await indexing', (t) => {const dir = mkdtempSync(join(tmpdir(), 'boxlite-npm-publication-'))t.after(() => rmSync(dir, { recursive: true, force: true }))const tag = 'v1.2.3'@@ -311,84 +313,100 @@ test('npm preflights all packages before publishing and verifies missing package'set -euo pipefail','case "$1" in',' view)',- ' entry="$RUNNER_TEMP/${2##*/}.integrity"',- ' if [[ ! -f "$entry" ]]; then echo "npm error code E404" >&2; exit 1; fi',- ' if [[ "${4:-}" == --json ]]; then jq -Rs . < "$entry"; else cat "$entry"; fi ;;',+ ' if [[ -f "$RUNNER_TEMP/lookup-failure" ]]; then echo "npm error code E401" >&2; exit 1; fi',+ ' if [[ ! -f "$RUNNER_TEMP/${2##*/}.visible" ]]; then echo "npm error code E404" >&2; exit 1; fi',+ ' cat "$RUNNER_TEMP/${2##*/}.visible" ;;',' publish)'," id=$(tar -xOzf \"$2\" package/package.json | jq -r '.name + \"@\" + .version')",- ' echo "$id" >> "$RUNNER_TEMP/published"',- ' digest=$(openssl dgst -sha512 -binary "$2" | openssl base64 -A)',- ' printf %s "${CORRUPT:-sha512-$digest}" > "$RUNNER_TEMP/${id##*/}.integrity" ;;',+ ' if [[ "${FAIL_PUBLISH:-}" == "$id" ]]; then exit 3; fi',+ ' echo "$id" >> "$RUNNER_TEMP/published" ;;',' *) exit 2 ;;','esac',].join('\n'), { mode: 0o755 })const script = release.jobs.npm.steps.find(step => step.name === 'Publish platform packages before the main package').runconst publish = (extra = {}) => spawnSync('bash', ['-ec', script], {cwd: dir, encoding: 'utf8',- env: { ...process.env, PATH: dir + ':' + process.env.PATH, RELEASE_ASSET_DIR: dir, RUNNER_TEMP: dir, TAG: tag, ...extra },+ env: { ...process.env, PATH: dir + ':' + process.env.PATH, RELEASE_ASSET_DIR: dir, RUNNER_TEMP: dir, GITHUB_WORKSPACE: workspace, GITHUB_STEP_SUMMARY: join(dir, 'summary'), TAG: tag, ...extra },})- const mainEntry = join(dir, '[email protected]')- writeFileSync(mainEntry, 'sha512-conflict')- assert.notEqual(publish().status, 0, 'existing main package conflicts')- assert.equal(readFileSync(record, 'utf8'), '', 'a later conflict must block even the first platform upload')- rmSync(mainEntry)+ const lookupFailure = join(dir, 'lookup-failure')+ writeFileSync(lookupFailure, '')+ assert.notEqual(publish().status, 0)+ assert.equal(readFileSync(record, 'utf8'), '', 'an unauthorized lookup must stop publication')+ rmSync(lookupFailure)+ assert.equal(publish({ FAIL_PUBLISH: platform }).status, 3)+ assert.equal(readFileSync(record, 'utf8'), '', 'a platform publish failure must stop the main publish')const first = publish()assert.equal(first.status, 0, first.stderr)assert.deepEqual(readFileSync(record, 'utf8').trim().split('\n'), [platform, main])+writeFileSync(record, '')- const retry = publish()- assert.equal(retry.status, 0, retry.stderr)- assert.equal(readFileSync(record, 'utf8'), '', 'matching packages must be reused')- rmSync(mainEntry)- assert.notEqual(publish({ CORRUPT: 'sha512-wrong' }).status, 0, 'the registry must report the uploaded digest')+ const summary = join(dir, 'summary')+ writeFileSync(summary, '')+ const integrity = name => 'sha512-' + createHash('sha512').update(readFileSync(join(dir, name))).digest('base64')+ const existing = (name, sri) => writeFileSync(join(dir, name + '@1.2.3.visible'), JSON.stringify({ version: '1.2.3', 'dist.integrity': sri }))+ existing('boxlite-linux-x64-gnu', integrity('boxlite-ai-boxlite-linux-x64-gnu-1.2.3.tgz'))+ assert.equal(publish().status, 0)assert.equal(readFileSync(record, 'utf8').trim(), main)+ writeFileSync(record, '')+ assert.equal(readFileSync(summary, 'utf8'), '', 'identical bytes are silent')+ const other = 'sha512-' + createHash('sha512').update('other').digest('base64')+ existing('boxlite', other)+ assert.equal(publish().status, 0)+ assert.equal(readFileSync(record, 'utf8'), '', 'published versions must be skipped')+ assert.ok(readFileSync(summary, 'utf8').includes(other), 'report both digests for an existing, different tarball')+ assert.ok(readFileSync(summary, 'utf8').includes(integrity('boxlite-ai-boxlite-1.2.3.tgz')))+ existing('boxlite', null)+ assert.equal(publish().status, 0)+ assert.match(readFileSync(summary, 'utf8'), /could not compare/i)+ assert.equal(readFileSync(record, 'utf8'), '')})-test('PyPI publication rejects conflicting wheels before the upload action can run', (t) => {- const dir = mkdtempSync(join(tmpdir(), 'pypi-preflight-'))+function mockRegistry(dir) {+ writeFileSync(join(dir, 'curl'), [+ '#!/bin/bash', 'set -eu',+ 'while [[ "$1" == --* ]]; do',+ ' case "$1" in --output) out=$2; shift 2 ;; --max-time|--retry|--user-agent|--write-out) shift 2 ;; *) shift ;; esac',+ 'done',+ '[[ "$1" == "$EXPECTED_URL" ]]',+ 'cat "$RUNNER_TEMP/response" > "$out"',+ 'printf %s "$HTTP"',+ ].join('\n'), { mode: 0o755 })+}++test('PyPI selects missing wheel filenames and reports only differing or unavailable checksums', t => {+ const dir = mkdtempSync(join(tmpdir(), 'boxlite-pypi-'))t.after(() => rmSync(dir, { recursive: true, force: true }))const steps = release.jobs.pypi.steps- const source = join(dir, 'source'),- filename = 'boxlite-1.2.3-py3-none-any.whl'- mkdirSync(source)- writeFileSync(join(source, filename), 'accepted')- writeFileSync(- join(dir, 'curl'),- '#!/bin/bash\nset -eu\nwhile [[ $# -gt 0 ]]; do if [[ "$1" == "-o" ]]; then cp "$DATA" "$2"; shift; fi; shift; done\nprintf %s "$STATUS"\n',- { mode: 0o755 },- )- const env = {- ...process.env,- PATH: dir + ':' + process.env.PATH,- TAG: 'v1.2.3',- RELEASE_ASSET_DIR: source,- DATA: join(dir, 'pypi-response'),- }- const select = steps.findIndex((step) => step.name === 'Select accepted wheels')- const upload = steps.findIndex((step) => step.uses?.startsWith('pypa/'))- const repo = new URL('../../../', import.meta.url).pathname.replace(/\/$/, '')- const before = steps- .slice(select, upload)- .map((step) => step.run)- .join('\n')- .replaceAll('scripts/release/', repo + '/scripts/release/')- const after = steps[upload + 1].run.replaceAll('scripts/release/', repo + '/scripts/release/')- function check(script, status, sha) {- writeFileSync(env.DATA, JSON.stringify({ urls: sha ? [{ filename, digests: { sha256: sha } }] : [] }))- return spawnSync('bash', ['-ec', script], { cwd: dir, env: { ...env, STATUS: status }, encoding: 'utf8' }).status- }- const hash = execFileSync('shasum', ['-a', '256', join(source, filename)], { encoding: 'utf8' }).split(' ')[0]- for (const [status, sha, allowed, complete] of [- ['200', '0'.repeat(64), false, false],- ['200', hash, true, true],- ['404', '', true, false],- ['500', '', false, false],- ['200', '', true, false],- ]) {+ const select = steps.find(step => step.name === 'Select accepted wheels')+ const upload = steps.at(-1)+ assert.equal(upload.uses, 'pypa/gh-action-pypi-publish@release/v1')+ assert.equal(upload.with['skip-existing'], true)+ const names = ['a.whl', 'b.whl', 'c.whl', 'd.whl']+ for (const name of names) writeFileSync(join(dir, name), name)+ const summary = join(dir, 'summary')+ writeFileSync(summary, '')+ const sum = text => createHash('sha256').update(text).digest('hex')+ const urls = names.slice(0, 3).map((filename, i) => ({ filename, digests: { sha256: [sum(filename), sum('other'), null][i] } }))+ mockRegistry(dir)+ const run = (http, files) => {rmSync(join(dir, 'dist'), { recursive: true, force: true })- assert.equal(check(before, status, sha) === 0, allowed, 'before publisher ' + status + ' ' + sha)- assert.equal(check(after, status, sha) === 0, complete, 'after publisher ' + status + ' ' + sha)+ writeFileSync(join(dir, 'response'), JSON.stringify({ urls: files }))+ return spawnSync('bash', ['-ec', select.run], { cwd: dir, encoding: 'utf8',+ env: { ...process.env, PATH: dir + ':' + process.env.PATH, GITHUB_WORKSPACE: workspace, RUNNER_TEMP: dir, RELEASE_ASSET_DIR: dir,+ GITHUB_OUTPUT: join(dir, 'output'), GITHUB_STEP_SUMMARY: summary, TAG: 'v1.2.3', HTTP: http, EXPECTED_URL: 'https://pypi.org/pypi/boxlite/1.2.3/json' } })}+ const mixed = run('200', urls)+ assert.equal(mixed.status, 0, mixed.stderr)+ assert.deepEqual(readdirSync(join(dir, 'dist')), ['d.whl'])+ assert.match(readFileSync(summary, 'utf8'), /b\.whl/)+ assert.match(readFileSync(summary, 'utf8'), /c\.whl.*could not compare/i)+ assert.doesNotMatch(readFileSync(summary, 'utf8'), /a\.whl/)+ assert.equal(run('404', []).status, 0)+ assert.deepEqual(readdirSync(join(dir, 'dist')).sort(), names)+ assert.equal(run('200', [...urls, { filename: 'd.whl', digests: { sha256: sum('d.whl') } }]).status, 0)+ assert.match(readFileSync(join(dir, 'output'), 'utf8').trim(), /has_missing=false$/)+ assert.match(upload.if, /steps\.wheels\.outputs\.has_missing == 'true'/)+ assert.notEqual(run('503', []).status, 0, 'unavailable inventory is not an empty inventory')})test('build-only never enters deployment, checks, or reporting; failed E2E cannot stamp acceptance', () => {@@ -551,6 +569,45 @@ test('completed builds unlock dev and dev acceptance independently unlocks prodassert.ok(jobs.publish_crates.needs.includes('finalize'))})+test('crates.io publishes missing crates and only reports differences or unavailable comparisons for existing versions', t => {+ const dir = mkdtempSync(join(tmpdir(), 'boxlite-crates-publish-'))+ t.after(() => rmSync(dir, { recursive: true, force: true }))+ const summary = join(dir, 'summary')+ writeFileSync(summary, '')+ mockRegistry(dir)+ writeFileSync(join(dir, 'cargo'), [+ '#!/bin/bash', 'set -eu', 'echo "$1" >> "$RUNNER_TEMP/calls"',+ 'if [[ "$1" == package ]]; then',+ ' [[ "$PACK" == ok ]] || exit 3',+ ' mkdir -p "$CARGO_TARGET_DIR/package"',+ ' printf bytes > "$CARGO_TARGET_DIR/package/$3-1.2.3.crate"',+ 'elif [[ "$PUSH" == duplicate ]]; then echo "error: crate [email protected] already exists on crates.io index" >&2; exit 101',+ 'else exit "$PUSH"; fi',+ ].join('\n'), { mode: 0o755 })+ const tier = release.jobs.publish_crates.steps.find(step => step.name === 'Publish boxlite (Tier 2)')+ symlinkSync(workspace, join(dir, '.release-ci'), 'dir')+ const digest = bytes => createHash('sha256').update(bytes).digest('hex')+ function run(http, checksum, { pack = 'ok', push = '0' } = {}) {+ writeFileSync(join(dir, 'calls'), '')+ writeFileSync(join(dir, 'response'), JSON.stringify({ version: { checksum } }))+ const result = spawnSync('bash', ['-ec', tier.run], { cwd: dir, encoding: 'utf8',+ env: { ...process.env, PATH: dir + ':' + process.env.PATH, RELEASE_TAG: 'v1.2.3', RUNNER_TEMP: dir, GITHUB_WORKSPACE: dir,+ GITHUB_STEP_SUMMARY: summary, HTTP: http, EXPECTED_URL: 'https://crates.io/api/v1/crates/boxlite/1.2.3', PACK: pack, PUSH: push } })+ return { status: result.status, calls: readFileSync(join(dir, 'calls'), 'utf8').trim(), stderr: result.stderr }+ }+ assert.equal(run('200', digest('bytes')).calls, 'package')+ assert.equal(readFileSync(summary, 'utf8'), '')+ assert.equal(run('200', digest('different')).status, 0)+ assert.ok(readFileSync(summary, 'utf8').includes(digest('different')))+ assert.ok(readFileSync(summary, 'utf8').includes(digest('bytes')))+ assert.equal(run('200', digest('bytes'), { pack: 'fail' }).status, 0)+ assert.match(readFileSync(summary, 'utf8'), /could not compare/i)+ assert.equal(run('404', null).calls, 'publish')+ assert.notEqual(run('404', null, { push: '7' }).status, 0)+ assert.equal(run('404', null, { push: 'duplicate' }).status, 0)+ assert.notEqual(run('503', null).status, 0)+})+test('Go tag stays unpublished until every C SDK can be downloaded anonymously for this public release', (t) => {const dir = mkdtempSync(join(tmpdir(), 'go-public-c-'))t.after(() => rmSync(dir, { recursive: true, force: true }))@@ -564,6 +621,9 @@ test('Go tag stays unpublished until every C SDK can be downloaded anonymously fconst sha = git('rev-parse', 'HEAD')git('remote', 'add', 'origin', join(dir, 'origin.git'))git('push', 'origin', sha + ':refs/tags/' + tag)+ git('-c', 'user.name=Fixture', '-c', '[email protected]', '-c', 'commit.gpgSign=false', 'commit', '--allow-empty', '-m', 'different')+ const other = git('rev-parse', 'HEAD')+ git('push', 'origin', other + ':refs/heads/other')for (const path of ['apps/infra/scripts/release-candidate.mjs', '.github/ci-config.json']) {mkdirSync(dirname(join(dir, path)), { recursive: true })copyFileSync(new URL(path, root), join(dir, path))@@ -583,11 +643,17 @@ test('Go tag stays unpublished until every C SDK can be downloaded anonymously f'esac',].join('\n'), { mode: 0o755 })writeFileSync(join(dir, 'public-fetch.mjs'), `+ import { execFileSync } from 'node:child_process'globalThis.fetch = async (url, options) => {const request = new Request(url, options)const base = 'https://github.com/boxlite-ai/boxlite/releases/download/v1.2.3/'if (!request.url.startsWith(base) || request.method !== 'GET' || request.headers.has('authorization')) throw Error('unexpected request')const name = request.url.slice(base.length)+ if (process.env.MOVE_PRODUCT_TAG && name === process.env.LAST_ARCHIVE) {+ const ref = 'refs/tags/' + process.env.RELEASE_TAG+ const update = process.env.MOVE_PRODUCT_TAG === 'delete' ? ['-d', ref] : [ref, process.env.MOVE_PRODUCT_TAG]+ execFileSync('git', ['--git-dir=origin.git', 'update-ref', ...update])+ }if (name === process.env.UNAVAILABLE) return new Response(null, { status: 404 })return new Response(name === process.env.CORRUPT ? 'wrong bytes' : name)}@@ -598,7 +664,7 @@ test('Go tag stays unpublished until every C SDK can be downloaded anonymously fwriteFileSync(join(dir, 'assets.json'), JSON.stringify([files]))return spawnSync('bash', ['-ec', steps.join('\n')], { cwd: dir, encoding: 'utf8',env: { ...process.env, FIXTURE: dir, PATH: dir + ':' + process.env.PATH, GITHUB_REPOSITORY: 'boxlite-ai/boxlite',- TAG: tag, RELEASE_TAG: tag, RELEASE_ID: '123', C_SHA: sha, NODE_OPTIONS: '--import=' + join(dir, 'public-fetch.mjs'), ...extra },+ GITHUB_STEP_SUMMARY: join(dir, 'summary'), TAG: tag, RELEASE_TAG: tag, RELEASE_ID: '123', C_SHA: sha, NODE_OPTIONS: '--import=' + join(dir, 'public-fetch.mjs'), ...extra },})}for (const [reason, options] of [@@ -609,11 +675,24 @@ test('Go tag stays unpublished until every C SDK can be downloaded anonymously fassert.equal(git('ls-remote', '--refs', 'origin', goRef), '', 'Go tag was pushed for ' + reason)assert.notEqual(result.status, 0, reason)}+ for (const target of [other, 'delete']) {+ const result = publish({ MOVE_PRODUCT_TAG: target, LAST_ARCHIVE: assets.at(-1).name })+ assert.equal(git('ls-remote', '--refs', 'origin', 'refs/tags/' + tag).split('\t')[0], target === 'delete' ? '' : other)+ assert.equal(git('ls-remote', '--refs', 'origin', goRef), '', 'a product tag changed during download must block the Go tag')+ assert.notEqual(result.status, 0)+ git('push', '--force', 'origin', sha + ':refs/tags/' + tag)+ }for (let attempt = 0; attempt < 2; attempt++) {- const result = publish()+ const result = publish(attempt === 0 ? {} : { UNAVAILABLE: assets[0].name })assert.equal(result.status, 0, result.stderr)assert.equal(git('ls-remote', '--refs', 'origin', goRef), sha + '\t' + goRef)}+ git('push', '--force', 'origin', other + ':' + goRef)+ const skipped = publish()+ assert.equal(skipped.status, 0, skipped.stderr)+ assert.ok(readFileSync(join(dir, 'summary'), 'utf8').includes(other))+ assert.ok(readFileSync(join(dir, 'summary'), 'utf8').includes(sha))+ assert.equal(git('ls-remote', '--refs', 'origin', goRef), other + '\t' + goRef)})test('publication gates accept a skipped optional ancestor and require successful direct prerequisites', () => {diff --git a/scripts/release/external-publication.sh b/scripts/release/external-publication.shnew file mode 100644index 000000000..c343603e2--- /dev/null+++ b/scripts/release/external-publication.sh@@ -0,0 +1,97 @@+#!/usr/bin/env bash+set -euo pipefail++# Only confirmed absence permits an upload. Checksums are advisory once a file exists.+registry_status() {+ curl --silent --show-error --location --retry 2 --max-time 30 \+ --user-agent 'boxlite-release (https://github.com/boxlite-ai/boxlite)' \+ --output "$2" --write-out '%{http_code}' "$1"+}++# Markdown code spans in these printf formats use literal backticks.+# shellcheck disable=SC2016+compare_existing() {+ local label=$1 local_digest=$2 remote_digest=$3+ if [[ -z "$local_digest" || -z "$remote_digest" ]]; then+ printf -- '- Skipped `%s` (already published); could not compare checksums.\n' "$label" >> "$GITHUB_STEP_SUMMARY"+ elif [[ "$local_digest" != "$remote_digest" ]]; then+ printf -- '- Skipped `%s` (different bytes). Local `%s`, registry `%s`.\n' \+ "$label" "$local_digest" "$remote_digest" >> "$GITHUB_STEP_SUMMARY"+ fi+}++compare_npm_tarball() {+ local file=$1 package=$2 metadata=$3 remote='' local_digest=''+ remote=$(jq -er '."dist.integrity" | strings | select(test("^sha512-[A-Za-z0-9+/]{86}==$"))' "$metadata") || remote=''+ if [[ -n "$remote" ]] && local_digest=$(openssl dgst -sha512 -binary "$file" | openssl base64 -A); then+ local_digest="sha512-$local_digest"+ else+ local_digest=''+ fi+ compare_existing "$package" "$local_digest" "$remote"+}++select_wheels() {+ local metadata="$RUNNER_TEMP/pypi-version.json" file name remote local_digest status has_missing=false+ status=$(registry_status "https://pypi.org/pypi/boxlite/${TAG#v}/json" "$metadata")+ case "$status" in+ 200) jq -e '.urls | arrays | all(.[]; (.filename | type) == "string" and (.filename | length) > 0)' "$metadata" >/dev/null ;;+ 404) printf '{"urls":[]}\n' > "$metadata" ;;+ *) echo "PyPI version lookup returned HTTP $status" >&2; return 1 ;;+ esac+ mkdir dist+ for file in "$RELEASE_ASSET_DIR"/*.whl; do+ name=${file##*/}+ if jq -e --arg file "$name" 'any(.urls[]; .filename == $file)' "$metadata" >/dev/null; then+ remote=$(jq -er --arg file "$name" '.urls[] | select(.filename == $file) | .digests.sha256 | strings | select(test("^[a-f0-9]{64}$"))' "$metadata") || remote=''+ local_digest=$(sha256sum < "$file" | cut -d' ' -f1) || local_digest=''+ compare_existing "$name" "$local_digest" "$remote"+ else+ cp -- "$file" dist/+ has_missing=true+ fi+ done+ echo "has_missing=$has_missing" >> "$GITHUB_OUTPUT"+}++compare_crate() {+ local crate=$1 version=$2 metadata=$3 remote='' local_digest=''+ remote=$(jq -er '.version.checksum | strings | select(test("^[a-f0-9]{64}$"))' "$metadata") || remote=''+ local target="$RUNNER_TEMP/crate-comparison"+ if [[ -n "$remote" ]] && CARGO_TARGET_DIR="$target" cargo package -p "$crate" --no-verify; then+ local_digest=$(sha256sum < "$target/package/$crate-$version.crate" | cut -d' ' -f1) || local_digest=''+ fi+ compare_existing "$crate@$version" "$local_digest" "$remote"+}++publish_crate() {+ local crate=$1 version=${RELEASE_TAG#v}+ shift+ local url="https://crates.io/api/v1/crates/$crate/$version" metadata="$RUNNER_TEMP/crate-version.json"+ local status log="$RUNNER_TEMP/publish-$crate.log"+ status=$(registry_status "$url" "$metadata")+ case "$status" in+ 200) compare_crate "$crate" "$version" "$metadata"; return ;;+ 404) ;;+ *) echo "crates.io lookup for $crate@$version returned HTTP $status" >&2; return 1 ;;+ esac+ if cargo publish -p "$crate" "$@" 2>&1 | tee "$log"; then+ return+ fi+ if grep -Fq 'already uploaded' "$log" || grep -Fq "crate $crate@$version already exists on " "$log"; then+ if [[ "$(registry_status "$url" "$metadata")" == 200 ]]; then+ compare_crate "$crate" "$version" "$metadata"+ else+ compare_existing "$crate@$version" '' ''+ fi+ return+ fi+ return 1+}++case "$1" in+ npm) shift; compare_npm_tarball "$@" ;;+ wheels) select_wheels ;;+ crate) shift; publish_crate "$@" ;;+ *) exit 2 ;;+esacdiff --git a/scripts/release/verify-pypi-wheels.sh b/scripts/release/verify-pypi-wheels.shdeleted file mode 100644index 2c4350ecd..000000000--- a/scripts/release/verify-pypi-wheels.sh+++ /dev/null@@ -1,19 +0,0 @@-#!/usr/bin/env bash-# SPDX-License-Identifier: AGPL-3.0-only-set -euo pipefail-mode=${1:?expected before or after}-[[ "$mode" == before || "$mode" == after ]]-[[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]-index=$(mktemp)-trap 'rm -f "$index"' EXIT-status=$(curl -sS --retry 5 --retry-all-errors -o "$index" -w '%{http_code}' "https://pypi.org/pypi/boxlite/${TAG#v}/json")-if [[ "$status" == 404 && "$mode" == before ]]; then exit 0; fi-[[ "$status" == 200 ]] || { echo "PyPI lookup for $TAG returned HTTP $status" >&2; exit 1; }-jq -e '.urls | type == "array"' "$index" >/dev/null-for wheel in dist/*.whl; do- sha=$(sha256sum "$wheel" | cut -d' ' -f1)- jq -e --arg name "${wheel##*/}" --arg sha "$sha" --arg mode "$mode" '- [.urls[] | select(.filename == $name)] |- if length == 0 then $mode == "before" else all(.[]; .digests.sha256 == $sha) end' "$index" >/dev/null ||- { echo "PyPI has a missing or conflicting accepted wheel: ${wheel##*/}" >&2; exit 1; }-done