From 2ec5275db5d8612133f454119e1215bb209047fc Mon Sep 17 00:00:00 2001 From: garrytan Date: Thu, 8 Oct 2026 06:17:04 +0000 Subject: [PATCH] fix(ci): install Bun from the SHA-256-verified release archive in GitLab CI and Ubicloud setup Rewrite of #1713. .gitlab-ci.yml's .setup-bun anchor and scripts/ubicloud/setup-free-suite.sh still piped https://bun.sh/install into bash. Both now download the bun-v$BUN_VERSION linux-x64 release zip, check it against the same SHA-256 Dockerfile.ci uses (#1706) before unzipping, install it to ~/.bun/bin and assert `bun --version`. test/ci-image-cli-pin.test.ts runs curlPipedToShell over both files and binds their hash and BUN_VERSION to Dockerfile.ci's amd64 arm and package.json's engines floor, so a Bun bump has to move all of them together. Verified by running the GitLab anchor in debian:stable-slim (bash and sh) and the Ubicloud block in a temp HOME. Co-authored-by: Zee Zheng <228040220+spacegeologist@users.noreply.github.com> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --- .gitlab-ci.yml | 14 +++++++++++-- scripts/ubicloud/setup-free-suite.sh | 11 +++++++++- test/ci-image-cli-pin.test.ts | 31 ++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index eb7735ac0..7b337726e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,9 +9,19 @@ variables: BUN_VERSION: "1.4.2" .setup-bun: &setup-bun - - apt-get update -qq && apt-get install -qq -y curl jq git - - curl -fsSL https://bun.sh/install | bash -s "bun-v$BUN_VERSION" + - apt-get update -qq && apt-get install -qq -y curl jq git unzip + # The exact release archive, verified by SHA-256 before it is unpacked, as + # in .github/docker/Dockerfile.ci. test/ci-image-cli-pin.test.ts keeps the + # hash and BUN_VERSION equal to that file's linux-x64 arm. + - | + curl --retry 5 --retry-delay 5 --retry-connrefused -fsSL \ + "https://github.com/oven-sh/bun/releases/download/bun-v$BUN_VERSION/bun-linux-x64.zip" -o /tmp/bun.zip + echo "36368faef7527875d5ffa52e53cd48021741f2a83eb6208a8dd64068d422a913 /tmp/bun.zip" | sha256sum -c - + unzip -q /tmp/bun.zip -d /tmp/bun + install -D -m 0755 /tmp/bun/bun-linux-x64/bun "$HOME/.bun/bin/bun" + rm -rf /tmp/bun /tmp/bun.zip - export PATH="$HOME/.bun/bin:$PATH" + - test "$(bun --version)" = "$BUN_VERSION" version-gate: stage: check diff --git a/scripts/ubicloud/setup-free-suite.sh b/scripts/ubicloud/setup-free-suite.sh index ed8d09253..af8029543 100755 --- a/scripts/ubicloud/setup-free-suite.sh +++ b/scripts/ubicloud/setup-free-suite.sh @@ -22,11 +22,20 @@ if ! command -v node >/dev/null; then | sudo tar -xJ -C /usr/local --strip-components=1 fi +# The exact release archive, verified by SHA-256 before it is unpacked, as in +# .github/docker/Dockerfile.ci (test/ci-image-cli-pin.test.ts keeps them equal). if [ ! -x "$HOME/.bun/bin/bun" ]; then - curl -fsSL https://bun.sh/install | bash -s "bun-v$BUN_VERSION" >/dev/null + bun_tmp=$(mktemp -d) + curl --retry 5 --retry-delay 5 --retry-connrefused -fsSL \ + "https://github.com/oven-sh/bun/releases/download/bun-v$BUN_VERSION/bun-linux-x64.zip" -o "$bun_tmp/bun.zip" + echo "36368faef7527875d5ffa52e53cd48021741f2a83eb6208a8dd64068d422a913 $bun_tmp/bun.zip" | sha256sum -c - >/dev/null + unzip -q "$bun_tmp/bun.zip" -d "$bun_tmp" + install -D -m 0755 "$bun_tmp/bun-linux-x64/bun" "$HOME/.bun/bin/bun" + rm -rf "$bun_tmp" fi grep -q '.bun/bin' "$HOME/.profile" || echo 'export PATH="$HOME/.bun/bin:$PATH"' >>"$HOME/.profile" export PATH="$HOME/.bun/bin:$PATH" +test "$(bun --version)" = "$BUN_VERSION" git config --global user.email "free-tests@gstack.test" git config --global user.name "Free Tests" diff --git a/test/ci-image-cli-pin.test.ts b/test/ci-image-cli-pin.test.ts index a04ce197c..805858c21 100644 --- a/test/ci-image-cli-pin.test.ts +++ b/test/ci-image-cli-pin.test.ts @@ -180,3 +180,34 @@ describe('ci image codex authentication', () => { } }); }); + +describe('other CI Bun installs match the image (#1713, #1706)', () => { + const docker = fs.readFileSync(DOCKERFILE, 'utf-8'); + const imageSha = bunArchiveArms(docker).get('amd64'); + const imageVersion = docker.match(/^ARG BUN_VERSION=(\S+)$/m)?.[1]; + const engines = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf-8')).engines.bun; + + for (const rel of ['.gitlab-ci.yml', 'scripts/ubicloud/setup-free-suite.sh']) { + const source = fs.readFileSync(path.join(ROOT, rel), 'utf-8'); + + test(`${rel} downloads the verified linux-x64 archive instead of piping an installer into a shell`, () => { + expect(curlPipedToShell(source)).toEqual([]); + const download = source.indexOf('/releases/download/bun-v$BUN_VERSION/bun-linux-x64.zip'); + const verify = source.indexOf('sha256sum -c'); + const unpack = source.indexOf('unzip -q'); + expect(download).toBeGreaterThan(-1); + expect(verify).toBeGreaterThan(download); + expect(unpack).toBeGreaterThan(verify); + expect(source).toContain('test "$(bun --version)" = "$BUN_VERSION"'); + }); + + test(`${rel} pins the same Bun version and SHA-256 as Dockerfile.ci`, () => { + expect(imageSha).toMatch(/^[0-9a-f]{64}$/); + const hashes = [...source.matchAll(/echo "([0-9a-f]{64}) /g)].map((m) => m[1]); + expect(hashes).toEqual([imageSha!]); + const version = source.match(/^\s*BUN_VERSION[=:]\s*"?([\d.]+)"?\s*$/m)?.[1]; + expect(version).toBe(imageVersion!); + expect(engines).toBe(`>=${imageVersion}`); + }); + } +});