From e55cb1efa3544c662d60b06a8e133d023ede7719 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 10 Nov 2026 17:09:15 +0000 Subject: [PATCH] fix(ci): build the scanner, not the caller, in scan-and-report.yml Every repository that calls scan-and-report.yml as a reusable workflow failed at "Run scan" with exit 127: ./target/release/panic-attack did not exist. In a reusable workflow, actions/checkout with no repository checks out the caller, so "cargo build" built the caller's crate. The step worked only when this repository ran the workflow on itself. Fetch the scanner source at the commit of this workflow file (job.workflow_repository at job.workflow_sha) and build that: - a caller that pins scan-and-report.yml@ gets the scanner at that SHA, never main by name (the #212 property); - a run of this workflow in its own repository still builds the commit under test; - the source goes to the runner's temp directory, outside the workspace, so the scan cannot report on the scanner's own files. The fetch step refuses a repository that is not owner/name and a commit that is not a full SHA, and checks that the fetched HEAD is that SHA. The cache step now keys on the scanner's workspace, not the caller's. The scan step takes the target path from the environment and quotes it. No uses: reference changes, so actions.lock is unchanged. Local run of the changed steps, extracted from the workflow file (x86_64 Linux, cargo 1.97.0): the fetch at c7b1c44 succeeds and is refused for "main", a short SHA and a malformed repository; the build takes 3 min 14 s and leaves the binary; the scan of a checkout of hyperpolymath/echidna as the caller exits 0 with a schema 2.6 report (951 of 951 files) that names no scanner source path. Not shown locally: that job.workflow_sha names this repository's commit inside a call from another repository. That needs a hosted run from an external caller. Refs #276, #212 Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_0136P7ZmAsYpFA9gxfQLF3F6 Signed-off-by: Claude --- .github/workflows/scan-and-report.yml | 61 ++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/.github/workflows/scan-and-report.yml b/.github/workflows/scan-and-report.yml index 233c012d..eaa3a7ba 100644 --- a/.github/workflows/scan-and-report.yml +++ b/.github/workflows/scan-and-report.yml @@ -36,8 +36,37 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 20 steps: + # The scan target. In a reusable workflow, a checkout with no + # `repository:` is the CALLER, not this repository. - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + # The scanner source, at the commit of THIS workflow file. `job.workflow_*` + # names the workflow that defines the job: for a caller that pins + # `scan-and-report.yml@` it is this repository at that SHA, and for a + # run of this file in its own repository it is the commit under test. It is + # never `main` by name. + # + # The source goes to the runner's temp directory, outside the workspace, + # so the scan below cannot report on the scanner's own files. + - name: Fetch the scanner source at this workflow's commit + env: + SCANNER_REPOSITORY: ${{ job.workflow_repository }} + SCANNER_SHA: ${{ job.workflow_sha }} + SCANNER_SRC: ${{ runner.temp }}/panic-attack-src + GIT_TERMINAL_PROMPT: '0' + run: | + set -euo pipefail + [[ "$SCANNER_REPOSITORY" =~ ^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$ ]] \ + || { echo "::error::scanner repository is not owner/name (got '${SCANNER_REPOSITORY}'); no scanner was built"; exit 2; } + [[ "$SCANNER_SHA" =~ ^[0-9a-f]{40}$ ]] \ + || { echo "::error::scanner commit is not a full SHA (got '${SCANNER_SHA}'); no scanner was built"; exit 2; } + git init -q "$SCANNER_SRC" + git -C "$SCANNER_SRC" fetch -q --depth 1 "https://github.com/${SCANNER_REPOSITORY}.git" "$SCANNER_SHA" + git -C "$SCANNER_SRC" checkout -q --detach FETCH_HEAD + [[ "$(git -C "$SCANNER_SRC" rev-parse HEAD)" == "$SCANNER_SHA" ]] \ + || { echo "::error::fetched scanner source is not ${SCANNER_SHA}"; exit 2; } + echo "scanner source: ${SCANNER_REPOSITORY}@${SCANNER_SHA}" + - name: Install Rust uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1 with: @@ -45,20 +74,32 @@ jobs: - name: Cache Rust dependencies uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 - - # Build the commit under test, not `main`. The previous step was - # `cargo install --git … --branch main`, so every pull request was scanned - # by whatever happened to be on main at that moment: the workflow reported - # on code it had not checked out, and a PR that broke the scanner could - # pass with the last good binary. - - name: Build the commit under test - run: cargo build --locked --release + with: + # Key and save the scanner's build, not the caller's workspace. + workspaces: ${{ runner.temp }}/panic-attack-src -> target + + # Build the scanner at the fetched commit, not `main` and not the caller. + # History of this step: `cargo install --git … --branch main` scanned + # every pull request with whatever was on main (#212). Its replacement, + # `cargo build` in the workspace, built the CALLER, so every external + # caller failed at "Run scan" with exit 127 (#276). + - name: Build the scanner at this workflow's commit + env: + SCANNER_SRC: ${{ runner.temp }}/panic-attack-src + run: | + set -euo pipefail + cargo build --locked --release --manifest-path "$SCANNER_SRC/Cargo.toml" + test -x "$SCANNER_SRC/target/release/panic-attack" - name: Run scan id: scan + env: + SCANNER: ${{ runner.temp }}/panic-attack-src/target/release/panic-attack + REPO_PATH: ${{ inputs.repo_path }} run: | - ./target/release/panic-attack assail ${{ inputs.repo_path }} --output scan-result.json - echo "scan_complete=true" >> $GITHUB_OUTPUT + set -euo pipefail + "$SCANNER" assail "$REPO_PATH" --output scan-result.json + echo "scan_complete=true" >> "$GITHUB_OUTPUT" - name: Enforce severity gate if: steps.scan.outputs.scan_complete == 'true' && inputs.fail_on_severity != 'none'