diff --git a/.github/workflows/secret-scan.yml b/.github/workflows/secret-scan.yml index 05491f4..edaeaa4 100644 --- a/.github/workflows/secret-scan.yml +++ b/.github/workflows/secret-scan.yml @@ -15,11 +15,6 @@ on: permissions: contents: read -env: - GITLEAKS_VERSION: 8.30.1 - # sha256 of gitleaks_8.30.1_linux_x64.tar.gz, equal to the line in the release's checksums file. - GITLEAKS_SHA256: 551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb - jobs: gitleaks: name: Secret scan (gitleaks) @@ -31,14 +26,7 @@ jobs: fetch-depth: 0 persist-credentials: false - name: Install gitleaks (pinned version and checksum) - run: | - set -euo pipefail - file="gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" - curl --proto '=https' --tlsv1.2 -fsSL -o "$RUNNER_TEMP/$file" \ - "https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/${file}" - echo "${GITLEAKS_SHA256} $RUNNER_TEMP/$file" | sha256sum --check - - mkdir "$RUNNER_TEMP/gitleaks" - tar -xzf "$RUNNER_TEMP/$file" -C "$RUNNER_TEMP/gitleaks" gitleaks + run: bash scripts/secret-scan/install-linux.sh - name: Scan the history # Only the history reachable from the commit this run checked out, never every branch that # fetch-depth 0 brought in: a throwaway test branch must not fail other pushes or pull requests. diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index dd46d0a..b1b5e7a 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -41,6 +41,13 @@ jobs: echo "changed=true" >> "$GITHUB_OUTPUT" git diff --cached --stat fi + - name: Scan the staged documentation + if: steps.changes.outputs.changed == 'true' + # A push by the workflow token does not run the push-triggered Secret scan. + run: | + bash scripts/secret-scan/install-linux.sh + "$RUNNER_TEMP/gitleaks/gitleaks" git --staged --redact --no-banner \ + --config .gitleaks.toml --exit-code 1 - name: Check the new pages build if: steps.changes.outputs.changed == 'true' run: pnpm verify diff --git a/scripts/secret-scan/install-linux.sh b/scripts/secret-scan/install-linux.sh new file mode 100644 index 0000000..dfd7f77 --- /dev/null +++ b/scripts/secret-scan/install-linux.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -euo pipefail + +# The linux_x64 archive checksum from the pinned Gitleaks release. +version=8.30.1 +sha256=551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb +file="gitleaks_${version}_linux_x64.tar.gz" +archive="${RUNNER_TEMP:?}/$file" + +curl --proto '=https' --tlsv1.2 -fsSL -o "$archive" \ + "https://github.com/gitleaks/gitleaks/releases/download/v${version}/$file" +printf '%s %s\n' "$sha256" "$archive" | sha256sum --check - +mkdir "$RUNNER_TEMP/gitleaks" +tar -xzf "$archive" -C "$RUNNER_TEMP/gitleaks" gitleaks