From 68f83cc9926892010f439383b469657c6f1f6510 Mon Sep 17 00:00:00 2001 From: Chinesezjc Date: Thu, 12 Nov 2026 02:19:56 +0800 Subject: [PATCH] fix(ci): cache the verified bubblewrap archive and bound its download Backport of #8325 to release/dsh-0.2.2. (cherry picked from commit 907c47c8f251cae6ce844cf8c7145bbfd5dbe176) --- .github/workflows/ci-master.yml | 3 + .github/workflows/ci.yml | 54 +++++++ .github/workflows/e2e.yml | 17 +++ scripts/ci-compatible-selfhosted.spec.ts | 6 +- scripts/ci-verified-download.sh | 105 +++++++++++++ scripts/ci-verified-download.spec.ts | 187 +++++++++++++++++++++++ scripts/ci-workflow.spec.ts | 70 +++++++++ scripts/prepare-ci-bubblewrap.sh | 12 +- 8 files changed, 450 insertions(+), 4 deletions(-) create mode 100644 scripts/ci-verified-download.sh create mode 100644 scripts/ci-verified-download.spec.ts diff --git a/.github/workflows/ci-master.yml b/.github/workflows/ci-master.yml index d69a860098..de2ac59ae9 100644 --- a/.github/workflows/ci-master.yml +++ b/.github/workflows/ci-master.yml @@ -495,6 +495,9 @@ jobs: console.log(JSON.stringify({ arch: process.arch, cpus: os.cpus().length, memoryGiB: Math.round(os.totalmem() / 2 ** 30) }))" + # No archive cache: this manual matrix includes the persistent 64/96-core + # fleet rows, and a `~` cache written by an ephemeral runner does not + # restore into the preparation directory there. - name: Install and prepare Linux if: matrix.platform == 'linux' run: | diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 916971cfa4..01ec607012 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -179,6 +179,16 @@ jobs: restore-keys: | ${{ runner.os }}-node-${{ env.PRIMARY_NODE_VERSION }}-pnpm- + # The persistent self-hosted pool keeps ~/.cache between jobs on its own + # layout, so the archive cache follows the hosted-only pnpm store guard. + - name: Restore verified bubblewrap archive + id: bubblewrap-cache + if: vars.DSH_CI_FAILOVER_LINUX != 'selfhosted' || github.event.pull_request.user.login == 'dependabot[bot]' + uses: actions/cache/restore@v6.1.0 + with: + path: ~/.cache/dsh-ci/bubblewrap + key: bubblewrap-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('scripts/prepare-ci-bubblewrap.sh') }} + - name: Install dependencies and prepare bubblewrap run: | pnpm install --frozen-lockfile & @@ -192,6 +202,16 @@ jobs: if (( install_status != 0 )); then exit "$install_status"; fi exit "$sandbox_status" + # The save step is skipped on a hit. A restored archive whose digest fails + # is re-downloaded but not re-saved (the key already exists), so a tampered + # entry survives until eviction; that needs deliberate cache poisoning. + - name: Save verified bubblewrap archive + if: (vars.DSH_CI_FAILOVER_LINUX != 'selfhosted' || github.event.pull_request.user.login == 'dependabot[bot]') && steps.bubblewrap-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v6.1.0 + with: + path: ~/.cache/dsh-ci/bubblewrap + key: bubblewrap-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('scripts/prepare-ci-bubblewrap.sh') }} + - name: Run exhaustive coverage run: pnpm run check:ci:coverage @@ -406,6 +426,16 @@ jobs: restore-keys: | ${{ runner.os }}-playwright- + # The persistent self-hosted pool keeps ~/.cache between jobs on its own + # layout, so the archive cache follows the hosted-only pnpm store guard. + - name: Restore verified bubblewrap archive + id: bubblewrap-cache + if: vars.DSH_CI_FAILOVER_LINUX != 'selfhosted' || github.event.pull_request.user.login == 'dependabot[bot]' + uses: actions/cache/restore@v6.1.0 + with: + path: ~/.cache/dsh-ci/bubblewrap + key: bubblewrap-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('scripts/prepare-ci-bubblewrap.sh') }} + - name: Install dependencies and prepare bubblewrap run: | pnpm install --frozen-lockfile & @@ -419,6 +449,13 @@ jobs: if (( install_status != 0 )); then exit "$install_status"; fi exit "$sandbox_status" + - name: Save verified bubblewrap archive + if: (vars.DSH_CI_FAILOVER_LINUX != 'selfhosted' || github.event.pull_request.user.login == 'dependabot[bot]') && steps.bubblewrap-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v6.1.0 + with: + path: ~/.cache/dsh-ci/bubblewrap + key: bubblewrap-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('scripts/prepare-ci-bubblewrap.sh') }} + # Blacksmith's Ubuntu HTTP archive endpoints can be unreachable while HTTPS works. - name: Use HTTPS for Ubuntu archives on Blacksmith if: vars.DSH_CI_FAILOVER_LINUX == 'blacksmith' @@ -532,9 +569,26 @@ jobs: - name: Install (immutable) run: pnpm install --frozen-lockfile + # The persistent self-hosted pool keeps ~/.cache between jobs on its own + # layout, so the archive cache follows the hosted-only pnpm store guard. + - name: Restore verified bubblewrap archive + id: bubblewrap-cache + if: vars.DSH_CI_FAILOVER_LINUX != 'selfhosted' || github.event.pull_request.user.login == 'dependabot[bot]' + uses: actions/cache/restore@v6.1.0 + with: + path: ~/.cache/dsh-ci/bubblewrap + key: bubblewrap-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('scripts/prepare-ci-bubblewrap.sh') }} + - name: Prepare bubblewrap (unrestrict userns) run: bash scripts/prepare-ci-bubblewrap.sh + - name: Save verified bubblewrap archive + if: (vars.DSH_CI_FAILOVER_LINUX != 'selfhosted' || github.event.pull_request.user.login == 'dependabot[bot]') && steps.bubblewrap-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v6.1.0 + with: + path: ~/.cache/dsh-ci/bubblewrap + key: bubblewrap-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('scripts/prepare-ci-bubblewrap.sh') }} + - name: Run compatibility smokes env: DSH_BUILD_CLIENT_PROFILE: official diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 32df0173e9..474ec71c21 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -79,12 +79,29 @@ jobs: - name: Install (immutable) run: pnpm install --frozen-lockfile + - name: Restore verified bubblewrap archive + id: bubblewrap-cache + uses: actions/cache/restore@v6.1.0 + with: + path: ~/.cache/dsh-ci/bubblewrap + key: bubblewrap-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('scripts/prepare-ci-bubblewrap.sh') }} + # The with-key escalation e2e self-skips without a usable runner. Prepare # bwrap so trusted CI exercises it; the functional probe remains the # authority on whether the runner can use the sandbox. - name: Prepare bubblewrap (unrestrict userns) run: bash scripts/prepare-ci-bubblewrap.sh + # A restored archive whose digest fails is re-downloaded but not re-saved + # (the hit key already exists), so a tampered entry survives until + # eviction; that needs deliberate cache poisoning. + - name: Save verified bubblewrap archive + if: steps.bubblewrap-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v6.1.0 + with: + path: ~/.cache/dsh-ci/bubblewrap + key: bubblewrap-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('scripts/prepare-ci-bubblewrap.sh') }} + # Guard against a false green: the e2e suites self-skip when the key is # absent, so a missing/misconfigured secret would otherwise pass as # "all skipped". This job only runs on trusted events (the `if:` above diff --git a/scripts/ci-compatible-selfhosted.spec.ts b/scripts/ci-compatible-selfhosted.spec.ts index e968645123..5d12db93d3 100644 --- a/scripts/ci-compatible-selfhosted.spec.ts +++ b/scripts/ci-compatible-selfhosted.spec.ts @@ -108,7 +108,11 @@ describe('Node compatibility self-hosted routing', () => { ) } expect(job.steps[0]?.with).toEqual({ 'persist-credentials': false }) - expect(job.steps.some(step => step.uses?.startsWith('actions/cache/'))).toBe(false) + // The verified bubblewrap archive is the one remote cache this job restores + // and saves; it must stay excluded from the persistent self-hosted pool. + const remoteCaches = job.steps.filter(step => step.uses?.startsWith('actions/cache/')) + expect(remoteCaches.length).toBeGreaterThan(0) + for (const step of remoteCaches) expect(step.if).toContain("vars.DSH_CI_FAILOVER_LINUX != 'selfhosted'") }) it('overrides runner exports inside setup-node without affecting later Node processes', () => { diff --git a/scripts/ci-verified-download.sh b/scripts/ci-verified-download.sh new file mode 100644 index 0000000000..94837897bc --- /dev/null +++ b/scripts/ci-verified-download.sh @@ -0,0 +1,105 @@ +# shellcheck shell=bash +# Sourced by CI preparation scripts; defines functions only. + +# Prints the SHA-256 digest of . +# +# CI runners do not all provide the same tool: GNU coreutils ships `sha256sum`, +# while macOS ships `shasum -a 256`. Probing both keeps a missing tool from +# being reported as a digest mismatch, which would discard a verified cached +# archive and send the next run back to a possibly unavailable download host. +sha256_digest() { + local output + if command -v sha256sum >/dev/null 2>&1; then + output="$(sha256sum < "$1")" + elif command -v shasum >/dev/null 2>&1; then + output="$(shasum -a 256 < "$1")" + else + echo 'No SHA-256 tool found: need sha256sum or shasum -a 256' >&2 + return 2 + fi + printf '%s\n' "${output%% *}" +} + +# Succeeds when has the SHA-256 digest . Returns 2, reporting the +# missing tool on stderr, when neither digest tool exists. +# +# Usage: verified_sha256 +verified_sha256() { + local actual status=0 + actual="$(sha256_digest "$2")" || status=$? + if (( status != 0 )); then + return "$status" + fi + [[ "$actual" == "$1" ]] +} + +# Leaves a copy of whose SHA-256 digest is at . +# +# A cached file with the expected digest is used without network access, so a +# restored Actions cache keeps CI independent of the download host. A cached +# file with any other digest is discarded. A download is verified before it +# replaces atomically, so the cache only ever holds a verified +# payload. A failed download or verification leaves nothing at and +# reports the URL on stderr. A missing SHA-256 tool returns 2 instead of +# treating the payload as mismatched. Each attempt is bounded so a stalled host +# fails within minutes. +# +# Usage: acquire_verified_archive +acquire_verified_archive() { + local url="$1" sha256="$2" cache_file="$3" cache_dir + cache_dir="$(dirname -- "$cache_file")" + + # Probe before the network work: a runner without a digest tool must fail + # immediately instead of downloading a payload it cannot verify. + sha256_digest /dev/null >/dev/null + + if [[ -f "$cache_file" ]]; then + local cache_status=0 + verified_sha256 "$sha256" "$cache_file" || cache_status=$? + if (( cache_status == 0 )); then + echo "Using verified cached archive $cache_file" + return 0 + fi + if (( cache_status != 1 )); then + return "$cache_status" + fi + echo "Discarding cached archive $cache_file: SHA-256 mismatch" >&2 + rm -f -- "$cache_file" + fi + + if ! mkdir -p -- "$cache_dir"; then + echo "Failed to create $cache_dir while preparing $url" >&2 + return 1 + fi + local partial + if ! partial="$(mktemp "${cache_file}.partial.XXXXXX")"; then + echo "Failed to create a temporary file in $cache_dir while preparing $url" >&2 + return 1 + fi + # A cancelled job must not leave a partial payload in the directory that + # actions/cache/save uploads. + trap 'rm -f -- "$partial"' EXIT + + if ! curl --fail --silent --show-error --location \ + --connect-timeout 15 --max-time 60 \ + --retry 8 --retry-all-errors --retry-max-time 240 \ + --output "$partial" "$url"; then + rm -f -- "$partial" + trap - EXIT + echo "Failed to download $url and no verified cached copy exists at $cache_file" >&2 + return 1 + fi + local download_status=0 + verified_sha256 "$sha256" "$partial" || download_status=$? + if (( download_status != 0 )); then + rm -f -- "$partial" + trap - EXIT + if (( download_status != 1 )); then + return "$download_status" + fi + echo "Downloaded $url does not have SHA-256 $sha256" >&2 + return 1 + fi + mv -f -- "$partial" "$cache_file" + trap - EXIT +} diff --git a/scripts/ci-verified-download.spec.ts b/scripts/ci-verified-download.spec.ts new file mode 100644 index 0000000000..493a4a0d7d --- /dev/null +++ b/scripts/ci-verified-download.spec.ts @@ -0,0 +1,187 @@ +import { spawnSync } from 'node:child_process' +import { createHash } from 'node:crypto' +import { + chmodSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, symlinkSync, writeFileSync, +} from 'node:fs' +import { tmpdir } from 'node:os' +import { delimiter, join, resolve } from 'node:path' +import { afterEach, describe, expect, it } from 'vitest' + +const library = resolve(import.meta.dirname, 'ci-verified-download.sh') +const url = 'https://downloads.invalid/payload.deb' +const payload = Buffer.from('verified payload\n') +const payloadSha256 = createHash('sha256').update(payload).digest('hex') +const bash = ['/bin/bash', '/usr/bin/bash'].find(candidate => existsSync(candidate)) ?? 'bash' + +// Records each invocation, then copies FAKE_CURL_SOURCE to the --output path +// or fails as curl does for an HTTP error when no source is configured. +const fakeCurl = `#!/usr/bin/env bash +printf '%s\\n' "$*" >> "$FAKE_CURL_LOG" +output='' +while (( $# > 0 )); do + if [[ "$1" == --output ]]; then output="$2"; shift; fi + shift +done +if [[ -z "\${FAKE_CURL_SOURCE:-}" ]]; then + echo 'curl: (22) The requested URL returned error: 503' >&2 + exit 22 +fi +cp "$FAKE_CURL_SOURCE" "$output" +` + +interface Fixture { + readonly root: string + readonly cacheDir: string + readonly cacheFile: string + readonly curlLog: string + readonly env: NodeJS.ProcessEnv +} + +const fixtureRoots: string[] = [] + +afterEach(() => { + for (const root of fixtureRoots.splice(0)) rmSync(root, { recursive: true, force: true }) +}) + +function createFixture(served?: Buffer): Fixture { + const root = mkdtempSync(join(tmpdir(), 'dsh-ci-verified-download-')) + fixtureRoots.push(root) + const bin = join(root, 'bin') + mkdirSync(bin) + writeFileSync(join(bin, 'curl'), fakeCurl) + chmodSync(join(bin, 'curl'), 0o755) + const curlLog = join(root, 'curl.log') + writeFileSync(curlLog, '') + const env: NodeJS.ProcessEnv = { ...process.env, PATH: bin + delimiter + (process.env.PATH ?? ''), FAKE_CURL_LOG: curlLog } + delete env.FAKE_CURL_SOURCE + if (served !== undefined) { + const source = join(root, 'served.deb') + writeFileSync(source, served) + env.FAKE_CURL_SOURCE = source + } + const cacheDir = join(root, 'cache', 'bubblewrap') + return { root, cacheDir, cacheFile: join(cacheDir, 'payload.deb'), curlLog, env } +} + +interface AcquireResult { + readonly status: number | null + readonly signal: NodeJS.Signals | null + readonly stderr: string +} + +function acquire(fixture: Fixture, env: NodeJS.ProcessEnv = fixture.env): AcquireResult { + const result = spawnSync( + bash, + ['-c', 'set -euo pipefail; source "$1"; acquire_verified_archive "$2" "$3" "$4"', 'acquire', library, url, payloadSha256, fixture.cacheFile], + { encoding: 'utf8', env, timeout: 30_000 }, + ) + return { status: result.status, signal: result.signal, stderr: result.stderr } +} + +function curlCalls(fixture: Fixture): string[] { + return readFileSync(fixture.curlLog, 'utf8').split('\n').filter(line => line !== '') +} + +function seedCache(fixture: Fixture, content: Buffer): void { + mkdirSync(fixture.cacheDir, { recursive: true }) + writeFileSync(fixture.cacheFile, content) +} + +// Builds a PATH that reaches only the named executables plus the fixture's fake +// curl, so a child can run on a host that provides a SHA-256 tool but see none. +function restrictedPath(fixture: Fixture, names: readonly string[]): string { + const bin = join(fixture.root, 'restricted-bin') + mkdirSync(bin, { recursive: true }) + for (const name of names) { + const resolved = spawnSync('sh', ['-c', `command -v ${name}`], { encoding: 'utf8' }).stdout.trim() + if (resolved === '') throw new Error(`the test host does not provide ${name}`) + symlinkSync(resolved, join(bin, name)) + } + return [bin, join(fixture.root, 'bin')].join(delimiter) +} + +function hasDigestTool(): boolean { + return spawnSync('sh', ['-c', 'command -v sha256sum || command -v shasum'], { stdio: 'ignore' }).status === 0 +} + +// The library targets Linux CI runners; the suite needs bash and a SHA-256 tool +// (sha256sum or shasum -a 256) and skips elsewhere. +describe.skipIf(process.platform === 'win32' || !hasDigestTool())('acquire_verified_archive', () => { + it('uses a verified cached archive without contacting the download host', () => { + const fixture = createFixture() + seedCache(fixture, payload) + + const result = acquire(fixture) + + expect(result.signal).toBeNull() + expect(result.status).toBe(0) + expect(curlCalls(fixture)).toEqual([]) + expect(readFileSync(fixture.cacheFile)).toEqual(payload) + }) + + it('fails with the URL when the download fails and no cached archive exists', () => { + const fixture = createFixture() + + const result = acquire(fixture) + + expect(result.signal).toBeNull() + expect(result.status).toBe(1) + expect(result.stderr).toContain(`Failed to download ${url} and no verified cached copy exists at ${fixture.cacheFile}`) + expect(curlCalls(fixture)).toHaveLength(1) + expect(readdirSync(fixture.cacheDir)).toEqual([]) + }) + + it('bounds every download attempt and the retry window', () => { + const fixture = createFixture(payload) + + expect(acquire(fixture).status).toBe(0) + + const [call] = curlCalls(fixture) + expect(call).toContain('--connect-timeout 15 ') + expect(call).toContain('--max-time 60 ') + expect(call).toContain('--retry 8 ') + // The last attempt may still run for its full --max-time, so the bounded + // failure time is this window plus 60 seconds. + expect(call).toContain('--retry-max-time 240 ') + expect(call).toContain(url) + }) + + it('fails immediately and reports the missing tool instead of a digest mismatch', () => { + const fixture = createFixture(payload) + const env = { ...fixture.env, PATH: restrictedPath(fixture, ['bash', 'dirname', 'mkdir', 'mktemp', 'mv', 'rm']) } + + const result = acquire(fixture, env) + + expect(result.signal).toBeNull() + expect(result.status).toBe(2) + expect(result.stderr).toContain('No SHA-256 tool found') + expect(curlCalls(fixture)).toEqual([]) + expect(existsSync(fixture.cacheFile)).toBe(false) + }) + + it('replaces a cached archive whose digest does not match with a verified download', () => { + const fixture = createFixture(payload) + seedCache(fixture, Buffer.from('corrupted payload\n')) + + const result = acquire(fixture) + + expect(result.signal).toBeNull() + expect(result.status).toBe(0) + expect(result.stderr).toContain('SHA-256 mismatch') + expect(curlCalls(fixture)).toHaveLength(1) + expect(readdirSync(fixture.cacheDir)).toEqual(['payload.deb']) + expect(readFileSync(fixture.cacheFile)).toEqual(payload) + }) + + it('rejects a downloaded archive whose digest does not match without caching it', () => { + const fixture = createFixture(Buffer.from('tampered payload\n')) + + const result = acquire(fixture) + + expect(result.signal).toBeNull() + expect(result.status).toBe(1) + expect(result.stderr).toContain(`Downloaded ${url} does not have SHA-256 ${payloadSha256}`) + expect(existsSync(fixture.cacheFile)).toBe(false) + expect(readdirSync(fixture.cacheDir)).toEqual([]) + }) +}) diff --git a/scripts/ci-workflow.spec.ts b/scripts/ci-workflow.spec.ts index ed7a360894..f92873eb19 100644 --- a/scripts/ci-workflow.spec.ts +++ b/scripts/ci-workflow.spec.ts @@ -1112,6 +1112,76 @@ describe('bubblewrap preparation script', () => { // Ubuntu removes superseded versions from its live package pool. expect(script).not.toMatch(/https?:\/\/[^/'"\s]+\/ubuntu(?:-ports)?\/pool\//u) }) + + it('verifies the archive against the pinned digest', () => { + const script = readFileSync(resolve(root, 'scripts/prepare-ci-bubblewrap.sh'), 'utf8') + + expect(script).toMatch(/^readonly BUBBLEWRAP_SHA256='[0-9a-f]{64}'$/mu) + expect(script).toContain('acquire_verified_archive "$BUBBLEWRAP_URL" "$BUBBLEWRAP_SHA256" "$archive"') + }) + + // Ephemeral runners share a `~` layout: GitHub-hosted runners and Blacksmith + // (whose runners register as self-hosted but keep /home/runner as HOME). The + // in-house `vm-backup` pool keeps `~/.cache` on a different, persistent + // layout, so lanes that can select it must not restore or save this cache. + // `ci-master.yml` prepares bubblewrap only on lanes that can select the + // persistent runners, and the manual benchmark matrix includes their 64/96-core + // rows, so neither carries cache steps. + const hostedOnly = "vars.DSH_CI_FAILOVER_LINUX != 'selfhosted' || github.event.pull_request.user.login == 'dependabot[bot]'" + const cachedJobs = new Map([ + ['ci.yml:node-24-coverage', hostedOnly], + ['ci.yml:node-24-consumers', hostedOnly], + ['ci.yml:node-compat', hostedOnly], + ['e2e.yml:e2e', undefined], + ]) + + it.each(['ci.yml', 'ci-master.yml', 'e2e.yml'])( + '%s caches the verified archive only on the lanes that run on ephemeral runners', + (name) => { + const script = readFileSync(resolve(root, 'scripts/prepare-ci-bubblewrap.sh'), 'utf8') + expect(script).toContain('readonly BUBBLEWRAP_CACHE_DIR="${HOME}/.cache/dsh-ci/bubblewrap"') + const cache = { + path: '~/.cache/dsh-ci/bubblewrap', + key: "bubblewrap-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('scripts/prepare-ci-bubblewrap.sh') }}", + } + const workflow = loadWorkflow('.github/workflows/' + name) + if (!isRecord(workflow.jobs)) throw new TypeError(`${name} must define jobs`) + + let preparations = 0 + for (const [jobName, job] of Object.entries(workflow.jobs)) { + if (!isRecord(job) || !Array.isArray(job.steps)) continue + const steps = job.steps.filter(isRecord) + const preparation = steps.findIndex(step => + typeof step.run === 'string' && step.run.includes('bash scripts/prepare-ci-bubblewrap.sh')) + if (preparation < 0) continue + preparations += 1 + const key = `${name}:${jobName}` + if (!cachedJobs.has(key)) { + expect( + steps.filter(step => typeof step.uses === 'string' && step.uses.startsWith('actions/cache/')), + key, + ).toEqual([]) + continue + } + const guard = cachedJobs.get(key) + const cacheHit = "steps.bubblewrap-cache.outputs.cache-hit != 'true'" + expect(steps[preparation - 1]).toEqual({ + name: 'Restore verified bubblewrap archive', + id: 'bubblewrap-cache', + ...(guard === undefined ? {} : { if: guard }), + uses: 'actions/cache/restore@v6.1.0', + with: cache, + }) + expect(steps[preparation + 1]).toEqual({ + name: 'Save verified bubblewrap archive', + if: guard === undefined ? cacheHit : `(${guard}) && ${cacheHit}`, + uses: 'actions/cache/save@v6.1.0', + with: cache, + }) + } + expect(preparations).toBeGreaterThan(0) + }, + ) }) describe('DeepSeek e2e workflow', () => { diff --git a/scripts/prepare-ci-bubblewrap.sh b/scripts/prepare-ci-bubblewrap.sh index 5b19d8ad6f..39c500bb2f 100755 --- a/scripts/prepare-ci-bubblewrap.sh +++ b/scripts/prepare-ci-bubblewrap.sh @@ -9,6 +9,13 @@ readonly BUBBLEWRAP_VERSION='0.12.0-1' readonly BUBBLEWRAP_SHA256='db4d572a7927bfd34cc9b8e24b56983efa8e0483d03da6c810f6caae081dcc36' # The recorded build remains addressable after Ubuntu prunes its live package pool. readonly BUBBLEWRAP_URL="https://launchpad.net/ubuntu/+source/bubblewrap/${BUBBLEWRAP_VERSION}/+build/33546835/+files/bubblewrap_${BUBBLEWRAP_VERSION}_amd64.deb" +# Workflows that run on ephemeral runners restore and save this directory as +# `~/.cache/dsh-ci/bubblewrap` with actions/cache, so a warm cache needs no +# Launchpad request; the persistent self-hosted pool keeps the directory itself. +readonly BUBBLEWRAP_CACHE_DIR="${HOME}/.cache/dsh-ci/bubblewrap" + +# shellcheck source=scripts/ci-verified-download.sh +source "$(dirname -- "${BASH_SOURCE[0]}")/ci-verified-download.sh" : "${RUNNER_TEMP:?prepare-ci-bubblewrap requires RUNNER_TEMP}" : "${GITHUB_PATH:?prepare-ci-bubblewrap requires GITHUB_PATH}" @@ -18,11 +25,10 @@ if [[ "$(uname -s)" != 'Linux' || "$(uname -m)" != 'x86_64' ]]; then exit 1 fi -archive="${RUNNER_TEMP}/bubblewrap_${BUBBLEWRAP_VERSION}_amd64.deb" +archive="${BUBBLEWRAP_CACHE_DIR}/bubblewrap_${BUBBLEWRAP_VERSION}_amd64.deb" root="${RUNNER_TEMP}/dsh-bubblewrap" -curl --fail --silent --show-error --location --retry 3 --retry-all-errors --output "$archive" "$BUBBLEWRAP_URL" -printf '%s %s\n' "$BUBBLEWRAP_SHA256" "$archive" | sha256sum --check --status +acquire_verified_archive "$BUBBLEWRAP_URL" "$BUBBLEWRAP_SHA256" "$archive" mkdir -p "$root" dpkg-deb --extract "$archive" "$root" printf '%s\n' "$root/usr/bin" >> "$GITHUB_PATH"