From d9488119beb6470015fcfb9e21f90a384baf822c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Mon, 16 Nov 2026 01:09:58 +0000 Subject: [PATCH] fix(aws-lambda): the release ships the arm64 ffmpeg only when it matches its committed digest (#7872) * fix(aws-lambda): the release ships the arm64 ffmpeg only when it matches its committed digest * style(ci): format the release workflow tests --- .github/workflows/lambda-arm64-image.yml | 5 +++ .github/workflows/publish.yml | 10 +++++ .github/workflows/studio-drag-frames.yml | 6 +-- .github/workflows/windows-render.yml | 12 ++--- .../aws-lambda/hf-media-linux-aarch64.sha256 | 1 + scripts/ci-cache-workflows.test.mjs | 18 ++++++++ scripts/publish-workflow.test.mjs | 45 +++++++++++++++++++ 7 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 packages/aws-lambda/hf-media-linux-aarch64.sha256 diff --git a/.github/workflows/lambda-arm64-image.yml b/.github/workflows/lambda-arm64-image.yml index e4e7c01f90..89bb727348 100644 --- a/.github/workflows/lambda-arm64-image.yml +++ b/.github/workflows/lambda-arm64-image.yml @@ -9,6 +9,7 @@ on: pull_request: paths: - "packages/aws-lambda/image/**" + - "packages/aws-lambda/hf-media-linux-aarch64.sha256" - "packages/aws-lambda/scripts/stage-arm64-image.ts" # A @sparticuz/chromium bump or a ZIP layout change must re-stage the image. - "packages/aws-lambda/package.json" @@ -59,6 +60,10 @@ jobs: docker buildx build --progress=plain --platform linux/arm64 --target artifact --output type=local,dest=out packages/aws-lambda/image - run: cat out/hf-media-check.txt && sha256sum out/*.tar.gz + # The reviewed digest of the build; a tarball from the cache or this run that differs fails here. + - name: Check the tarball against its committed digest + working-directory: out + run: sha256sum hf-media-linux-aarch64.tar.gz && sha256sum --strict -c ../packages/aws-lambda/hf-media-linux-aarch64.sha256 # Same path and key as publish.yml's lambda-arm64-ffmpeg job reads. - if: matrix.copy == 'a' && github.ref == 'refs/heads/main' uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ce0f20b6f8..d064916e7d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -52,6 +52,10 @@ jobs: run: >- docker buildx build --progress=plain --platform linux/arm64 --target artifact --output type=local,dest=out packages/aws-lambda/image + # The reviewed digest of the build; a tarball from the cache or this run that differs fails here. + - name: Check the tarball against its committed digest + working-directory: out + run: sha256sum hf-media-linux-aarch64.tar.gz && sha256sum --strict -c ../packages/aws-lambda/hf-media-linux-aarch64.sha256 - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 with: name: hf-media-linux-aarch64 @@ -89,7 +93,10 @@ jobs: echo "::error::Expected release commit $EXPECTED_COMMIT_SHA, checked out $ACTUAL_SHA" exit 1 fi + # The release installs the bun it downloads, never one restored from the shared cache. - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2 + with: + no-cache: true - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: node-version: 24 @@ -176,7 +183,10 @@ jobs: PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} run: node scripts/validate-release-channel.mjs + # The release installs the bun it downloads, never one restored from the shared cache. - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2 + with: + no-cache: true - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: node-version: 24 diff --git a/.github/workflows/studio-drag-frames.yml b/.github/workflows/studio-drag-frames.yml index 54553941f2..3c0ae90550 100644 --- a/.github/workflows/studio-drag-frames.yml +++ b/.github/workflows/studio-drag-frames.yml @@ -9,11 +9,9 @@ env: # Measures drag smoothness on a runner with nothing else on it. The bench measures a blank page per case # in the same run, and the box only counts as quiet if that control dropped no frame anywhere. on: + # Dispatch on the ref to measure: the run then checks out that ref and writes only that ref's cache. workflow_dispatch: inputs: - ref: - description: Commit, branch or tag to measure - default: main filter: description: Case ids to run (a regular expression) default: "^(move|resize|rotate|crop)-(none|tween)-px-r0-root-z100$" @@ -34,13 +32,11 @@ jobs: matrix: run: [1, 2, 3, 4, 5] env: - BENCH_REF: ${{ inputs.ref || 'main' }} BENCH_FILTER: ${{ inputs.filter || '^(move|resize|rotate|crop)-(none|tween)-px-r0-root-z100$' }} BENCH_GRID: ${{ inputs.grid || 'pr' }} steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 with: - ref: ${{ env.BENCH_REF }} lfs: true - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2 - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 diff --git a/.github/workflows/windows-render.yml b/.github/workflows/windows-render.yml index 249d0a0a76..af004adc29 100644 --- a/.github/workflows/windows-render.yml +++ b/.github/workflows/windows-render.yml @@ -27,12 +27,8 @@ on: branches: [main] push: branches: [main] + # Dispatch on the ref to render: the run then checks out that ref and writes only that ref's cache. workflow_dispatch: - inputs: - ref: - description: "Git ref to render (branch / tag / SHA)." - required: false - default: "" concurrency: group: windows-render-${{ github.ref }} @@ -98,7 +94,7 @@ jobs: steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 with: - ref: ${{ inputs.ref || github.sha }} + ref: ${{ github.sha }} - uses: ./.github/actions/preflight render-windows: @@ -125,7 +121,7 @@ jobs: - name: Checkout uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 with: - ref: ${{ inputs.ref || github.sha }} + ref: ${{ github.sha }} lfs: true - name: Show platform info @@ -459,7 +455,7 @@ jobs: - name: Checkout uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 with: - ref: ${{ inputs.ref || github.sha }} + ref: ${{ github.sha }} # Only the engine-cli lanes read an LFS file (engine's ffprobe test parses a producer HDR PNG). lfs: ${{ matrix.process_tests == true }} diff --git a/packages/aws-lambda/hf-media-linux-aarch64.sha256 b/packages/aws-lambda/hf-media-linux-aarch64.sha256 new file mode 100644 index 0000000000..7e18126c9c --- /dev/null +++ b/packages/aws-lambda/hf-media-linux-aarch64.sha256 @@ -0,0 +1 @@ +897b12368d50a60a8141f75dc293b29750925fe74ce8a6f2b21b1f6d83e28e13 hf-media-linux-aarch64.tar.gz diff --git a/scripts/ci-cache-workflows.test.mjs b/scripts/ci-cache-workflows.test.mjs index 78c7b55ef7..5ec83cd1d5 100644 --- a/scripts/ci-cache-workflows.test.mjs +++ b/scripts/ci-cache-workflows.test.mjs @@ -42,3 +42,21 @@ test("preflight installs without downloading ffmpeg or Chrome", () => { assert.ok(ffmpeg >= 0 && ffmpeg < install, "prepare-ffmpeg-bin runs before bun install"); assert.equal(steps[install].env?.PUPPETEER_SKIP_DOWNLOAD, "true"); }); + +// A dispatched run's cache scope is its own ref; a ref chosen by an input would run that code under main's scope. +test("no dispatched workflow checks out a ref its inputs choose", () => { + const chosen = workflows.flatMap(({ file, doc }) => { + const inputs = Object.keys(doc.on?.workflow_dispatch?.inputs ?? {}); + return Object.entries(doc.jobs ?? {}).flatMap(([name, job]) => + (job.steps ?? []) + .filter((step) => step.uses?.startsWith("actions/checkout@")) + .filter( + (step) => + /\binputs\.|github\.event\.inputs\./.test(String(step.with?.ref ?? "")) || + inputs.includes("ref"), + ) + .map(() => `${file} ${name}`), + ); + }); + assert.deepEqual([...new Set(chosen)], []); +}); diff --git a/scripts/publish-workflow.test.mjs b/scripts/publish-workflow.test.mjs index a9e32a354a..15e44d6416 100644 --- a/scripts/publish-workflow.test.mjs +++ b/scripts/publish-workflow.test.mjs @@ -492,3 +492,48 @@ test("every publish runs in the approval-gated npm-publish environment", () => { ["publish"], ); }); + +const pin = readFileSync( + new URL("../packages/aws-lambda/hf-media-linux-aarch64.sha256", import.meta.url), + "utf8", +); +const digestCheck = (steps) => + steps.findIndex((step) => step.name === "Check the tarball against its committed digest"); + +test("the Lambda ffmpeg ships only when it matches its committed digest", () => { + assert.match(pin, /^[0-9a-f]{64} {2}hf-media-linux-aarch64\.tar\.gz\n$/); + const steps = config.jobs["lambda-arm64-ffmpeg"].steps; + const at = digestCheck(steps); + const upload = steps.findIndex((step) => step.uses?.startsWith("actions/upload-artifact@")); + assert.ok( + at > 0 && at < upload, + "the check runs after the cache or the build, before the upload", + ); + assert.equal(steps[at].if, undefined, "a cache hit and a fresh build are both checked"); + assert.match( + steps[at].run, + /sha256sum --strict -c \.\.\/packages\/aws-lambda\/hf-media-linux-aarch64\.sha256$/, + ); + + const image = parse( + readFileSync(new URL("../.github/workflows/lambda-arm64-image.yml", import.meta.url), "utf8"), + ); + assert.ok( + digestCheck(image.jobs.ffmpeg.steps) > 0, + "a pull request that changes the build must update the digest", + ); + assert.ok( + image.on.pull_request.paths.includes("packages/aws-lambda/hf-media-linux-aarch64.sha256"), + ); +}); + +test("the release installs no tool restored from the shared cache", () => { + const steps = Object.values(config.jobs).flatMap((job) => job.steps ?? []); + const bun = steps.filter((step) => step.uses?.startsWith("oven-sh/setup-bun@")); + assert.ok(bun.length >= 1); + assert.equal(bun.filter((step) => step.with?.["no-cache"] !== true).length, 0); + assert.equal( + steps.filter((step) => step.uses?.startsWith("actions/setup-node@") && step.with?.cache).length, + 0, + ); +});