From ec3df0dd8fec86e56010d1b6fbfe618ef3d7bc57 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Fri, 6 Mar 2026 14:34:36 -0500 Subject: [PATCH] CI: scope secret scans to changed files --- .github/workflows/ci.yml | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 199c6a8b1b5..a77dbeab49d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -303,13 +303,33 @@ jobs: - name: Install pre-commit run: | python -m pip install --upgrade pip - python -m pip install pre-commit detect-secrets==1.5.0 + python -m pip install pre-commit - name: Detect secrets run: | - if ! detect-secrets scan --baseline .secrets.baseline; then - echo "::error::Secret scanning failed. See docs/gateway/security.md#secret-scanning-detect-secrets" - exit 1 + set -euo pipefail + + if [ "${{ github.event_name }}" = "push" ]; then + BASE="${{ github.event.before }}" + else + BASE="${{ github.event.pull_request.base.sha }}" + fi + + changed_files=() + if git rev-parse --verify "$BASE^{commit}" >/dev/null 2>&1; then + while IFS= read -r path; do + [ -n "$path" ] || continue + [ -f "$path" ] || continue + changed_files+=("$path") + done < <(git diff --name-only --diff-filter=ACMR "$BASE" HEAD) + fi + + if [ "${#changed_files[@]}" -gt 0 ]; then + echo "Running detect-secrets on ${#changed_files[@]} changed file(s)." + pre-commit run detect-secrets --files "${changed_files[@]}" + else + echo "Falling back to full detect-secrets scan." + pre-commit run --all-files detect-secrets fi - name: Detect committed private keys