Merge pull request #8383 from deepseek-harness/release-0.2.2-ci-bubblewrap-cache
fix(ci): cache the verified bubblewrap archive and bound its download (backport #8325 to 0.2.2)
This commit is contained in:
commit
bbad94f927
8 files changed
+450
-4
No files matched your search
@@ -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: |
|
||||
|
||||
@@ -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/[email protected]
|
||||
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/[email protected]
|
||||
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/[email protected]
|
||||
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/[email protected]
|
||||
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/[email protected]
|
||||
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/[email protected]
|
||||
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
|
||||
|
||||
@@ -79,12 +79,29 @@ jobs:
|
||||
- name: Install (immutable)
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Restore verified bubblewrap archive
|
||||
id: bubblewrap-cache
|
||||
uses: actions/cache/[email protected]
|
||||
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/[email protected]
|
||||
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
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
# shellcheck shell=bash
|
||||
# Sourced by CI preparation scripts; defines functions only.
|
||||
|
||||
# Prints the SHA-256 digest of <file>.
|
||||
#
|
||||
# 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 <file> has the SHA-256 digest <sha256>. Returns 2, reporting the
|
||||
# missing tool on stderr, when neither digest tool exists.
|
||||
#
|
||||
# Usage: verified_sha256 <sha256> <file>
|
||||
verified_sha256() {
|
||||
local actual status=0
|
||||
actual="$(sha256_digest "$2")" || status=$?
|
||||
if (( status != 0 )); then
|
||||
return "$status"
|
||||
fi
|
||||
[[ "$actual" == "$1" ]]
|
||||
}
|
||||
|
||||
# Leaves a copy of <url> whose SHA-256 digest is <sha256> at <cache-file>.
|
||||
#
|
||||
# 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 <cache-file> atomically, so the cache only ever holds a verified
|
||||
# payload. A failed download or verification leaves nothing at <cache-file> 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 <url> <sha256> <cache-file>
|
||||
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
|
||||
}
|
||||
@@ -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([])
|
||||
})
|
||||
})
|
||||
@@ -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<string, string | undefined>([
|
||||
['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/[email protected]',
|
||||
with: cache,
|
||||
})
|
||||
expect(steps[preparation + 1]).toEqual({
|
||||
name: 'Save verified bubblewrap archive',
|
||||
if: guard === undefined ? cacheHit : `(${guard}) && ${cacheHit}`,
|
||||
uses: 'actions/cache/[email protected]',
|
||||
with: cache,
|
||||
})
|
||||
}
|
||||
expect(preparations).toBeGreaterThan(0)
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
describe('DeepSeek e2e workflow', () => {
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user