Skip to content

Commit b257798

Browse files
committed
fix(ci): scope gitleaks to changed commits
1 parent b31fe02 commit b257798

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

.github/workflows/gitleaks.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,26 @@ jobs:
3939
gitleaks version
4040
4141
- name: Run gitleaks
42-
# Scan the full working tree. Returns non-zero on any finding so the
43-
# job fails the build the same way the wrapper action did.
42+
# Scan only the PR/push commit range. The checkout still fetches full
43+
# history above so these ranges resolve, but pre-existing historical
44+
# findings do not block unrelated source-only PRs.
4445
run: |
46+
set -euo pipefail
47+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
48+
log_opts="${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}"
49+
else
50+
before="${{ github.event.before }}"
51+
if [[ "$before" =~ ^0+$ ]]; then
52+
log_opts="${{ github.sha }}^..${{ github.sha }}"
53+
else
54+
log_opts="${before}..${{ github.sha }}"
55+
fi
56+
fi
57+
echo "Scanning gitleaks range: ${log_opts}"
4558
gitleaks detect \
4659
--config .gitleaks.toml \
4760
--source . \
61+
--log-opts "$log_opts" \
4862
--verbose \
4963
--redact \
5064
--report-format sarif \

0 commit comments

Comments
 (0)