Skip to content

Commit d025069

Browse files
MoonBoi9001claude
andauthored
fix: Resolve TruffleHog BASE/HEAD comparison failure (#11)
Fix the 'BASE and HEAD commits are the same' error in the Security Scanning workflow by implementing context-aware commit comparison: - Push events: Compare github.event.before → github.sha - Pull requests: Compare base.sha → head.sha - Scheduled runs: Compare HEAD~1 → HEAD - Handle edge cases like initial commits and new branches This resolves the workflow failure that occurred after PR merges to main where both base and head resolved to the same commit. Fixes: Security Scanning / Secrets Scan failing after PR merges 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent ee06dee commit d025069

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

.github/workflows/security.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,39 @@ jobs:
5959
steps:
6060
- name: Checkout code
6161
uses: actions/checkout@v4
62+
with:
63+
# Fetch more history for proper commit comparison
64+
fetch-depth: 0
65+
66+
- name: Determine scan range
67+
id: scan-range
68+
run: |
69+
if [ "${{ github.event_name }}" = "push" ]; then
70+
# For push events, scan from the previous commit to current commit
71+
if [ "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]; then
72+
echo "base=${{ github.event.before }}" >> $GITHUB_OUTPUT
73+
echo "head=${{ github.sha }}" >> $GITHUB_OUTPUT
74+
else
75+
# New branch or initial commit - scan just the current commit
76+
echo "base=HEAD~1" >> $GITHUB_OUTPUT
77+
echo "head=HEAD" >> $GITHUB_OUTPUT
78+
fi
79+
elif [ "${{ github.event_name }}" = "pull_request" ]; then
80+
# For PRs, scan from base branch to PR head
81+
echo "base=${{ github.event.pull_request.base.sha }}" >> $GITHUB_OUTPUT
82+
echo "head=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
83+
else
84+
# For scheduled runs, scan the last commit only
85+
echo "base=HEAD~1" >> $GITHUB_OUTPUT
86+
echo "head=HEAD" >> $GITHUB_OUTPUT
87+
fi
6288
6389
- name: Scan for secrets
6490
uses: trufflesecurity/trufflehog@main
6591
with:
6692
path: ./
67-
base: main
68-
head: HEAD
93+
base: ${{ steps.scan-range.outputs.base }}
94+
head: ${{ steps.scan-range.outputs.head }}
6995
extra_args: --only-verified
7096

7197
# =============================================================================

0 commit comments

Comments
 (0)