diff --git a/.changeset/supply-chain-skill-preflight-secrets.md b/.changeset/supply-chain-skill-preflight-secrets.md new file mode 100644 index 0000000000..0f1154196c --- /dev/null +++ b/.changeset/supply-chain-skill-preflight-secrets.md @@ -0,0 +1,5 @@ +--- +"stash": patch +--- + +The `stash-supply-chain-security` skill now describes the secrets of the FFI release pre-flight workflow correctly. It said that the workflow passes no secrets to its build. The workflow now passes exactly two, by name: `DOCKER_HUB_USERNAME` and `DOCKER_HUB_PASSWORD`. The musl build uses them to log in to Docker Hub before it pulls Alpine. They cannot authenticate an npm publish, so the workflow still cannot publish. diff --git a/.github/actionlint.yaml b/.github/actionlint.yaml index 633dcb4066..a5d35a8920 100644 --- a/.github/actionlint.yaml +++ b/.github/actionlint.yaml @@ -1,18 +1,9 @@ -# actionlint validates every `runs-on:` against the list of GitHub-hosted runner -# labels it ships with. Blacksmith runners are self-hosted from its perspective, -# so without this file each of the fourteen jobs using one is reported as an -# unknown label — and the release lint gate (.github/workflows/lint-release.yml) -# would be red on the day it lands, for reasons that have nothing to do with the -# release machinery it exists to check. +# actionlint checks every `runs-on:` label against the GitHub-hosted labels it +# knows, and against the self-hosted labels listed here. # -# Nothing complained before because actionlint has never run in this repository; -# lint-release.yml is what introduces it. +# The list is empty. Every self-hosted job runs on RunsOn, and each RunsOn +# label starts with `runs-on=${{ github.run_id }}`. actionlint does not check +# a label that contains an expression. So a Blacksmith label is now unknown, +# and actionlint reports it. self-hosted-runner: - labels: - - blacksmith-4vcpu-ubuntu-2404 - # Every job in the imported EQL suite. Sixteen of them, and the size is - # deliberate upstream: the sharded SQLx matrix compiles the full Rust - # dependency tree, so the runner is chosen for the compile rather than for - # the tests. Kept as its own label rather than renamed to the 4vcpu one — - # rehoming those jobs is a cost decision, not a lint fix. - - blacksmith-16vcpu-ubuntu-2204 + labels: [] diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 3b2407d024..7a83f16156 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -78,7 +78,7 @@ updates: versioning-strategy: lockfile-only # Monthly, where npm and actions are weekly. The deviation is about # validation cost, not risk appetite: a Cargo.lock bump is checked by - # tests-rust.yml — one Blacksmith job, 45-minute timeout, cargo test + + # tests-rust.yml — one RunsOn job, 45-minute timeout, cargo test + # clippy on host AND wasm32 — and the release additionally cross-builds # six platform binaries. Security fixes are not delayed by this: Dependabot # security updates are driven by alerts, not by `schedule`. diff --git a/.github/workflows/_build-eql-docs.yml b/.github/workflows/_build-eql-docs.yml index 63e6fb4ca4..f3fd186571 100644 --- a/.github/workflows/_build-eql-docs.yml +++ b/.github/workflows/_build-eql-docs.yml @@ -37,7 +37,7 @@ permissions: jobs: publish-docs: name: Build and publish documentation - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 20 steps: @@ -53,10 +53,18 @@ jobs: cache: false # publish path; see _build-eql-sql.yml working_directory: packages/eql + # A fresh RunsOn machine can still be running apt from boot, and apt-get + # fails at once on a held lock unless told to wait for it. + # DPkg::Lock::Timeout makes install wait. It does not make update wait + # for the package-list lock, so update retries for up to 5 minutes. - name: Install Doxygen run: | - sudo apt-get update - sudo apt-get install -y doxygen + for attempt in $(seq 1 20); do + sudo apt-get -o DPkg::Lock::Timeout=300 update && break + if [ "$attempt" -eq 20 ]; then exit 1; fi + sleep 15 + done + sudo apt-get -o DPkg::Lock::Timeout=300 install -y doxygen - name: Generate documentation env: diff --git a/.github/workflows/_build-eql-sql.yml b/.github/workflows/_build-eql-sql.yml index f27115dd1c..2daf41fc07 100644 --- a/.github/workflows/_build-eql-sql.yml +++ b/.github/workflows/_build-eql-sql.yml @@ -57,7 +57,7 @@ permissions: jobs: build: name: Build EQL - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 20 steps: diff --git a/.github/workflows/_build-ffi-artifacts.yml b/.github/workflows/_build-ffi-artifacts.yml index 14b4541410..7ad7813853 100644 --- a/.github/workflows/_build-ffi-artifacts.yml +++ b/.github/workflows/_build-ffi-artifacts.yml @@ -35,6 +35,13 @@ on: description: Commit to build from required: true type: string + # For the musl leg's Docker Hub login. Optional, because the login does + # nothing without them and the build still runs. + secrets: + DOCKER_HUB_USERNAME: + required: false + DOCKER_HUB_PASSWORD: + required: false permissions: contents: read @@ -114,12 +121,21 @@ jobs: # a native x86_64 build — so the other two legs were paying an # `apt-get update` (full package indexes) plus a ~200MB toolchain they do # not link against. + # + # A fresh RunsOn machine can still be running apt from boot, and apt-get + # fails at once on a held lock unless told to wait for it. + # DPkg::Lock::Timeout makes install wait. It does not make update wait + # for the package-list lock, so update retries for up to 5 minutes. - name: Install cross-compile toolchain (linux-arm64-gnu) if: ${{ matrix.cfg.platform == 'linux-arm64-gnu' }} run: | set -euo pipefail - sudo apt-get update - sudo apt-get install -y gcc-13-aarch64-linux-gnu + for attempt in $(seq 1 20); do + sudo apt-get -o DPkg::Lock::Timeout=300 update && break + if [ "$attempt" -eq 20 ]; then exit 1; fi + sleep 15 + done + sudo apt-get -o DPkg::Lock::Timeout=300 install -y gcc-13-aarch64-linux-gnu sudo ln -sf /usr/bin/aarch64-linux-gnu-gcc-13 /usr/bin/aarch64-linux-gnu-gcc # Rust comes from the runner image; only the TARGET has to be added. This @@ -216,6 +232,26 @@ jobs: pnpm run "$BUILD_SCRIPT" fi + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. With either secret empty, + # this step does nothing and pulls stay anonymous. + # scripts/__tests__/workflow-docker-hub-login.test.mjs requires it. Only + # the RunsOn legs log in. The macOS leg has no Docker, + # so `docker login` would fail there once the secrets exist. + - name: Log in to Docker Hub + if: ${{ startsWith(matrix.cfg.os, 'runs-on=') }} + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + set -euo pipefail + if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then + echo "No Docker Hub credentials, so image pulls stay anonymous." + exit 0 + fi + printf '%s' "$DOCKER_HUB_PASSWORD" | + docker login --username "$DOCKER_HUB_USERNAME" --password-stdin + # The musl binary is built inside Alpine Linux, a musl system, so the # compiler and its runtime libraries are musl's own. The toolchain this # leg used to download from musl.cc timed out from GitHub's runners on @@ -266,6 +302,13 @@ jobs: node -e "require(process.argv[1])" "$PWD/platforms/$PLATFORM/index.node" ' + # The login stored the Docker Hub password in the Docker config file, + # where any later step could read it. No later step pulls an image. + # scripts/__tests__/workflow-docker-hub-login.test.mjs checks the order. + - name: Log out of Docker Hub + if: ${{ always() && startsWith(matrix.cfg.os, 'runs-on=') }} + run: docker logout + - name: Place the binding in its platform package if: ${{ matrix.cfg.platform != 'linux-x64-musl' }} working-directory: languages/typescript/packages/protect-ffi @@ -358,7 +401,7 @@ jobs: # this job collects the six platform artifacts and uploads the complete set # as one artifact, so a caller downloads `ffi-tarballs` and has everything. needs: [binaries] - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 45 steps: - uses: actions/checkout@v6 diff --git a/.github/workflows/_test-auth-refresh-soak.yml b/.github/workflows/_test-auth-refresh-soak.yml index b129d8d78a..5d28d82b88 100644 --- a/.github/workflows/_test-auth-refresh-soak.yml +++ b/.github/workflows/_test-auth-refresh-soak.yml @@ -12,7 +12,7 @@ permissions: jobs: soak: - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 30 env: MISE_ENV: test diff --git a/.github/workflows/bench-eql.yml b/.github/workflows/bench-eql.yml index 8d46945ae7..19a675899f 100644 --- a/.github/workflows/bench-eql.yml +++ b/.github/workflows/bench-eql.yml @@ -93,7 +93,7 @@ defaults: jobs: bench: name: "Bench EQL (Postgres 17)" - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 60 env: @@ -146,10 +146,34 @@ jobs: # slow. Asserted by scripts/__tests__/eql-suite-ci.test.mjs. save-if: false + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. With either secret empty, + # this step does nothing and pulls stay anonymous. + # scripts/__tests__/workflow-docker-hub-login.test.mjs requires it. + - name: Log in to Docker Hub + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + set -euo pipefail + if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then + echo "No Docker Hub credentials, so image pulls stay anonymous." + exit 0 + fi + printf '%s' "$DOCKER_HUB_PASSWORD" | + docker login --username "$DOCKER_HUB_USERNAME" --password-stdin + - name: Setup database run: | mise run postgres:up "postgres-${POSTGRES_VERSION}" --extra-args "--detach --wait" + # The login stored the Docker Hub password in the Docker config file, + # where any later step could read it. No later step pulls an image. + # scripts/__tests__/workflow-docker-hub-login.test.mjs checks the order. + - name: Log out of Docker Hub + if: always() + run: docker logout + - name: Run bench tests # CS_* scoped to THIS step only (least privilege): test:bench -> test:sqlx:prep # -> fixture:generate:all encrypts via cipherstash-client and needs BOTH a diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 9a5b5072cf..2b6464ee4b 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -18,7 +18,7 @@ permissions: jobs: analyze: name: Analyze - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 10 strategy: diff --git a/.github/workflows/crap-crates.yml b/.github/workflows/crap-crates.yml index 8a325ab1ad..6ce34e7aff 100644 --- a/.github/workflows/crap-crates.yml +++ b/.github/workflows/crap-crates.yml @@ -59,7 +59,7 @@ env: jobs: crap-stack-auth: name: CRAP (stack-auth) - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 45 steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 @@ -83,7 +83,7 @@ jobs: crap-stack-encrypt: name: CRAP (stack-encrypt) - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 45 steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 diff --git a/.github/workflows/ffi-preflight.yml b/.github/workflows/ffi-preflight.yml index 5372ea2fe7..96986d3486 100644 --- a/.github/workflows/ffi-preflight.yml +++ b/.github/workflows/ffi-preflight.yml @@ -9,10 +9,14 @@ name: FFI release pre-flight # It never publishes, and cannot — both authentication paths are absent, which # takes more than the one line it looks like. No `id-token` permission closes # OIDC; a plain `NPM_TOKEN` would authenticate a publish regardless, so there is -# also no secret passed (no `secrets: inherit` on the call below), no -# `registry-url` on setup-node (that is what writes an `_authToken` line into -# .npmrc), and no NPM_TOKEN or NODE_AUTH_TOKEN anywhere. Adding any one of them -# turns this dry run into a publisher. +# also no `secrets: inherit` on the call below, no `registry-url` on setup-node +# (that is what writes an `_authToken` line into .npmrc), and no NPM_TOKEN or +# NODE_AUTH_TOKEN anywhere. Adding any one of them turns this dry run into a +# publisher. +# +# The call below passes exactly two secrets, by name: DOCKER_HUB_USERNAME and +# DOCKER_HUB_PASSWORD. The musl build logs in to Docker Hub with them before it +# pulls Alpine. They cannot authenticate an npm publish. on: workflow_dispatch: @@ -35,6 +39,9 @@ jobs: uses: ./.github/workflows/_build-ffi-artifacts.yml with: ref: ${{ inputs.ref }} + secrets: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} smoke: name: Install and smoke-test diff --git a/.github/workflows/fta-v3.yml b/.github/workflows/fta-v3.yml index df59df0651..7e03f8deb1 100644 --- a/.github/workflows/fta-v3.yml +++ b/.github/workflows/fta-v3.yml @@ -38,7 +38,7 @@ permissions: jobs: fta: name: Analyze v3 complexity - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 10 steps: diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index baa8e8cd8f..04dd89c40e 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -65,7 +65,7 @@ jobs: # Not on the nightly schedule, which is the campaign's. A manual dispatch # runs both jobs. if: github.event_name != 'schedule' - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 30 strategy: fail-fast: false @@ -112,7 +112,7 @@ jobs: fuzz-campaign: name: fuzz campaign (${{ matrix.slug }}) if: github.event_name != 'pull_request' - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 30 strategy: fail-fast: false diff --git a/.github/workflows/integration-drizzle.yml b/.github/workflows/integration-drizzle.yml index 041feebf10..32a268a460 100644 --- a/.github/workflows/integration-drizzle.yml +++ b/.github/workflows/integration-drizzle.yml @@ -204,7 +204,7 @@ on: jobs: integration: name: Drizzle v3 integration (db=${{ matrix.db }}) - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 35 # No concurrency group: `integration-db` gives each job its own compose # project and ephemeral host ports, so live-DB jobs no longer contend and do @@ -300,6 +300,24 @@ jobs: with: wasm: 'true' + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. With either secret empty, + # as on a fork's pull request, this step does nothing and pulls stay + # anonymous. scripts/__tests__/workflow-docker-hub-login.test.mjs + # requires it. + - name: Log in to Docker Hub + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + set -euo pipefail + if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then + echo "No Docker Hub credentials, so image pulls stay anonymous." + exit 0 + fi + printf '%s' "$DOCKER_HUB_PASSWORD" | + docker login --username "$DOCKER_HUB_USERNAME" --password-stdin + # No pre-`up` cleanup step any more: the project name is unique per job, so # a container leaked by a hard-killed prior run cannot hold this job's # name or its (ephemeral) port. Blanket-pruning would now be actively @@ -311,6 +329,13 @@ jobs: with: db: ${{ matrix.db }} + # The login stored the Docker Hub password in the Docker config file, + # where any later step could read it. No later step pulls an image. + # scripts/__tests__/workflow-docker-hub-login.test.mjs checks the order. + - name: Log out of Docker Hub + if: always() + run: docker logout + # `globalSetup` installs EQL v3 by shelling out to the real # `stash eql install --eql-version 3`, so an installer regression fails # here rather than hiding behind a test-only SQL apply. diff --git a/.github/workflows/integration-prisma-next.yml b/.github/workflows/integration-prisma-next.yml index c64663c36f..22d4017a38 100644 --- a/.github/workflows/integration-prisma-next.yml +++ b/.github/workflows/integration-prisma-next.yml @@ -114,7 +114,7 @@ on: jobs: integration: name: prisma-next v3 integration (db=${{ matrix.db }}) - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 15 # No concurrency group: `integration-db` gives each job its own compose # project and ephemeral host ports, so live-DB jobs no longer contend and do @@ -172,6 +172,24 @@ jobs: - name: Build the @cipherstash/auth binding uses: ./.github/actions/build-auth-binding + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. With either secret empty, + # as on a fork's pull request, this step does nothing and pulls stay + # anonymous. scripts/__tests__/workflow-docker-hub-login.test.mjs + # requires it. + - name: Log in to Docker Hub + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + set -euo pipefail + if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then + echo "No Docker Hub credentials, so image pulls stay anonymous." + exit 0 + fi + printf '%s' "$DOCKER_HUB_PASSWORD" | + docker login --username "$DOCKER_HUB_USERNAME" --password-stdin + # No pre-`up` cleanup step any more: the project name is unique per job, so # a container leaked by a hard-killed prior run cannot hold this job's # name or its (ephemeral) port. Blanket-pruning would now be actively @@ -183,6 +201,13 @@ jobs: with: db: ${{ matrix.db }} + # The login stored the Docker Hub password in the Docker config file, + # where any later step could read it. No later step pulls an image. + # scripts/__tests__/workflow-docker-hub-login.test.mjs checks the order. + - name: Log out of Docker Hub + if: always() + run: docker logout + # `globalSetup` installs EQL v3 by shelling out to the real # `stash eql install --eql-version 3`, so an installer regression fails # here rather than hiding behind a test-only SQL apply. diff --git a/.github/workflows/integration-protect-ffi.yml b/.github/workflows/integration-protect-ffi.yml index 8b8f4ff037..70ed1cbbb3 100644 --- a/.github/workflows/integration-protect-ffi.yml +++ b/.github/workflows/integration-protect-ffi.yml @@ -160,7 +160,7 @@ concurrency: jobs: integration: name: protect-ffi integration suite - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache # Generous, because a cold `build-ffi-binding` compiles the cipherstash # client graph from scratch. It is also the backstop for `mise run # start-db`, whose readiness loop retries `pg_isready` forever rather than @@ -341,6 +341,24 @@ jobs: # Must name runs-on's image; see scripts/__tests__/workflow-mise-cache-image.test.mjs cache_key_prefix: mise-v1-ubuntu-2404 + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. With either secret empty, + # as on a fork's pull request, this step does nothing and pulls stay + # anonymous. scripts/__tests__/workflow-docker-hub-login.test.mjs + # requires it. + - name: Log in to Docker Hub + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + set -euo pipefail + if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then + echo "No Docker Hub credentials, so image pulls stay anonymous." + exit 0 + fi + printf '%s' "$DOCKER_HUB_PASSWORD" | + docker login --username "$DOCKER_HUB_USERNAME" --password-stdin + # One task, four things the suite cannot run without (see # integration-tests/tasks.toml): `pnpm install --frozen-lockfile` (a # no-op here — the step above already ran it), `docker compose up` for @@ -365,6 +383,13 @@ jobs: working-directory: languages/typescript/packages/protect-ffi run: mise run setup + # The login stored the Docker Hub password in the Docker config file, + # where any later step could read it. No later step pulls an image. + # scripts/__tests__/workflow-docker-hub-login.test.mjs checks the order. + - name: Log out of Docker Hub + if: always() + run: docker logout + # vitest directly rather than `mise run test:integration:all`, because # that task's first two steps are the debug cargo build and a wasm-pack # rebuild that `build-ffi-binding` has already done (above). What it runs diff --git a/.github/workflows/integration-supabase.yml b/.github/workflows/integration-supabase.yml index 80e55dae22..067a8c749d 100644 --- a/.github/workflows/integration-supabase.yml +++ b/.github/workflows/integration-supabase.yml @@ -173,7 +173,7 @@ on: jobs: integration: name: Supabase v3 integration (db=${{ matrix.db }}) - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 15 # No concurrency group: `integration-db` gives each job its own compose # project and ephemeral host ports, so live-DB jobs no longer contend and do @@ -251,6 +251,24 @@ jobs: - name: Build the @cipherstash/auth binding uses: ./.github/actions/build-auth-binding + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. With either secret empty, + # as on a fork's pull request, this step does nothing and pulls stay + # anonymous. scripts/__tests__/workflow-docker-hub-login.test.mjs + # requires it. + - name: Log in to Docker Hub + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + set -euo pipefail + if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then + echo "No Docker Hub credentials, so image pulls stay anonymous." + exit 0 + fi + printf '%s' "$DOCKER_HUB_PASSWORD" | + docker login --username "$DOCKER_HUB_USERNAME" --password-stdin + # No pre-`up` cleanup step any more: the project name is unique per job, so # a container leaked by a hard-killed prior run cannot hold this job's # name or its (ephemeral) port. Blanket-pruning would now be actively @@ -262,6 +280,13 @@ jobs: with: db: ${{ matrix.db }} + # The login stored the Docker Hub password in the Docker config file, + # where any later step could read it. No later step pulls an image. + # scripts/__tests__/workflow-docker-hub-login.test.mjs checks the order. + - name: Log out of Docker Hub + if: always() + run: docker logout + # `globalSetup` installs EQL v3 by shelling out to the real # `stash eql install --eql-version 3 --supabase --direct`, so an installer # regression fails here rather than hiding behind a test-only SQL apply. diff --git a/.github/workflows/lint-release.yml b/.github/workflows/lint-release.yml index adde4c9332..0ea5dac8d1 100644 --- a/.github/workflows/lint-release.yml +++ b/.github/workflows/lint-release.yml @@ -6,7 +6,7 @@ name: Lint release tooling # pull request that touches any of it. # # actionlint is introduced here and nowhere else in the repo. It reads -# `.github/actionlint.yaml` for the Blacksmith runner label, and it runs +# `.github/actionlint.yaml` for its self-hosted runner labels, and it runs # shellcheck over every `run:` block — which is why the workflows it gates # avoid `sed`-into-`export` (SC2001, SC2155), `ls | wc -l` (SC2012), and # dollar-braces or backticks inside single-quoted `node -e` arguments (SC2016). @@ -19,7 +19,7 @@ name: Lint release tooling on: pull_request: # Exactly what the job reads: the workflows actionlint is pointed at, the - # config it resolves the Blacksmith label from, and the shell scripts the + # config it reads runner labels from, and the shell scripts the # later steps check and run. The filter also named scripts/release-gate.mjs, # scripts/ffi-release-matrix.mjs, scripts/lint-no-workflow-caching.mjs and # package.json — none of which this job looks at, since it deliberately does diff --git a/.github/workflows/macro-expand-eql.yml b/.github/workflows/macro-expand-eql.yml index f0949d16b9..7478b79cd4 100644 --- a/.github/workflows/macro-expand-eql.yml +++ b/.github/workflows/macro-expand-eql.yml @@ -51,7 +51,7 @@ permissions: jobs: macro-expand: name: "Macro expand drift (nightly)" - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 30 steps: diff --git a/.github/workflows/miri.yml b/.github/workflows/miri.yml index 75711f5fda..5342767b0b 100644 --- a/.github/workflows/miri.yml +++ b/.github/workflows/miri.yml @@ -40,7 +40,7 @@ env: jobs: miri-stack-guest-abi: name: Miri (stack-guest-abi) - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 30 steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 diff --git a/.github/workflows/mutants.yml b/.github/workflows/mutants.yml index 65cabc4c0b..26ef909fbc 100644 --- a/.github/workflows/mutants.yml +++ b/.github/workflows/mutants.yml @@ -64,7 +64,7 @@ env: jobs: mutants: name: Mutants gate - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 120 permissions: contents: read diff --git a/.github/workflows/prisma-example-readme-e2e.yml b/.github/workflows/prisma-example-readme-e2e.yml index 1a9b95c8d8..12f6d103e9 100644 --- a/.github/workflows/prisma-example-readme-e2e.yml +++ b/.github/workflows/prisma-example-readme-e2e.yml @@ -82,7 +82,7 @@ on: jobs: walkthrough: name: Run README walkthrough - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 15 # Skip cleanly on fork PRs where secrets aren't available. The @@ -158,9 +158,34 @@ jobs: - name: Build @cipherstash/stack-prisma run: pnpm exec turbo run build --filter @cipherstash/stack-prisma + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. With either secret empty, + # as on a fork's pull request, this step does nothing and pulls stay + # anonymous. scripts/__tests__/workflow-docker-hub-login.test.mjs + # requires it. + - name: Log in to Docker Hub + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + set -euo pipefail + if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then + echo "No Docker Hub credentials, so image pulls stay anonymous." + exit 0 + fi + printf '%s' "$DOCKER_HUB_PASSWORD" | + docker login --username "$DOCKER_HUB_USERNAME" --password-stdin + - name: Run README walkthrough e2e run: pnpm exec turbo run test:e2e --filter @cipherstash/e2e -- --run tests/prisma-example-readme.e2e.test.ts + # The login stored the Docker Hub password in the Docker config file, + # where any later step could read it. No later step pulls an image. + # scripts/__tests__/workflow-docker-hub-login.test.mjs checks the order. + - name: Log out of Docker Hub + if: always() + run: docker logout + - name: Tear down bundled Postgres (best-effort) if: always() working-directory: languages/typescript/examples/prisma diff --git a/.github/workflows/prisma-next-e2e.yml b/.github/workflows/prisma-next-e2e.yml index e917abe346..ea5e0f36bb 100644 --- a/.github/workflows/prisma-next-e2e.yml +++ b/.github/workflows/prisma-next-e2e.yml @@ -82,7 +82,7 @@ on: jobs: e2e: name: Run Prisma Next E2E - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 15 # Skip cleanly on fork PRs where secrets aren't available. The @@ -181,6 +181,24 @@ jobs: - name: Emit example contract run: pnpm exec turbo run emit --filter @cipherstash/prisma-example + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. With either secret empty, + # as on a fork's pull request, this step does nothing and pulls stay + # anonymous. scripts/__tests__/workflow-docker-hub-login.test.mjs + # requires it. + - name: Log in to Docker Hub + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + set -euo pipefail + if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then + echo "No Docker Hub credentials, so image pulls stay anonymous." + exit 0 + fi + printf '%s' "$DOCKER_HUB_PASSWORD" | + docker login --username "$DOCKER_HUB_USERNAME" --password-stdin + - name: Start E2E Postgres container working-directory: languages/typescript/examples/prisma run: | @@ -195,6 +213,13 @@ jobs: sleep 1 done + # The login stored the Docker Hub password in the Docker config file, + # where any later step could read it. No later step pulls an image. + # scripts/__tests__/workflow-docker-hub-login.test.mjs checks the order. + - name: Log out of Docker Hub + if: always() + run: docker logout + - name: Run E2E suite run: pnpm exec turbo run test:e2e --filter @cipherstash/prisma-example --env-mode=loose diff --git a/.github/workflows/release-golang.yml b/.github/workflows/release-golang.yml index 0db79e34ad..f59494a61e 100644 --- a/.github/workflows/release-golang.yml +++ b/.github/workflows/release-golang.yml @@ -71,7 +71,7 @@ concurrency: jobs: build: name: Build and test the release - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 90 env: VERSION: ${{ inputs.version }} @@ -242,7 +242,7 @@ jobs: publish: name: Tag and release needs: build - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 15 # Required reviewers set on this environment in the repository settings # gate every release; with none set, it gates nothing. @@ -370,7 +370,7 @@ jobs: verify: name: Check that Go resolves the version needs: publish - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 15 env: VERSION: ${{ inputs.version }} diff --git a/.github/workflows/release-postgres-eql-image.yml b/.github/workflows/release-postgres-eql-image.yml index c4006fd274..7a106ca715 100644 --- a/.github/workflows/release-postgres-eql-image.yml +++ b/.github/workflows/release-postgres-eql-image.yml @@ -58,7 +58,7 @@ jobs: name: Build EQL SQL needs: [eql-armed] if: needs.eql-armed.outputs.armed == 'true' - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 20 defaults: run: @@ -110,7 +110,7 @@ jobs: name: Build postgres-eql image (PG ${{ matrix.pg_version }}) needs: [eql-armed, build-sql] if: needs.eql-armed.outputs.armed == 'true' - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 30 permissions: contents: read @@ -135,6 +135,23 @@ jobs: # The Dockerfile COPYs it from its own build context. path: packages/eql/docker/ + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. With either secret empty, + # this step does nothing and pulls stay anonymous. + # scripts/__tests__/workflow-docker-hub-login.test.mjs requires it. + - name: Log in to Docker Hub + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + set -euo pipefail + if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then + echo "No Docker Hub credentials, so image pulls stay anonymous." + exit 0 + fi + printf '%s' "$DOCKER_HUB_PASSWORD" | + docker login --username "$DOCKER_HUB_USERNAME" --password-stdin + - name: Set up QEMU uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3 with: @@ -184,13 +201,20 @@ jobs: EQL_VERSION=${{ env.EQL_VERSION }} tags: ${{ steps.tags.outputs.tags }} + # The login stored the Docker Hub password in the Docker config file, + # where any later step could read it. No later step pulls an image. + # scripts/__tests__/workflow-docker-hub-login.test.mjs checks the order. + - name: Log out of Docker Hub + if: always() + run: docker logout + promote-latest: name: Promote PG17 image to :latest and : # No eql-armed condition: both its `needs` carry one, and a skipped `needs` # skips this job. needs: [eql-armed, build-sql, build-images] if: needs.build-sql.outputs.update_floating_tags == 'true' - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 10 permissions: contents: read @@ -199,11 +223,35 @@ jobs: EQL_VERSION: ${{ needs.build-sql.outputs.eql_version }} steps: + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. With either secret empty, + # this step does nothing and pulls stay anonymous. + # scripts/__tests__/workflow-docker-hub-login.test.mjs requires it. + - name: Log in to Docker Hub + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + set -euo pipefail + if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then + echo "No Docker Hub credentials, so image pulls stay anonymous." + exit 0 + fi + printf '%s' "$DOCKER_HUB_PASSWORD" | + docker login --username "$DOCKER_HUB_USERNAME" --password-stdin + - name: Set up Buildx uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 with: cache-binary: false + # The login stored the Docker Hub password in the Docker config file, + # where any later step could read it. No later step pulls an image. + # scripts/__tests__/workflow-docker-hub-login.test.mjs checks the order. + - name: Log out of Docker Hub + if: always() + run: docker logout + - name: Login to GHCR uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 32d93b00bf..8fe0acfb32 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -207,6 +207,11 @@ jobs: uses: ./.github/workflows/_build-ffi-artifacts.yml with: ref: ${{ github.sha }} + # By name, not `secrets: inherit`, so the called workflow gets no other + # secret of this workflow. + secrets: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} publish-ffi: name: Publish FFI packages @@ -493,7 +498,7 @@ jobs: needs.gate.outputs.auth != 'true' || needs.publish-auth.result == 'success' ) - # GitHub-hosted (not Blacksmith): npm provenance attestations, which are + # GitHub-hosted (not RunsOn): npm provenance attestations, which are # generated automatically by OIDC trusted publishing, are only accepted # from github-hosted runners — self-hosted runners are rejected with E422. runs-on: ubuntu-latest diff --git a/.github/workflows/test-eql.yml b/.github/workflows/test-eql.yml index 776ac20eae..9facafed04 100644 --- a/.github/workflows/test-eql.yml +++ b/.github/workflows/test-eql.yml @@ -153,7 +153,7 @@ jobs: # would either skip the merge-queue matrix or deadlock `ci-required`. changes: name: "Detect relevant changes" - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 10 outputs: relevant: ${{ steps.r.outputs.relevant }} @@ -243,7 +243,7 @@ jobs: # everything else -> PG 14-17 x 2 shards (coverage lane). setup: name: "Compute matrix" - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 10 # Opts out of the workflow-level `working-directory: packages/eql`. This job # deliberately does not check out — it is pure bash deriving a matrix — so @@ -315,7 +315,7 @@ jobs: || needs.changes.outputs.relevant == 'true') && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 45 env: # test:sqlx:archive depends on test:sqlx:prep, which copies the built EQL @@ -363,10 +363,35 @@ jobs: # `save-if: false` so a fast-finishing light job can't win the save race # and overwrite the key with a deps-less target/. + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. With either secret empty, + # as on a fork's pull request, this step does nothing and pulls stay + # anonymous. scripts/__tests__/workflow-docker-hub-login.test.mjs + # requires it. + - name: Log in to Docker Hub + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + set -euo pipefail + if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then + echo "No Docker Hub credentials, so image pulls stay anonymous." + exit 0 + fi + printf '%s' "$DOCKER_HUB_PASSWORD" | + docker login --username "$DOCKER_HUB_USERNAME" --password-stdin + - name: Setup database (Postgres 17) run: | mise run postgres:up "postgres-${POSTGRES_VERSION}" --extra-args "--detach --wait" + # The login stored the Docker Hub password in the Docker config file, + # where any later step could read it. No later step pulls an image. + # scripts/__tests__/workflow-docker-hub-login.test.mjs checks the order. + - name: Log out of Docker Hub + if: always() + run: docker logout + - name: Build EQL + archive test binaries run: | mise run test:sqlx:archive @@ -400,7 +425,7 @@ jobs: if: >- github.event_name != 'pull_request' || needs.changes.outputs.relevant == 'true' - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 75 strategy: fail-fast: false @@ -445,10 +470,35 @@ jobs: name: nextest-archive path: packages/eql + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. With either secret empty, + # as on a fork's pull request, this step does nothing and pulls stay + # anonymous. scripts/__tests__/workflow-docker-hub-login.test.mjs + # requires it. + - name: Log in to Docker Hub + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + set -euo pipefail + if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then + echo "No Docker Hub credentials, so image pulls stay anonymous." + exit 0 + fi + printf '%s' "$DOCKER_HUB_PASSWORD" | + docker login --username "$DOCKER_HUB_USERNAME" --password-stdin + - name: Setup database (Postgres ${{ matrix.postgres-version }}) run: | mise run postgres:up "postgres-${POSTGRES_VERSION}" --extra-args "--detach --wait" + # The login stored the Docker Hub password in the Docker config file, + # where any later step could read it. No later step pulls an image. + # scripts/__tests__/workflow-docker-hub-login.test.mjs checks the order. + - name: Log out of Docker Hub + if: always() + run: docker logout + - name: Run shard ${{ matrix.shard }}/${{ needs.setup.outputs.shard-total }} run: | mise run test:sqlx:partition @@ -463,7 +513,7 @@ jobs: if: >- github.event_name != 'pull_request' || needs.changes.outputs.relevant == 'true' - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 10 strategy: fail-fast: false @@ -491,10 +541,35 @@ jobs: shared-key: sqlx-tests save-if: false + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. With either secret empty, + # as on a fork's pull request, this step does nothing and pulls stay + # anonymous. scripts/__tests__/workflow-docker-hub-login.test.mjs + # requires it. + - name: Log in to Docker Hub + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + set -euo pipefail + if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then + echo "No Docker Hub credentials, so image pulls stay anonymous." + exit 0 + fi + printf '%s' "$DOCKER_HUB_PASSWORD" | + docker login --username "$DOCKER_HUB_USERNAME" --password-stdin + - name: Setup database (Postgres ${{ matrix.postgres-version }}) run: | mise run postgres:up "postgres-${POSTGRES_VERSION}" --extra-args "--detach --wait" + # The login stored the Docker Hub password in the Docker config file, + # where any later step could read it. No later step pulls an image. + # scripts/__tests__/workflow-docker-hub-login.test.mjs checks the order. + - name: Log out of Docker Hub + if: always() + run: docker logout + # Source-only doc checks (coverage + required-tags) moved to the dedicated # `docs-static` job so they run exactly once, not per-Postgres. This step # keeps only the DB-backed SQL-syntax validation, which genuinely needs the @@ -523,7 +598,7 @@ jobs: if: >- github.event_name != 'pull_request' || needs.changes.outputs.relevant == 'true' - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 10 steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 @@ -553,11 +628,22 @@ jobs: if: >- github.event_name != 'pull_request' || needs.changes.outputs.relevant == 'true' - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 15 services: encryption-postgres: image: postgres:17 + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. One expression, not + # `username:` and `password:` keys: GitHub rejects an empty value for + # either key ("Unexpected value ''"), which fails the job on a fork's + # pull request. With either secret empty this gives `{}`, and the + # runner then pulls without a login. + credentials: >- + ${{ secrets.DOCKER_HUB_USERNAME != '' && secrets.DOCKER_HUB_PASSWORD != '' + && fromJSON(format('{{"username":{0},"password":{1}}}', + toJSON(secrets.DOCKER_HUB_USERNAME), toJSON(secrets.DOCKER_HUB_PASSWORD))) + || fromJSON('{}') }} env: POSTGRES_PASSWORD: postgres # Container port only: Docker picks the host port, and the test step @@ -682,7 +768,7 @@ jobs: if: >- github.event_name != 'pull_request' || needs.changes.outputs.relevant == 'true' - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 10 steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 @@ -715,7 +801,7 @@ jobs: if: >- github.event_name != 'pull_request' || needs.changes.outputs.relevant == 'true' - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 10 steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 @@ -752,7 +838,7 @@ jobs: if: >- github.event_name != 'pull_request' || needs.changes.outputs.relevant == 'true' - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 20 steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 @@ -795,7 +881,7 @@ jobs: if: >- github.event_name != 'pull_request' || needs.changes.outputs.relevant == 'true' - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 10 env: POSTGRES_VERSION: "17" @@ -828,9 +914,35 @@ jobs: workspaces: packages/eql shared-key: sqlx-tests save-if: false + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. With either secret empty, + # as on a fork's pull request, this step does nothing and pulls stay + # anonymous. scripts/__tests__/workflow-docker-hub-login.test.mjs + # requires it. + - name: Log in to Docker Hub + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + set -euo pipefail + if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then + echo "No Docker Hub credentials, so image pulls stay anonymous." + exit 0 + fi + printf '%s' "$DOCKER_HUB_PASSWORD" | + docker login --username "$DOCKER_HUB_USERNAME" --password-stdin + - name: Setup database run: | mise run postgres:up "postgres-${POSTGRES_VERSION}" --extra-args "--detach --wait" + + # The login stored the Docker Hub password in the Docker config file, + # where any later step could read it. No later step pulls an image. + # scripts/__tests__/workflow-docker-hub-login.test.mjs checks the order. + - name: Log out of Docker Hub + if: always() + run: docker logout + - name: Build and install EQL run: | set -euo pipefail @@ -856,7 +968,7 @@ jobs: # per-version `validate` job). docs-static: name: "SQL doc validation" - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 10 steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 @@ -896,7 +1008,7 @@ jobs: # issue state, so it runs on every PR rather than hiding behind the e2e job. known-failures: name: "known-failure markers" - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 10 permissions: contents: read @@ -935,7 +1047,7 @@ jobs: # PRs it exists to check. doc-anchors: name: "doc anchor links" - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 10 steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 @@ -969,7 +1081,7 @@ jobs: || needs.changes.outputs.relevant == 'true') && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 40 env: POSTGRES_VERSION: "17" @@ -1002,9 +1114,35 @@ jobs: workspaces: packages/eql shared-key: sqlx-tests save-if: false + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. With either secret empty, + # as on a fork's pull request, this step does nothing and pulls stay + # anonymous. scripts/__tests__/workflow-docker-hub-login.test.mjs + # requires it. + - name: Log in to Docker Hub + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + set -euo pipefail + if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then + echo "No Docker Hub credentials, so image pulls stay anonymous." + exit 0 + fi + printf '%s' "$DOCKER_HUB_PASSWORD" | + docker login --username "$DOCKER_HUB_USERNAME" --password-stdin + - name: Setup database (Postgres 17) run: | mise run postgres:up "postgres-${POSTGRES_VERSION}" --extra-args "--detach --wait" + + # The login stored the Docker Hub password in the Docker config file, + # where any later step could read it. No later step pulls an image. + # scripts/__tests__/workflow-docker-hub-login.test.mjs checks the order. + - name: Log out of Docker Hub + if: always() + run: docker logout + - name: Run e2e property suite run: | mise run test:sqlx:e2e @@ -1021,7 +1159,7 @@ jobs: codegen, self-contained-v3, matrix-coverage, splinter, docs-static, known-failures, doc-anchors, e2e] if: always() - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 10 # Same opt-out as `setup`, and this is the worse of the two to get wrong: # this job is the required check. It reads `needs.*.result` and checks out diff --git a/.github/workflows/tests-bench.yml b/.github/workflows/tests-bench.yml index 0df32e9847..f470d05375 100644 --- a/.github/workflows/tests-bench.yml +++ b/.github/workflows/tests-bench.yml @@ -46,7 +46,7 @@ on: jobs: tests-bench: name: Run Bench Smoke Tests - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 10 steps: @@ -89,6 +89,24 @@ jobs: working-directory: languages/typescript/packages/bench run: pnpm test:unit + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. With either secret empty, + # as on a fork's pull request, this step does nothing and pulls stay + # anonymous. scripts/__tests__/workflow-docker-hub-login.test.mjs + # requires it. + - name: Log in to Docker Hub + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + set -euo pipefail + if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then + echo "No Docker Hub credentials, so image pulls stay anonymous." + exit 0 + fi + printf '%s' "$DOCKER_HUB_PASSWORD" | + docker login --username "$DOCKER_HUB_USERNAME" --password-stdin + # Service-scoped `postgres`: local/docker-compose.yml also defines a # PostgREST that bench never talks to. # @@ -100,6 +118,13 @@ jobs: working-directory: local run: docker compose up --wait --wait-timeout 60 postgres + # The login stored the Docker Hub password in the Docker config file, + # where any later step could read it. No later step pulls an image. + # scripts/__tests__/workflow-docker-hub-login.test.mjs checks the order. + - name: Log out of Docker Hub + if: always() + run: docker logout + # `pnpm test:local` resolves to `vitest run`; the trailing `db-only` # is a vitest path filter that narrows to __tests__/db-only.test.ts # (credential-free smoke). Note: pnpm 10 forwards script args without diff --git a/.github/workflows/tests-crates.yml b/.github/workflows/tests-crates.yml index 40cc572cce..c36ba2c75b 100644 --- a/.github/workflows/tests-crates.yml +++ b/.github/workflows/tests-crates.yml @@ -79,7 +79,7 @@ env: jobs: rust: name: fmt, clippy, nextest, doctests, rustdoc - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 60 env: # Job-level, not workflow-level: RUSTFLAGS replaces the @@ -158,7 +158,7 @@ jobs: node-bindings: name: node bindings, napi typings, stack-auth-wasm - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 45 steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 diff --git a/.github/workflows/tests-golang.yml b/.github/workflows/tests-golang.yml index 9bfff334ab..727015047d 100644 --- a/.github/workflows/tests-golang.yml +++ b/.github/workflows/tests-golang.yml @@ -95,7 +95,7 @@ env: jobs: wasi-check: name: WASI check, guests and Go (Linux) - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 60 env: # wasm:guest:test and wasm:auth-guest:test run nextest, which is pinned @@ -242,7 +242,7 @@ jobs: # guests: the packages embed a directory and compile without them. go-lint: name: Go lint - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 15 steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 @@ -334,7 +334,7 @@ jobs: live: name: Go live tests and stack-encrypt examples needs: wasi-check - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 30 env: CS_WORKSPACE_CRN: ${{ vars.CS_WORKSPACE_CRN }} diff --git a/.github/workflows/tests-rust.yml b/.github/workflows/tests-rust.yml index 1a1bdc3885..3d05d70ecc 100644 --- a/.github/workflows/tests-rust.yml +++ b/.github/workflows/tests-rust.yml @@ -58,7 +58,7 @@ concurrency: jobs: rust: name: cargo test + clippy + rustfmt - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 45 steps: - uses: actions/checkout@v6 diff --git a/.github/workflows/tests-supply-chain.yml b/.github/workflows/tests-supply-chain.yml index d2831856f7..589d241596 100644 --- a/.github/workflows/tests-supply-chain.yml +++ b/.github/workflows/tests-supply-chain.yml @@ -13,7 +13,7 @@ name: Test supply chain security # See the "CI/CD Supply-Chain Hardening" section of SECURITY.md. # # Deliberately minimal: -# - GitHub-hosted runner (no Blacksmith transparent cache) +# - GitHub-hosted runner (no RunsOn transparent S3 cache) # - contents:read only # - no secrets # - no caching diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7369eebfbb..2cc2521206 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,7 +21,7 @@ jobs: # Tightening to fail on warnings is tracked in #625. lint: name: Lint (Biome) - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 10 steps: - name: Checkout Repo @@ -54,7 +54,7 @@ jobs: run-tests: name: Run Tests (Node ${{ matrix.node-version }}) - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 25 strategy: matrix: @@ -399,7 +399,7 @@ jobs: e2e-tests: name: Run E2E Tests - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache # The migration harness's live Runs take most of this job's time; the # limit covers them plus the job's other suites, with headroom. timeout-minutes: 30 @@ -470,6 +470,24 @@ jobs: id: auth-binding uses: ./.github/actions/build-auth-binding + # Docker Hub refuses pulls without a login after too many from one + # address, and RunsOn machines reach that limit. With either secret empty, + # as on a fork's pull request, this step does nothing and pulls stay + # anonymous. scripts/__tests__/workflow-docker-hub-login.test.mjs + # requires it. + - name: Log in to Docker Hub + env: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} + run: | + set -euo pipefail + if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then + echo "No Docker Hub credentials, so image pulls stay anonymous." + exit 0 + fi + printf '%s' "$DOCKER_HUB_PASSWORD" | + docker login --username "$DOCKER_HUB_USERNAME" --password-stdin + # Run the standalone `e2e/` workspace via turbo so the `^build` # dep on the `test:e2e` task builds cli + wizard first. CLI's own # E2E (`languages/typescript/packages/cli/tests/e2e/**`) is covered by the `run-tests` @@ -547,6 +565,13 @@ jobs: port="$(docker port pg18-upgrade 5432/tcp | head -n1 | sed 's/.*://')" echo "database-url=postgres://postgres:password@127.0.0.1:${port}/postgres" >> "$GITHUB_OUTPUT" + # The login stored the Docker Hub password in the Docker config file, + # where any later step could read it. No later step pulls an image. + # scripts/__tests__/workflow-docker-hub-login.test.mjs checks the order. + - name: Log out of Docker Hub + if: always() + run: docker logout + - name: Run the Postgres upgrade example on PostgreSQL 18 if: ${{ !cancelled() && steps.db18.outcome == 'success' }} run: pnpm exec turbo run test:protect-crossover --filter @cipherstash/e2e --env-mode=loose -- tests/protect-postgres-upgrade.e2e.test.ts @@ -564,7 +589,7 @@ jobs: # a silent fallback to the NAPI module is impossible. wasm-e2e-tests: name: Run WASM E2E Tests (Deno) - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 35 permissions: @@ -708,7 +733,7 @@ jobs: run-tests-bun: name: Run Tests (Bun) - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 15 continue-on-error: true diff --git a/.github/workflows/udeps.yml b/.github/workflows/udeps.yml index db3d33b98c..ed05f96d0b 100644 --- a/.github/workflows/udeps.yml +++ b/.github/workflows/udeps.yml @@ -68,7 +68,7 @@ env: jobs: udeps: name: Check unused Rust dependencies - runs-on: blacksmith-4vcpu-ubuntu-2404 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache timeout-minutes: 45 steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 diff --git a/scripts/__tests__/crates-ci.test.mjs b/scripts/__tests__/crates-ci.test.mjs index 8b3a64bb3f..7bb535560f 100644 --- a/scripts/__tests__/crates-ci.test.mjs +++ b/scripts/__tests__/crates-ci.test.mjs @@ -2,6 +2,12 @@ import { execFileSync } from 'node:child_process' import { existsSync, readdirSync, readFileSync } from 'node:fs' import { join } from 'node:path' import { describe, expect, it } from 'vitest' +import { + parseIncludes, + parseStringArray, + parseTomlTasks, + stripCommentLines, +} from './lib/mise-tasks.mjs' import { REPO_ROOT } from './lib/repo-root.mjs' import { readWorkflow, WORKFLOW_DIR, workflowFiles } from './lib/workflows.mjs' @@ -38,42 +44,11 @@ const IMPORTED_WORKFLOW_DIR = '.github/imported-workflows' // The task graph // --------------------------------------------------------------------------- -/** The `["a", 'b']` inside a TOML array, without a TOML parser. */ -const parseStringArray = (inner) => - [...inner.matchAll(/"([^"]+)"|'([^']+)'/g)].map((m) => m[1] ?? m[2]) - -/** `[task_config].includes` from the root mise.toml. */ -function parseIncludes(miseText) { - const section = /^\[task_config\][^\n]*\n([\s\S]*?)(?=^\[|$(?![\s\S]))/m.exec( - miseText, - ) - const array = /^includes\s*=\s*\[([^\]]*)\]/m.exec(section?.[1] ?? '') - return array ? parseStringArray(array[1]) : [] -} - -/** - * mise task blocks. In mise.toml a task is `[tasks."name"]`; in an included - * file every top-level table is a task, `["name"]` (see - * `eql-suite-ci.test.mjs` for why the dialects must not be merged). - */ -function parseTomlTasks(text, { bareTables }) { - const header = bareTables - ? /^\[(?:"([^"]+)"|([\w:.-]+))\]/ - : /^\[tasks\.(?:"([^"]+)"|([\w:.-]+))\]/ - return text - .split(/^(?=\[)/m) - .map((block) => ({ match: header.exec(block), block })) - .filter(({ match }) => match) - .map(({ match, block }) => ({ name: match[1] ?? match[2], block })) -} - const parseDepends = (block) => { const m = /^[ \t]*depends\s*=\s*\[([^\]]*)\]/m.exec(block) return m ? parseStringArray(m[1]) : [] } -const stripCommentLines = (text) => text.replace(/^[ \t]*#.*$/gm, '') - function taskGraph() { const tasks = new Map() const bySource = new Map() diff --git a/scripts/__tests__/eql-suite-ci.test.mjs b/scripts/__tests__/eql-suite-ci.test.mjs index ee00032a80..2f77d8d756 100644 --- a/scripts/__tests__/eql-suite-ci.test.mjs +++ b/scripts/__tests__/eql-suite-ci.test.mjs @@ -3,6 +3,12 @@ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs' import { dirname, join, relative, sep } from 'node:path' import yaml from 'js-yaml' import { describe, expect, it } from 'vitest' +import { + parseIncludes, + parseStringArray, + parseTomlTasks, + stripCommentLines, +} from './lib/mise-tasks.mjs' import { REPO_ROOT } from './lib/repo-root.mjs' import { readWorkflow, WORKFLOW_DIR, workflowFiles } from './lib/workflows.mjs' @@ -599,54 +605,6 @@ const MISE_TOML = `${EQL_PACKAGE}/mise.toml` const readRepo = (relPath) => readFileSync(join(REPO_ROOT, relPath), 'utf8') -/** The `["a", 'b']` inside a TOML array, without a TOML parser. */ -const parseStringArray = (inner) => - [...inner.matchAll(/"([^"]+)"|'([^']+)'/g)].map((m) => m[1] ?? m[2]) - -/** - * `[task_config].includes`, read rather than hard-coded. - * - * The list used to be a `MISE_CONFIGS` const here, which is a copy of a - * declaration that lives in mise.toml — and the failure mode of a stale copy is - * the one this file is about: a fourth config lands, this scan never opens it, - * and every task in it becomes unguarded silently. Reading the real list means - * a new entry is covered the day it is added; `TASK_SOURCES` below then insists - * each entry actually yielded a task, so an entry that resolves to nothing - * fails rather than contributing nothing. - */ -function parseIncludes(miseText) { - const section = /^\[task_config\][^\n]*\n([\s\S]*?)(?=^\[|$)/m.exec(miseText) - const array = /^includes\s*=\s*\[([^\]]*)\]/m.exec(section?.[1] ?? '') - return array ? parseStringArray(array[1]) : [] -} - -/** - * mise's task blocks, without a TOML parser. - * - * Adding one is an audit decision in this repo, and the shape needed here is - * small: a table header, an optional `depends = [...]`, and the body text. - * - * The two dialects are NOT interchangeable, and merging them would be wrong in - * both directions. In `mise.toml` a task is `[tasks."name"]` and a bare - * `[settings]` / `[tools]` / `[env]` table is configuration. In a file named by - * `includes` the whole document is tasks, so EVERY top-level table is a task - * name and `[tasks."name"]` is not a task at all — mise rejects the file with - * "unknown field `name`, expected one of `description`, `alias`, …". That is - * why `tasks/postgres.toml` writes `["postgres:up"]` and `tasks/fixtures.toml` - * writes `["fixture:generate:all"]`, and why the old single regex parsed 0 of - * their 6 tasks. - */ -function parseTomlTasks(text, { bareTables }) { - const header = bareTables - ? /^\[(?:"([^"]+)"|([\w:.-]+))\]/ - : /^\[tasks\.(?:"([^"]+)"|([\w:.-]+))\]/ - return text - .split(/^(?=\[)/m) // split on top-level table headers; keep header + body - .map((block) => ({ match: header.exec(block), block })) - .filter(({ match }) => match) - .map(({ match, block }) => ({ name: match[1] ?? match[2], block })) -} - /** * A task's `depends`, from either dialect. * @@ -660,25 +618,6 @@ function parseDepends(text) { return m ? parseStringArray(m[1]) : [] } -/** - * Comment lines, in both TOML and shell. Prose is not a step — see `invokes` - * and `scriptBodies`, which both read a body only after this has run. - * - * Memoised on the exact input string. The mutation test below re-runs the whole - * reachability walk once per workflow, so this is called tens of thousands of - * times over the same ~100 bodies; without the cache that test spends most of a - * second re-stripping text and starts flaking against vitest's 5s timeout. - */ -const strippedBodies = new Map() -function stripCommentLines(text) { - let stripped = strippedBodies.get(text) - if (stripped === undefined) { - stripped = text.replace(/^[ \t]*#.*$/gm, '') - strippedBodies.set(text, stripped) - } - return stripped -} - /** * How many hops of script→script delegation to follow before giving up. * @@ -1547,8 +1486,10 @@ describe('the guard fails when a workflow stops calling a cargo check', () => { * site. Versioned docs artifacts are still * built by _build-eql-docs.yml * lint-release.yml -> merged into the root file of that name - * .github/actionlint.yaml -> DROPPED: the root copy already carries the - * `blacksmith-16vcpu-ubuntu-2204` label + * .github/actionlint.yaml -> DROPPED: the root copy is the one + * actionlint reads, and it lists every + * self-hosted runner label (none, since + * RunsOn labels are expressions) * ISSUE_TEMPLATE/docs-feedback.yml -> DROPPED: the root copy is the same file * with the Code of Conduct link already * repointed at cipherstash/stack diff --git a/scripts/__tests__/ffi-release-matrix.test.mjs b/scripts/__tests__/ffi-release-matrix.test.mjs index 3a71919ac4..fd5f095e73 100644 --- a/scripts/__tests__/ffi-release-matrix.test.mjs +++ b/scripts/__tests__/ffi-release-matrix.test.mjs @@ -8,6 +8,7 @@ import { triplesFromPlatformManifests, } from '../ffi-release-matrix.mjs' import { REPO_ROOT } from './lib/repo-root.mjs' +import { runsOnLabel } from './lib/runs-on.mjs' /** * The release matrix decides what each of the six platform jobs compiles and @@ -56,7 +57,9 @@ function logFileOf(scriptName) { return redirect ? redirect[1] : null } -const MATRIX = releaseMatrix(TRIPLES) +const RUN_ID = '1234' +const MATRIX = releaseMatrix(TRIPLES, RUN_ID) +const RUNS_ON_4 = runsOnLabel(4, { runId: RUN_ID }) describe('the platform fixture matches the package', () => { it('covers exactly the platforms this package publishes', () => { @@ -157,21 +160,21 @@ describe('release matrix', () => { { platform: 'linux-x64-gnu', target: 'x86_64-unknown-linux-gnu', - os: 'blacksmith-4vcpu-ubuntu-2404', + os: RUNS_ON_4, script: 'zigbuild', log: 'zig.log', }, { platform: 'linux-arm64-gnu', target: 'aarch64-unknown-linux-gnu', - os: 'blacksmith-4vcpu-ubuntu-2404', + os: RUNS_ON_4, script: 'zigbuild', log: 'zig.log', }, { platform: 'linux-x64-musl', target: 'x86_64-unknown-linux-musl', - os: 'blacksmith-4vcpu-ubuntu-2404', + os: RUNS_ON_4, script: 'build:native', log: 'cargo.log', }, @@ -180,8 +183,16 @@ describe('release matrix', () => { it('sends a platform the table does not name to a Linux runner', () => { // The fallback arm, which the table above cannot reach. A seventh platform - // added tomorrow gets Blacksmith unless `runnerFor` is taught otherwise. - expect(runnerFor('linux-arm64-musl')).toBe('blacksmith-4vcpu-ubuntu-2404') + // added tomorrow builds on RunsOn unless `runnerFor` is taught otherwise. + expect(runnerFor('linux-arm64-musl', RUN_ID)).toBe(RUNS_ON_4) + }) + + it('refuses a RunsOn label with no run ID in it', () => { + // `runs-on=undefined/…` would be one label shared by every run, so one + // run's machine could take another run's job. + expect(() => runnerFor('linux-x64-gnu', '')).toThrow(/GITHUB_RUN_ID/) + // Only a RunsOn label needs the run ID. + expect(runnerFor('darwin-x64', '')).toBe('macos-latest') }) it('is empty for an empty mapping, rather than inventing platforms', () => { diff --git a/scripts/__tests__/fixtures/lint-no-workflow-caching/thirdparty-cache.yml b/scripts/__tests__/fixtures/lint-no-workflow-caching/thirdparty-cache.yml index 391079b250..cf2346314c 100644 --- a/scripts/__tests__/fixtures/lint-no-workflow-caching/thirdparty-cache.yml +++ b/scripts/__tests__/fixtures/lint-no-workflow-caching/thirdparty-cache.yml @@ -2,9 +2,9 @@ # `^actions/cache(/(restore|save))?@`, and neither carries a `cache:` input for # the `with.cache` rule to read. Both restore the GitHub Actions cache anyway. # -# Not hypothetical. This repo runs eleven jobs on `blacksmith-*` runners, where -# `useblacksmith/cache` is the documented drop-in for `actions/cache`, and it -# has just absorbed a Cargo workspace at `packages/protect-ffi`, where +# Not hypothetical. Each runner vendor publishes a drop-in for `actions/cache`: +# `useblacksmith/cache` for Blacksmith, and `runs-on/cache` for RunsOn, where +# this repo's self-hosted jobs run. The repo has also absorbed a Cargo workspace at `packages/protect-ffi`, where # `Swatinem/rust-cache` is the conventional choice. Either could be added by # someone who reasonably believed this gate would catch the mistake. name: Third Party Cache diff --git a/scripts/__tests__/lib/mise-tasks.mjs b/scripts/__tests__/lib/mise-tasks.mjs new file mode 100644 index 0000000000..035d36fb62 --- /dev/null +++ b/scripts/__tests__/lib/mise-tasks.mjs @@ -0,0 +1,50 @@ +// Reads mise task definitions without a TOML parser: adding one is an audit +// decision in this repo, and the guards need only headers, `depends` and +// body text. + +export const parseStringArray = (inner) => + [...inner.matchAll(/"([^"]+)"|'([^']+)'/g)].map((m) => m[1] ?? m[2]) + +// A whole line that names a table. A line of a multi-line `run` string can +// also start with `[`, such as `[ -n "$x" ] || exit 1`, and is not a header. +const TABLE_HEADER = String.raw`\[(?:tasks\.)?(?:"[^"]+"|[\w:.-]+)\][ \t]*(?:#[^\n]*)?$` +const BEFORE_HEADER = new RegExp(`^(?=${TABLE_HEADER})`, 'm') + +export function parseIncludes(miseText) { + const section = new RegExp( + String.raw`^\[task_config\][^\n]*\n([\s\S]*?)(?=^${TABLE_HEADER}|$(?![\s\S]))`, + 'm', + ).exec(miseText) + const array = /^includes\s*=\s*\[([^\]]*)\]/m.exec(section?.[1] ?? '') + return array ? parseStringArray(array[1]) : [] +} + +/** + * The two dialects must not be merged. In `mise.toml` a task is + * `[tasks."name"]`, and a bare `[tools]` or `[env]` is configuration. In a + * file named by `includes`, every top-level table is a task, `["name"]`, and + * mise rejects `[tasks."name"]` there. Pass `bareTables: true` for such a file. + */ +export function parseTomlTasks(text, { bareTables }) { + const header = bareTables + ? /^\[(?:"([^"]+)"|([\w:.-]+))\]/ + : /^\[tasks\.(?:"([^"]+)"|([\w:.-]+))\]/ + return text + .split(BEFORE_HEADER) + .map((block) => ({ match: header.exec(block), block })) + .filter(({ match }) => match) + .map(({ match, block }) => ({ name: match[1] ?? match[2], block })) +} + +// Memoised: eql-suite-ci.test.mjs re-runs its reachability walk once per +// workflow, tens of thousands of calls over ~100 bodies, and without the cache +// it flakes against vitest's 5s timeout. +const strippedBodies = new Map() +export function stripCommentLines(text) { + let stripped = strippedBodies.get(text) + if (stripped === undefined) { + stripped = text.replace(/^[ \t]*#.*$/gm, '') + strippedBodies.set(text, stripped) + } + return stripped +} diff --git a/scripts/__tests__/lib/runs-on.mjs b/scripts/__tests__/lib/runs-on.mjs new file mode 100644 index 0000000000..1b7855dc99 --- /dev/null +++ b/scripts/__tests__/lib/runs-on.mjs @@ -0,0 +1,52 @@ +/** + * The RunsOn labels ADR 0004 names, and which jobs run on RunsOn. Shared by + * the guards that hold RunsOn jobs to their rules. + */ + +// biome-ignore lint/suspicious/noTemplateCurlyInString: a GitHub Actions expression, written into the label verbatim. +const RUN_ID_EXPRESSION = '${{ github.run_id }}' + +// Each Blacksmith size keeps its Ubuntu version on RunsOn. +const IMAGE_FOR_CPU = { 16: 'ubuntu22-full-x64', 4: 'ubuntu24-full-x64' } + +/** `family: 'm8a'` is for a job that ran out of memory on c8a's 2 GB per vCPU. */ +export function runsOnLabel( + cpu, + { family = 'c8a+m8a', runId = RUN_ID_EXPRESSION } = {}, +) { + const image = IMAGE_FOR_CPU[cpu] + if (!image) + throw new Error(`ADR 0004 names no RunsOn label with ${cpu} vCPUs`) + return `runs-on=${runId}/family=${family}/cpu=${cpu}/image=${image}/volume=80gb/extras=s3-cache` +} + +export const RUNS_ON_LABELS = new Set([ + runsOnLabel(16), + runsOnLabel(4), + runsOnLabel(16, { family: 'm8a' }), + runsOnLabel(4, { family: 'm8a' }), +]) + +// A guard cannot read which runner a matrix picks, so each such job is +// classified here. workflow-runs-on.test.mjs keeps this list complete. +export const MATRIX_RUNNERS = { + '.github/workflows/_build-ffi-artifacts.yml#binaries': { + runsOn: true, + reason: + 'scripts/ffi-release-matrix.mjs gives every Linux platform a RunsOn label.', + }, + '.github/workflows/_build-auth-artifacts.yml#binaries': { + runsOn: false, + reason: 'Its matrix names GitHub-hosted runners only.', + }, + '.github/workflows/tests-golang.yml#go-binding-cross': { + runsOn: false, + reason: 'Its matrix is macos-latest and windows-latest.', + }, +} + +export function isRunsOnJob(job, ref) { + const label = job?.['runs-on'] + if (typeof label === 'string' && label.startsWith('runs-on=')) return true + return MATRIX_RUNNERS[ref]?.runsOn === true +} diff --git a/scripts/__tests__/lib/workflows.mjs b/scripts/__tests__/lib/workflows.mjs index e8f933176a..40b2b9b5e4 100644 --- a/scripts/__tests__/lib/workflows.mjs +++ b/scripts/__tests__/lib/workflows.mjs @@ -1,4 +1,4 @@ -import { readdirSync, readFileSync } from 'node:fs' +import { existsSync, readdirSync, readFileSync } from 'node:fs' import { join } from 'node:path' import yaml from 'js-yaml' import { REPO_ROOT } from './repo-root.mjs' @@ -53,3 +53,24 @@ export function workflowFiles() { export function readWorkflow(relPath) { return yaml.load(readFileSync(join(REPO_ROOT, relPath), 'utf8')) } + +/** + * A step, or the steps of the local composite action it uses, expanded through + * nested local actions. A cycle between actions, or a missing manifest, adds + * no steps. + */ +export function stepsOf(step, seen = new Set()) { + const uses = typeof step?.uses === 'string' ? step.uses.trim() : '' + if (!uses.startsWith('./')) return [step] + const dir = uses.replace(/^\.\//, '').replace(/\/$/, '') + if (seen.has(dir)) return [] + seen.add(dir) + for (const file of ['action.yml', 'action.yaml']) { + const rel = `${dir}/${file}` + if (existsSync(join(REPO_ROOT, rel))) + return (readWorkflow(rel)?.runs?.steps ?? []).flatMap((inner) => + stepsOf(inner, seen), + ) + } + return [] +} diff --git a/scripts/__tests__/mise-tasks.test.mjs b/scripts/__tests__/mise-tasks.test.mjs new file mode 100644 index 0000000000..6ad9c2a169 --- /dev/null +++ b/scripts/__tests__/mise-tasks.test.mjs @@ -0,0 +1,54 @@ +import { describe, expect, it } from 'vitest' +import { parseIncludes, parseTomlTasks } from './lib/mise-tasks.mjs' + +describe('reading mise tasks', () => { + it('keeps a shell line that starts with [ inside its task', () => { + const text = [ + '[tasks."test:pg"]', + 'run = """', + 'listing=$(cargo test --list)', + '[ -n "$listing" ] || { echo "no tests" >&2; exit 1; }', + 'docker run --rm postgres:17 true', + '"""', + '', + '[tasks.other]', + 'run = "true"', + ].join('\n') + const tasks = parseTomlTasks(text, { bareTables: false }) + expect(tasks.map(({ name }) => name)).toEqual(['test:pg', 'other']) + expect(tasks[0].block).toContain('docker run --rm postgres:17 true') + }) + + it('splits at each form of table header', () => { + const text = [ + '[tools]', + 'node = "24"', + '[tasks."a:b"] # a comment', + 'run = "one"', + '[tasks.c]', + 'run = "two"', + '[env]', + 'X = "1"', + ].join('\n') + const tasks = parseTomlTasks(text, { bareTables: false }) + expect(tasks.map(({ name }) => name)).toEqual(['a:b', 'c']) + expect(tasks[1].block).not.toContain('X = "1"') + expect( + parseTomlTasks('["x"]\nrun = "1"\n[y]\nrun = "2"\n', { + bareTables: true, + }).map(({ name }) => name), + ).toEqual(['x', 'y']) + }) + + it('reads includes that span lines', () => { + const text = [ + '[task_config]', + 'includes = [', + ' "a/tasks.toml",', + " 'b',", + ']', + '[env]', + ].join('\n') + expect(parseIncludes(text)).toEqual(['a/tasks.toml', 'b']) + }) +}) diff --git a/scripts/__tests__/workflow-docker-hub-login.test.mjs b/scripts/__tests__/workflow-docker-hub-login.test.mjs new file mode 100644 index 0000000000..bbe976c63e --- /dev/null +++ b/scripts/__tests__/workflow-docker-hub-login.test.mjs @@ -0,0 +1,607 @@ +import { execFileSync } from 'node:child_process' +import { existsSync, readFileSync, statSync } from 'node:fs' +import { basename, dirname, join, relative } from 'node:path' +import { describe, expect, it } from 'vitest' +import { expr } from './lib/expressions.mjs' +import { + parseIncludes, + parseStringArray, + parseTomlTasks, + stripCommentLines, +} from './lib/mise-tasks.mjs' +import { REPO_ROOT } from './lib/repo-root.mjs' +import { isRunsOnJob } from './lib/runs-on.mjs' +import { readWorkflow, stepsOf, workflowFiles } from './lib/workflows.mjs' + +/** + * Every RunsOn job logs in to Docker Hub before it pulls an image. + * + * Docker Hub refuses pulls without a login after too many from one address. + * RunsOn machines reach that limit: on #1419, Postgres shards failed with + * `toomanyrequests` before a single test ran, and failed again on a re-run. + * So a RunsOn job that may pull an image logs in first, with the + * `DOCKER_HUB_USERNAME` and `DOCKER_HUB_PASSWORD` secrets. + * + * The login must do nothing when either secret is empty. That is the case on a + * fork's pull request, and on Dependabot's, and the job must still run there. + * + * - A service or job container from Docker Hub sets `credentials` to one + * expression that reads both secrets and falls back to `fromJSON('{}')`. + * `username:` and `password:` keys do not work: GitHub rejects an empty + * value for either ("Unexpected value ''"), so the job fails at "Set up + * job". With `{}`, the runner pulls without a login. + * - Any other pull needs a `run:` step before it that pipes the password to + * `docker login --password-stdin`, and exits early when either secret is + * empty. + * + * "May pull" is decided without knowing the registry, so it fails closed. A + * step that starts or builds a container counts, whichever registry its image + * comes from. That covers a `docker` command in the step, a `docker/` action + * that pulls, a local composite action that does either, and a `mise run` of a + * task that reaches either through its body, its `depends`, or a nested + * `mise run`. A login a job did not need costs one step and nothing else. + * + * A job counts as RunsOn when its label starts with `runs-on=`. It also + * counts when `MATRIX_RUNNERS` in `lib/runs-on.mjs` says its matrix gives it + * RunsOn machines, because a matrix runner is an expression this file cannot + * read. GitHub-hosted runners are not limited this way. + * + * In a called workflow, `secrets.*` is empty unless the caller passes it. A + * login there would skip, and the job would pull anonymously with no error. + * So every caller of a workflow whose RunsOn jobs log in passes both secrets. + */ + +// --------------------------------------------------------------------------- +// What pulls an image +// --------------------------------------------------------------------------- + +/** A command that starts or builds a container, so may pull an image. */ +const PULLS = new RegExp( + [ + String.raw`\bdocker(?:-compose|\s+compose)\b[^\n]*\b(?:up|pull|run|create)\b`, + String.raw`\bdocker\s+(?:run|pull|create|build)\b`, + String.raw`\bdocker\s+buildx\s+(?:build|bake)\b`, + String.raw`\bdocker\s+container\s+(?:run|create)\b`, + String.raw`\bdocker\s+image\s+(?:pull|build)\b`, + ].join('|'), +) + +/** Comment lines gone, and each `\`-continued command on one line. */ +const commands = (script) => + stripCommentLines(script).replace(/\\\r?\n[ \t]*/g, ' ') + +/** + * `docker/` actions that pull: QEMU's binfmt image, the BuildKit image, and + * the base images of a build. Logging in and computing tags pull nothing. + */ +const PULLING_ACTION = /^docker\/(?!login-action@|metadata-action@)[\w-]+@/ + +const DOCKER_HUB_HOSTS = new Set([ + 'docker.io', + 'index.docker.io', + 'registry-1.docker.io', +]) + +/** Whether an image reference names Docker Hub, where a bare name resolves. */ +export function onDockerHub(image) { + const first = String(image).split('/')[0] + const isHost = + String(image).includes('/') && + (first.includes('.') || first.includes(':') || first === 'localhost') + return !isHost || DOCKER_HUB_HOSTS.has(first) +} + +// --------------------------------------------------------------------------- +// mise tasks +// --------------------------------------------------------------------------- + +// Tracked files only. A walk of the working tree would read gitignored +// configs such as mise.local.toml, descend into .claude/worktrees, and fail on +// a broken symbolic link anywhere in an untracked folder. +function trackedFiles(relDir = '.') { + return execFileSync('git', ['ls-files', '-z', '--', relDir], { + cwd: REPO_ROOT, + encoding: 'utf8', + }) + .split('\0') + .filter(Boolean) +} + +/** Every `mise.toml` / `mise..toml`, repo-relative. */ +const miseConfigs = () => + trackedFiles().filter((rel) => + /^\.?mise(\.[\w-]+)?\.toml$/.test(basename(rel)), + ) + +/** File tasks: `tasks/test/splinter.sh` is the task `test:splinter`. */ +function fileTasks(dir) { + const relDir = relative(REPO_ROOT, dir) + return trackedFiles(relDir) + .filter((rel) => !rel.endsWith('.toml')) + .map((rel) => ({ + name: relative(relDir, rel) + .replace(/\.[^./]+$/, '') + .split('/') + .join(':'), + block: readFileSync(join(REPO_ROOT, rel), 'utf8'), + })) +} + +/** + * Task name -> bodies. Names repeat across configs (two packages can each + * have a `setup`), so a name keeps every body, and pulls if any of them does. + * That is the fail-closed direction. + */ +function taskIndex() { + const index = new Map() + const add = ({ name, block }) => { + if (!index.has(name)) index.set(name, []) + index.get(name).push(block) + } + for (const config of miseConfigs()) { + const text = readFileSync(join(REPO_ROOT, config), 'utf8') + for (const task of parseTomlTasks(text, { bareTables: false })) add(task) + for (const include of parseIncludes(text)) { + const path = join(REPO_ROOT, dirname(config), include) + if (!existsSync(path)) continue + if (statSync(path).isDirectory()) fileTasks(path).forEach(add) + else + parseTomlTasks(readFileSync(path, 'utf8'), { + bareTables: true, + }).forEach(add) + } + } + return index +} + +// A quote starts a command only at the start of a line, as in a TOML +// `run = [ "mise run …" ]` entry. Mid-line it is a message to the reader. +const COMMAND_START = String.raw`(?:^[ \t]*["']?|(?:&&|\|\||[;|(){}])[ \t]*)` + +function invokes(text, taskName) { + const escaped = taskName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + return new RegExp( + `${COMMAND_START}mise\\s+run\\s+[^\\n'"]*?(? + [...body.matchAll(/depends\s*=\s*\[([^\]]*)\]/g)].flatMap((m) => + parseStringArray(m[1]), + ) + +/** The names of every task that may pull an image, directly or through others. */ +function pullingTasks(index) { + const pulling = new Set( + [...index] + .filter(([, bodies]) => bodies.some((body) => PULLS.test(commands(body)))) + .map(([name]) => name), + ) + // Grow the set until nothing new reaches a member: a fixpoint, so a cycle + // between tasks cannot loop. + let grew = true + while (grew) { + grew = false + for (const [name, bodies] of index) { + if (pulling.has(name)) continue + const reaches = bodies.some( + (body) => + dependsOf(body).some((dep) => pulling.has(dep)) || + [...pulling].some((target) => invokes(body, target)), + ) + if (reaches) { + pulling.add(name) + grew = true + } + } + } + return pulling +} + +const PULLING_TASKS = pullingTasks(taskIndex()) + +// Pulls this file cannot find, because test code or a README the test runs +// starts the container. Each named step counts as a pull. +export const HIDDEN_PULLS = { + '.github/workflows/prisma-example-readme-e2e.yml#walkthrough': [ + { + step: 'Run README walkthrough e2e', + reason: + "e2e/tests/prisma-example-readme.e2e.test.ts runs the Prisma example's README, whose `docker compose up -d` pulls postgres:16.", + }, + ], + '.github/workflows/tests.yml#e2e-tests': [ + { + step: 'Run E2E tests', + reason: 'e2e/vitest.config.ts includes the same README walkthrough test.', + }, + { + step: 'Run the credentialed Migration Harness self-test', + reason: + 'With HARNESS_LIVE=1, e2e/migration-harness runs postgres:17-alpine and node:22-bookworm-slim, and builds an image from node:22-bookworm-slim.', + }, + ], +} + +const isHiddenPull = (ref, step) => + (HIDDEN_PULLS[ref] ?? []).some((hidden) => hidden.step === step?.name) + +// --------------------------------------------------------------------------- +// Steps and jobs +// --------------------------------------------------------------------------- + +/** Whether one step, or the local composite action it uses, may pull an image. */ +export function stepPulls(step) { + return stepsOf(step).some((inner) => { + const uses = typeof inner?.uses === 'string' ? inner.uses.trim() : '' + if (PULLING_ACTION.test(uses)) return true + const run = typeof inner?.run === 'string' ? commands(inner.run) : '' + return ( + PULLS.test(run) || [...PULLING_TASKS].some((task) => invokes(run, task)) + ) + }) +} + +const USERNAME = expr('secrets.DOCKER_HUB_USERNAME') +const PASSWORD = expr('secrets.DOCKER_HUB_PASSWORD') + +/** Whether a step logs in to Docker Hub, and does nothing without the secrets. */ +export function loginFinding(step) { + const run = typeof step?.run === 'string' ? step.run : '' + if (!/\bdocker\s+login\b/.test(run)) return 'not a login' + if ( + step.env?.DOCKER_HUB_USERNAME !== USERNAME || + step.env?.DOCKER_HUB_PASSWORD !== PASSWORD + ) + return `does not read ${USERNAME} and ${PASSWORD} into DOCKER_HUB_USERNAME and DOCKER_HUB_PASSWORD` + if (!/--password-stdin/.test(run)) + return 'does not pass the password on stdin' + if ( + !/-z\s+"\$DOCKER_HUB_USERNAME"/.test(run) || + !/-z\s+"\$DOCKER_HUB_PASSWORD"/.test(run) + ) + return 'does not skip the login when a secret is empty, so a fork pull request would fail' + return null +} + +/** + * Whether a step logs out of Docker Hub even when an earlier step failed. The + * login stores the password in the Docker config file, where every later + * step's code can read it. + */ +export function logoutFinding(step) { + const run = typeof step?.run === 'string' ? step.run : '' + if (!/\bdocker\s+logout\b/.test(run)) return 'not a logout' + if (!/\balways\(\)/.test(String(step.if ?? ''))) + return 'logs out of Docker Hub only when every earlier step passed; add always() to its if' + return null +} + +/** Whether a container's `credentials` log in, and still work without the secrets. */ +export function credentialsFinding(credentials) { + if (credentials === undefined) return 'sets no credentials' + if (typeof credentials !== 'string') + return "sets username and password keys, which fail at 'Set up job' when a secret is empty; use one expression with a fromJSON('{}') fallback" + const flat = credentials.replace(/\s+/g, ' ') + if ( + !flat.includes('secrets.DOCKER_HUB_USERNAME') || + !flat.includes('secrets.DOCKER_HUB_PASSWORD') + ) + return 'does not read secrets.DOCKER_HUB_USERNAME and secrets.DOCKER_HUB_PASSWORD' + if (!flat.includes("|| fromJSON('{}')")) + return "has no || fromJSON('{}') fallback for when a secret is empty" + return null +} + +/** Every finding for one job, or [] when it is correct. */ +export function jobFindings(where, job, ref) { + if (!isRunsOnJob(job, ref)) return [] + const findings = [] + const containers = [ + ...Object.entries(job.services ?? {}).map(([name, svc]) => [ + `service ${name}`, + svc, + ]), + ...(job.container ? [['container', job.container]] : []), + ] + for (const [what, def] of containers) { + const image = typeof def === 'string' ? def : def?.image + if (!image || !onDockerHub(image)) continue + const finding = credentialsFinding(def?.credentials) + if (finding) + findings.push( + `${where}: ${what} pulls ${image} from Docker Hub, and ${finding}`, + ) + } + const steps = job.steps ?? [] + const pulls = (step) => stepPulls(step) || isHiddenPull(ref, step) + const firstPull = steps.findIndex(pulls) + if (firstPull === -1) return findings + const logins = steps + .map((step, i) => ({ i, finding: loginFinding(step) })) + .filter(({ finding }) => finding !== 'not a login') + for (const { i, finding } of logins) + if (finding) findings.push(`${where}: step ${i + 1} ${finding}`) + const nameOf = (i) => steps[i].name ?? steps[i].uses ?? 'run' + if (!logins.some(({ i }) => i < firstPull)) + findings.push( + `${where}: step ${firstPull + 1} (${nameOf(firstPull)}) may pull an image, and no Docker Hub login comes before it`, + ) + if (logins.length === 0) return findings + const lastPull = steps.findLastIndex(pulls) + const logouts = steps + .map((step, i) => ({ i, finding: logoutFinding(step) })) + .filter(({ finding }) => finding !== 'not a logout') + for (const { i, finding } of logouts) { + if (finding) findings.push(`${where}: step ${i + 1} ${finding}`) + if (i < lastPull) + findings.push( + `${where}: step ${i + 1} logs out of Docker Hub before step ${lastPull + 1} (${nameOf(lastPull)}), which may pull an image`, + ) + } + if (!logouts.some(({ i, finding }) => i > lastPull && finding === null)) + findings.push( + `${where}: no Docker Hub logout with if: always() comes after step ${lastPull + 1} (${nameOf(lastPull)}), the last step that may pull an image`, + ) + return findings +} + +function runsOnJobs() { + return workflowFiles().flatMap((file) => + Object.entries(readWorkflow(file)?.jobs ?? {}) + .map(([name, job]) => ({ + where: `${file} ${name}`, + ref: `${file}#${name}`, + job, + })) + .filter(({ job, ref }) => isRunsOnJob(job, ref)), + ) +} + +/** Whether a calling job passes both Docker Hub secrets to the workflow it calls. */ +export function callerFinding(job) { + if (job?.secrets === 'inherit') return null + const passed = job?.secrets ?? {} + const missing = [ + ['DOCKER_HUB_USERNAME', USERNAME], + ['DOCKER_HUB_PASSWORD', PASSWORD], + ] + .filter(([name, value]) => passed[name] !== value) + .map(([name]) => name) + return missing.length + ? `does not pass ${missing.join(' and ')} to the workflow it calls, so its login would skip` + : null +} + +/** Each local workflow call whose called RunsOn jobs log in, and what it lacks. */ +function callerFindings() { + return workflowFiles().flatMap((file) => + Object.entries(readWorkflow(file)?.jobs ?? {}) + .filter(([, job]) => + String(job?.uses ?? '').startsWith('./.github/workflows/'), + ) + .flatMap(([name, job]) => { + const called = job.uses.replace(/^\.\//, '').replace(/@.*$/, '') + const logsIn = Object.entries(readWorkflow(called)?.jobs ?? {}).some( + ([id, calledJob]) => + isRunsOnJob(calledJob, `${called}#${id}`) && + (calledJob.steps ?? []).some((step) => loginFinding(step) === null), + ) + const finding = logsIn ? callerFinding(job) : null + return finding ? [`${file}#${name}: ${finding}`] : [] + }), + ) +} + +// --------------------------------------------------------------------------- + +describe('Docker Hub login on RunsOn', () => { + const jobs = runsOnJobs() + + it('finds the jobs it checks', () => { + // A discovery test that finds nothing passes having checked nothing. + expect(jobs.length).toBeGreaterThan(50) + expect( + jobs.filter(({ job }) => (job.steps ?? []).some((s) => stepPulls(s))) + .length, + ).toBeGreaterThan(8) + expect(PULLING_TASKS).toContain('postgres:up') + expect(PULLING_TASKS).toContain('setup') + }) + + it('logs in before every pull', () => { + expect( + jobs.flatMap(({ where, job, ref }) => jobFindings(where, job, ref)), + ).toEqual([]) + }) + + it('passes the Docker Hub secrets to every called workflow whose RunsOn jobs log in', () => { + expect(callerFindings()).toEqual([]) + }) + + it('names a RunsOn job and a real step for every hidden pull', () => { + // A stale entry would stop guarding the pull it was written for. + const stale = Object.entries(HIDDEN_PULLS).flatMap(([ref, hidden]) => { + const entry = jobs.find((j) => j.ref === ref) + return hidden + .filter( + ({ step }) => !(entry?.job.steps ?? []).some((s) => s?.name === step), + ) + .map(({ step }) => `${ref} ${step}`) + }) + expect(stale).toEqual([]) + }) + + // Every job in the tree is correct, so the test above runs none of the + // branches that report a wrong one. These do. + const runsOn = 'runs-on=1/family=c8a+m8a/cpu=8' + const login = { + name: 'Log in to Docker Hub', + env: { DOCKER_HUB_USERNAME: USERNAME, DOCKER_HUB_PASSWORD: PASSWORD }, + run: [ + 'if [ -z "$DOCKER_HUB_USERNAME" ] || [ -z "$DOCKER_HUB_PASSWORD" ]; then', + ' exit 0', + 'fi', + 'printf \'%s\' "$DOCKER_HUB_PASSWORD" |', + ' docker login --username "$DOCKER_HUB_USERNAME" --password-stdin', + ].join('\n'), + } + const up = { name: 'Start Postgres', run: 'mise run postgres:up' } + const logout = { + name: 'Log out of Docker Hub', + if: 'always()', + run: 'docker logout', + } + + it('reports a pull with no login before it', () => { + expect(jobFindings('w j', { 'runs-on': runsOn, steps: [up] })).toEqual([ + expect.stringMatching(/no Docker Hub login comes before it/), + ]) + expect( + jobFindings('w j', { 'runs-on': runsOn, steps: [up, login, logout] }), + ).toEqual([expect.stringMatching(/no Docker Hub login comes before it/)]) + expect( + jobFindings('w j', { 'runs-on': runsOn, steps: [login, up, logout] }), + ).toEqual([]) + // Not RunsOn: out of scope. + expect( + jobFindings('w j', { 'runs-on': 'ubuntu-latest', steps: [up] }), + ).toEqual([]) + // A matrix runner that MATRIX_RUNNERS marks as RunsOn is in scope. + expect( + jobFindings( + 'w j', + // biome-ignore lint/suspicious/noTemplateCurlyInString: a GitHub Actions expression, the literal `runs-on` value under test. + { 'runs-on': '${{ matrix.cfg.os }}', steps: [up] }, + '.github/workflows/_build-ffi-artifacts.yml#binaries', + ), + ).toEqual([expect.stringMatching(/no Docker Hub login comes before it/)]) + }) + + it('reports a login with no logout after the last pull', () => { + const job = (...steps) => ({ 'runs-on': runsOn, steps }) + expect(jobFindings('w j', job(login, up))).toEqual([ + expect.stringMatching( + /no Docker Hub logout with if: always\(\) comes after step 2 \(Start Postgres\)/, + ), + ]) + expect( + jobFindings('w j', job(login, up, { ...logout, if: undefined })), + ).toEqual([ + expect.stringMatching(/step 3 logs out .* add always\(\) to its if/), + expect.stringMatching(/no Docker Hub logout with if: always\(\)/), + ]) + expect(jobFindings('w j', job(login, up, logout, up))).toEqual([ + expect.stringMatching(/step 3 logs out of Docker Hub before step 4/), + expect.stringMatching(/no Docker Hub logout .* after step 4/), + ]) + // A matrix leg's own condition may sit beside always(). + expect( + logoutFinding({ + ...logout, + // biome-ignore lint/suspicious/noTemplateCurlyInString: a GitHub Actions expression under test. + if: "${{ always() && startsWith(matrix.cfg.os, 'runs-on=') }}", + }), + ).toBeNull() + }) + + it('reports a call that does not pass both secrets', () => { + const uses = './.github/workflows/x.yml' + expect(callerFinding({ uses })).toMatch(/DOCKER_HUB_USERNAME/) + expect(callerFinding({ uses, secrets: 'inherit' })).toBeNull() + expect( + callerFinding({ + uses, + secrets: { + DOCKER_HUB_USERNAME: USERNAME, + DOCKER_HUB_PASSWORD: PASSWORD, + }, + }), + ).toBeNull() + expect( + callerFinding({ uses, secrets: { DOCKER_HUB_USERNAME: USERNAME } }), + ).toMatch(/DOCKER_HUB_PASSWORD/) + }) + + it('reports a login that would fail on a fork pull request', () => { + const noSkip = { + ...login, + run: 'printf \'%s\' "$DOCKER_HUB_PASSWORD" | docker login --username "$DOCKER_HUB_USERNAME" --password-stdin', + } + expect(loginFinding(noSkip)).toMatch(/fork pull request/) + expect(loginFinding({ ...login, env: {} })).toMatch(/does not read/) + expect(loginFinding(login)).toBeNull() + }) + + it('reports a Docker Hub service with no credentials', () => { + const job = (credentials) => ({ + 'runs-on': runsOn, + services: { pg: { image: 'postgres:17', credentials } }, + steps: [], + }) + expect(jobFindings('w j', job(undefined))).toEqual([ + expect.stringMatching( + /service pg pulls postgres:17.*sets no credentials/, + ), + ]) + // The form GitHub rejects when a secret is empty. + expect( + jobFindings('w j', job({ username: USERNAME, password: PASSWORD })), + ).toEqual([expect.stringMatching(/fail at 'Set up job'/)]) + const flat = `secrets.DOCKER_HUB_USERNAME != '' && secrets.DOCKER_HUB_PASSWORD != '' && fromJSON(format('{{"username":{0},"password":{1}}}', toJSON(secrets.DOCKER_HUB_USERNAME), toJSON(secrets.DOCKER_HUB_PASSWORD)))` + expect(jobFindings('w j', job(expr(flat)))).toEqual([ + expect.stringMatching(/no \|\| fromJSON\('\{\}'\) fallback/), + ]) + expect(jobFindings('w j', job(expr(`${flat} || fromJSON('{}')`)))).toEqual( + [], + ) + expect( + jobFindings('w j', { + 'runs-on': runsOn, + services: { pg: { image: 'ghcr.io/cipherstash/postgres-eql:17' } }, + steps: [], + }), + ).toEqual([]) + }) + + it('recognises what may pull an image', () => { + expect( + stepPulls({ run: 'docker compose -p x -f y.yml up -d --wait' }), + ).toBe(true) + expect(stepPulls({ run: 'docker run --rm alpine true' })).toBe(true) + expect( + stepPulls({ run: 'mise run --output prefix postgres:up pg-17' }), + ).toBe(true) + expect(stepPulls({ uses: './.github/actions/integration-db' })).toBe(true) + expect(stepPulls({ uses: 'docker/setup-qemu-action@abc' })).toBe(true) + expect(stepPulls({ uses: 'docker/login-action@abc' })).toBe(false) + for (const run of [ + 'docker compose \\\n -f x.yml \\\n up -d', + 'docker compose -f x.yml pull', + 'docker compose run --rm app true', + 'docker compose create', + 'docker-compose run app true', + 'docker-compose pull', + 'docker buildx bake', + 'docker container run --rm alpine true', + 'docker container create alpine', + 'docker image pull alpine', + 'mise run \\\n postgres:up', + ]) + expect({ run, pulls: stepPulls({ run }) }).toEqual({ run, pulls: true }) + expect(stepPulls({ run: 'docker exec -i pg psql -f-' })).toBe(false) + expect(stepPulls({ run: 'docker compose logs pg' })).toBe(false) + expect(stepPulls({ run: 'docker compose down' })).toBe(false) + expect(stepPulls({ run: '# docker run in a comment' })).toBe(false) + }) + + it('reads which registry an image names', () => { + expect(onDockerHub('postgres:17')).toBe(true) + expect(onDockerHub('supabase/postgres:17.4.1.048')).toBe(true) + expect(onDockerHub('docker.io/library/postgres:17')).toBe(true) + expect(onDockerHub('ghcr.io/cipherstash/postgres-eql:17')).toBe(false) + expect(onDockerHub('public.ecr.aws/docker/library/postgres:17')).toBe(false) + expect(onDockerHub('localhost:5000/pg')).toBe(false) + }) +}) diff --git a/scripts/__tests__/workflow-mise-cache-image.test.mjs b/scripts/__tests__/workflow-mise-cache-image.test.mjs index 4007ba9d3c..3d7f417b2a 100644 --- a/scripts/__tests__/workflow-mise-cache-image.test.mjs +++ b/scripts/__tests__/workflow-mise-cache-image.test.mjs @@ -8,9 +8,9 @@ import { readWorkflow, workflowFiles } from './lib/workflows.mjs' * Every cached `jdx/mise-action` step keys its cache by runner image. * * mise-action's default key is `mise-v1-----`. It names Linux, not the distro, so a job on - * `blacksmith-*-ubuntu-2404` (glibc 2.39) and one on `…-ubuntu-2204` (glibc - * 2.35) read and write the same entry. The `cargo:` tools in `mise.test.toml` + * of the mise config>`. It names Linux, not the distro, so a job on a RunsOn + * `image=ubuntu24-full-x64` machine (glibc 2.39) and one on + * `image=ubuntu22-full-x64` (glibc 2.35) read and write the same entry. The `cargo:` tools in `mise.test.toml` * are built where they are installed, so whichever job saves the key first * decides what glibc every other job's `cargo-nextest` and `cargo-llvm-cov` * need. When a 2404 job (fuzz, udeps) wins, every 2204 job dies with @@ -24,8 +24,9 @@ import { readWorkflow, workflowFiles } from './lib/workflows.mjs' * * So each cached step sets `cache_key_prefix: mise-v1-`, where `` * is the `ubuntu-NNNN` its job's `runs-on` names (`ubuntu-24.04` counts as - * `ubuntu-2404`). A job whose `runs-on` names no image (a matrix, - * `ubuntu-latest`) must turn the cache off. No step sets `cache_key`, which + * `ubuntu-2404`, and so does a RunsOn label's `image=ubuntu24-full-x64`). A job + * whose `runs-on` names no image (a matrix, `ubuntu-latest`, a RunsOn label with + * no `image=`) must turn the cache off. No step sets `cache_key`, which * mise-action prefers over the prefix and so would bring the shared key back. * A step with the cache off sets no prefix: it would read as a cache in use, * on paths `scripts/lint-no-workflow-caching.mjs` keeps cache-free. @@ -63,7 +64,14 @@ const IMAGE_INDEPENDENT_TOOLS = new Set(['aqua:wasm-bindgen/wasm-pack']) /** The `ubuntu-NNNN` a runs-on label names, or undefined. */ function imageOf(runsOn) { - const m = /ubuntu-(\d{2})\.?(\d{2})/.exec(String(runsOn)) + const label = String(runsOn) + // RunsOn takes its image from an `image=` segment, and ships only LTS ones. + // With no segment it uses the stack's default, which the label cannot show. + if (label.startsWith('runs-on=')) { + const m = /\/image=ubuntu(\d{2})-/.exec(label) + return m ? `ubuntu-${m[1]}04` : undefined + } + const m = /ubuntu-(\d{2})\.?(\d{2})/.exec(label) return m ? `ubuntu-${m[1]}${m[2]}` : undefined } @@ -149,6 +157,22 @@ describe('mise-action cache keys', () => { expect(imageOf(undefined)).toBeUndefined() }) + it('reads the image of a RunsOn label', () => { + expect( + imageOf( + // biome-ignore lint/suspicious/noTemplateCurlyInString: a GitHub Actions expression, the literal `runs-on` value under test. + 'runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=8/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache', + ), + ).toBe('ubuntu-2204') + expect(imageOf('runs-on=1/family=c8a/cpu=4/image=ubuntu24-full-x64')).toBe( + 'ubuntu-2404', + ) + // No `image=`: RunsOn uses the stack's default image, which the label + // does not name, so the cache must be off. + expect(imageOf('runs-on=1/family=c8a+m8a/cpu=8')).toBeUndefined() + expect(imageOf('runs-on=1/runner=4cpu-linux-x64')).toBeUndefined() + }) + it('lets a composite action cache only image-independent tools', () => { const checked = [] const wrong = [] diff --git a/scripts/__tests__/workflow-runs-on.test.mjs b/scripts/__tests__/workflow-runs-on.test.mjs new file mode 100644 index 0000000000..278205371e --- /dev/null +++ b/scripts/__tests__/workflow-runs-on.test.mjs @@ -0,0 +1,192 @@ +import { describe, expect, it } from 'vitest' +import { + isRunsOnJob, + MATRIX_RUNNERS, + RUNS_ON_LABELS, + runsOnLabel, +} from './lib/runs-on.mjs' +import { readWorkflow, stepsOf, workflowFiles } from './lib/workflows.mjs' + +/** + * Every self-hosted job runs on a RunsOn machine of the size its Blacksmith + * job had. ADR 0004 records the decision and the two labels. + * + * - No job names a Blacksmith label. + * - Every RunsOn label is one of the labels ADR 0004 names. A job that ran out + * of memory may use the same label with `family=m8a`. Any other label, such + * as `cpu=8`, gives the job a machine of the wrong size. + * - A job whose runner comes from an expression is listed in + * `MATRIX_RUNNERS`, with whether its matrix gives it RunsOn machines. The + * other guards read that list, because they cannot see which runner a matrix + * picks. + */ + +const jobs = workflowFiles().flatMap((file) => + Object.entries(readWorkflow(file)?.jobs ?? {}).map(([id, job]) => ({ + ref: `${file}#${id}`, + job, + })), +) + +const refsWhere = (predicate) => jobs.filter(predicate).map(({ ref }) => ref) + +/** A runner chosen when the job starts, so a guard cannot read it. */ +function isExpressionRunner(job) { + const label = job?.['runs-on'] + if (label === undefined) return false + if (typeof label !== 'string') return true + return label.includes('${{') && !label.startsWith('runs-on=') +} + +const expressionRunnerRefs = () => + refsWhere(({ job }) => isExpressionRunner(job)) + +// A new RunsOn machine can still be running apt from boot. apt-get fails at +// once on the held lock unless told to wait for it. +const APT_COMMAND = + /\bapt(?:-get)?\s.*\b(?:update|install|upgrade|dist-upgrade|remove|purge|autoremove)\b/ + +// DPkg::Lock::Timeout covers only the dpkg locks. apt-get update takes the +// package-list lock without waiting, whatever the option says, so it must +// be retried in a loop that ends with `&& break`. +// +// `update` must be the subcommand: options, each with an optional value, may +// come before it, but a package name such as update-notifier-common is not it. +const APT_UPDATE = + /\bapt(?:-get)?\s+(?:-\S+\s+(?:(?!-)\S+\s+)?)*update(?![\w-])/ + +export function aptFinding(run) { + const joined = String(run).replace(/\\\r?\n[ \t]*/g, ' ') + for (const line of joined.split('\n')) { + if (/^\s*#/.test(line)) continue + if (APT_COMMAND.test(line) && !line.includes('DPkg::Lock::Timeout=')) + return `runs apt without waiting for the lock: "${line.trim()}". Add -o DPkg::Lock::Timeout=300.` + if (APT_UPDATE.test(line) && !/&&\s*break\b/.test(line)) + return `runs apt-get update without retrying it: "${line.trim()}". It does not wait for the package-list lock, so retry it in a loop with && break.` + } + return null +} + +export function aptFindingsInRunsOnJobs() { + return jobs + .filter(({ job, ref }) => isRunsOnJob(job, ref)) + .flatMap(({ ref, job }) => + (job.steps ?? []).flatMap((step, i) => + stepsOf(step) + .map((inner) => aptFinding(inner?.run ?? '')) + .filter(Boolean) + .map((finding) => `${ref} step ${i + 1}: ${finding}`), + ), + ) +} + +describe('RunsOn runner labels', () => { + it('builds the labels ADR 0004 names', () => { + expect(runsOnLabel(16)).toBe( + // biome-ignore lint/suspicious/noTemplateCurlyInString: a GitHub Actions expression, the literal `runs-on` value under test. + 'runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache', + ) + expect(runsOnLabel(4)).toBe( + // biome-ignore lint/suspicious/noTemplateCurlyInString: a GitHub Actions expression, the literal `runs-on` value under test. + 'runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache', + ) + expect(runsOnLabel(4, { family: 'm8a' })).toBe( + // biome-ignore lint/suspicious/noTemplateCurlyInString: a GitHub Actions expression, the literal `runs-on` value under test. + 'runs-on=${{ github.run_id }}/family=m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache', + ) + expect(() => runsOnLabel(8)).toThrow() + }) + + it('finds the jobs it checks', () => { + // A scan that finds nothing passes every check below. + expect( + jobs.filter(({ job, ref }) => isRunsOnJob(job, ref)).length, + ).toBeGreaterThan(50) + }) + + it('names no Blacksmith label', () => { + // JSON.stringify also covers a runs-on that is a list or an object. + expect( + refsWhere(({ job }) => + /blacksmith-/.test(JSON.stringify(job?.['runs-on'] ?? '')), + ), + ).toEqual([]) + }) + + it('uses only the labels ADR 0004 names', () => { + expect( + refsWhere(({ job }) => { + const label = job?.['runs-on'] + return ( + typeof label === 'string' && + label.startsWith('runs-on=') && + !RUNS_ON_LABELS.has(label) + ) + }), + ).toEqual([]) + }) + + it('lists every job whose runner comes from an expression', () => { + // Both directions: a new matrix job must be listed, and an entry whose + // job is gone must be removed. + expect(expressionRunnerRefs().sort()).toEqual( + Object.keys(MATRIX_RUNNERS).sort(), + ) + expect( + Object.values(MATRIX_RUNNERS).every(({ reason }) => reason.trim()), + ).toBe(true) + }) +}) + +describe('apt on a new RunsOn machine', () => { + it('recognises an apt command that does not wait for the lock', () => { + expect(aptFinding('sudo apt-get update')).toMatch(/DPkg::Lock::Timeout/) + expect(aptFinding('sudo apt install -y jq')).toMatch(/DPkg::Lock::Timeout/) + expect( + aptFinding('sudo apt-get -o DPkg::Lock::Timeout=300 install -y doxygen'), + ).toBeNull() + expect(aptFinding('# sudo apt-get update')).toBeNull() + expect(aptFinding('apt-cache policy doxygen')).toBeNull() + }) + + it('recognises an apt-get update that is not retried', () => { + expect( + aptFinding('sudo apt-get -o DPkg::Lock::Timeout=300 update'), + ).toMatch(/&& break/) + expect( + aptFinding(' sudo apt-get -o DPkg::Lock::Timeout=300 update && break'), + ).toBeNull() + expect( + aptFinding('sudo apt-get -o DPkg::Lock::Timeout=300 upgrade -y'), + ).toBeNull() + expect( + aptFinding('sudo apt-get -q -o DPkg::Lock::Timeout=300 update'), + ).toMatch(/&& break/) + // A package whose name starts with "update" is not an update. + expect( + aptFinding( + 'sudo apt-get -o DPkg::Lock::Timeout=300 install -y update-notifier-common', + ), + ).toBeNull() + }) + + it('reads a command continued with a backslash as one line', () => { + expect( + aptFinding( + 'sudo apt-get install -y \\\n -o DPkg::Lock::Timeout=300 doxygen', + ), + ).toBeNull() + expect( + aptFinding( + 'sudo apt-get -o DPkg::Lock::Timeout=300 update \\\n && break', + ), + ).toBeNull() + expect(aptFinding('sudo apt-get install -y \\\n doxygen')).toMatch( + /DPkg::Lock::Timeout/, + ) + }) + + it('waits for the apt lock in every RunsOn job', () => { + expect(aptFindingsInRunsOnJobs()).toEqual([]) + }) +}) diff --git a/scripts/ffi-release-matrix.mjs b/scripts/ffi-release-matrix.mjs index c4475fbf7e..d66dcca42a 100644 --- a/scripts/ffi-release-matrix.mjs +++ b/scripts/ffi-release-matrix.mjs @@ -44,15 +44,21 @@ const PLATFORMS_DIR = join( /** * Where each platform builds. * - * Linux goes to Blacksmith (the repo's standard Linux runner); the Darwin and - * Windows builds need GitHub-hosted images for their SDKs. Both Darwin - * platforms share `macos-latest` and cross-compile — which is exactly why - * `target` is explicit. + * Darwin and Windows need GitHub-hosted images for their SDKs; both Darwin + * platforms share `macos-latest` and cross-compile, which is why `target` is + * explicit. Every Linux platform builds on a RunsOn machine with 4 vCPUs, its + * size on Blacksmith (docs/adr/0004). A matrix value cannot read + * `${{ github.run_id }}`, so the run ID that makes the RunsOn label unique is + * passed in. */ -export function runnerFor(platform) { +export function runnerFor(platform, runId = process.env.GITHUB_RUN_ID) { if (platform.startsWith('win32')) return 'windows-latest' if (platform.startsWith('darwin')) return 'macos-latest' - return 'blacksmith-4vcpu-ubuntu-2404' + if (!runId) + throw new Error( + `${platform} builds on RunsOn, whose label needs the run ID; set GITHUB_RUN_ID`, + ) + return `runs-on=${runId}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache` } /** @@ -97,11 +103,11 @@ export function triplesFromPlatformManifests(dir = PLATFORMS_DIR) { * `triples` is a platform name -> Rust target triple mapping, as * `triplesFromPlatformManifests()` (or `neon list-platforms`) produces. */ -export function releaseMatrix(triples) { +export function releaseMatrix(triples, runId = process.env.GITHUB_RUN_ID) { return Object.entries(triples).map(([platform, target]) => ({ platform, target, - os: runnerFor(platform), + os: runnerFor(platform, runId), ...buildFor(platform), })) } diff --git a/scripts/lint-no-workflow-caching.mjs b/scripts/lint-no-workflow-caching.mjs index 2fbb7d88b8..cfaf2d3140 100644 --- a/scripts/lint-no-workflow-caching.mjs +++ b/scripts/lint-no-workflow-caching.mjs @@ -80,10 +80,10 @@ const PARENT_USES = /^\.\.\// // `actions/cache*`, and an action that takes a `cache:` input. A third-party // cache action has neither, so it was invisible to the whole file. Reproduced // against a composite reached from a targeted workflow holding -// `useblacksmith/cache@v5` and `Swatinem/rust-cache@v2`: `OK`, exit 0. Both are -// live-relevant here — eleven jobs in this repo run on `blacksmith-*` runners, -// where `useblacksmith/cache` is the documented drop-in for `actions/cache`, -// and the absorbed Cargo workspace at `languages/typescript/packages/protect-ffi` is exactly where +// `useblacksmith/cache@v5` and `Swatinem/rust-cache@v2`: `OK`, exit 0. Both +// kinds are live-relevant here. The self-hosted jobs in this repo run on +// RunsOn, whose `runs-on/cache` is a drop-in for `actions/cache`, as +// `useblacksmith/cache` is on Blacksmith. And the absorbed Cargo workspace at `languages/typescript/packages/protect-ffi` is exactly where // someone reaches for `Swatinem/rust-cache`. // // The obvious repair is to enumerate the cache actions — by name diff --git a/skills/stash-supply-chain-security/SKILL.md b/skills/stash-supply-chain-security/SKILL.md index a5f63d371b..c7060aa63e 100644 --- a/skills/stash-supply-chain-security/SKILL.md +++ b/skills/stash-supply-chain-security/SKILL.md @@ -209,15 +209,18 @@ npm ≥ 11.5.1, no Actions cache. `optionalDependencies` are exact versions, so publishing it first exposes a version whose binaries do not exist yet. - `ffi-preflight.yml` is the dry run — `changeset publish` has no `--dry-run`. - Dispatch it against a Version Packages branch and it builds the real tarballs, - checks each binary's architecture and libc, installs the host pair and loads - it. It cannot publish, and "no `id-token`" is only half of why: that closes - the OIDC path, while a plain `NPM_TOKEN` would still authenticate one. Both - are absent — the workflow grants `contents: read`, passes no secrets (no - `secrets: inherit` on its call into the build workflow), sets no - `registry-url` (which is what writes an `_authToken` line into `.npmrc`), and - names no `NPM_TOKEN` or `NODE_AUTH_TOKEN`. Keep it that way; adding any one of - them turns a dry run into a publisher. + Dispatched against a Version Packages branch, it builds the real tarballs, + checks each binary's architecture and libc, then installs and loads the host + pair. It cannot publish. "No `id-token`" is only half of why. It closes the + OIDC path, but a plain `NPM_TOKEN` would still authenticate a publish. Both + paths are absent. The workflow grants only `contents: read`, and names no + `NPM_TOKEN` or `NODE_AUTH_TOKEN`. It sets no `registry-url`. That setting is + what writes an `_authToken` line into `.npmrc`. Its call into the build workflow passes + exactly two secrets, by name: `DOCKER_HUB_USERNAME` and + `DOCKER_HUB_PASSWORD`. The musl build logs in to Docker Hub with them before + it pulls Alpine. They cannot authenticate an npm publish. Keep it that way: + an `id-token` permission, `secrets: inherit`, a `registry-url`, or an npm + token would each turn the dry run into a publisher. Trusted publishing is configured **per package** on npmjs.com (package settings → Trusted publisher → GitHub Actions): owner/repo `cipherstash/stack`, workflow