Skip to content

Commit 57c3b58

Browse files
committed
fix(ci): handle trufflehog same-commit scan fallback
1 parent 7888c48 commit 57c3b58

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,45 @@ jobs:
7070
runs-on: ubuntu-latest
7171
steps:
7272
- uses: actions/checkout@v4
73+
with:
74+
fetch-depth: 0
7375

7476
- name: Run npm audit
7577
run: npm audit --audit-level=moderate
7678
continue-on-error: true
7779

78-
- name: Check for secrets
80+
- name: Determine TruffleHog scan mode
81+
id: trufflehog-range
82+
shell: bash
83+
run: |
84+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
85+
BASE="${{ github.event.pull_request.base.sha }}"
86+
HEAD="${{ github.event.pull_request.head.sha }}"
87+
else
88+
BASE="${{ github.event.before }}"
89+
HEAD="${{ github.sha }}"
90+
fi
91+
92+
if [[ -z "$BASE" || "$BASE" == "0000000000000000000000000000000000000000" || "$BASE" == "$HEAD" ]]; then
93+
echo "mode=full" >> "$GITHUB_OUTPUT"
94+
else
95+
echo "mode=range" >> "$GITHUB_OUTPUT"
96+
echo "base=$BASE" >> "$GITHUB_OUTPUT"
97+
echo "head=$HEAD" >> "$GITHUB_OUTPUT"
98+
fi
99+
100+
- name: Check for secrets (commit range)
101+
if: steps.trufflehog-range.outputs.mode == 'range'
102+
uses: trufflesecurity/trufflehog@main
103+
with:
104+
path: ./
105+
base: ${{ steps.trufflehog-range.outputs.base }}
106+
head: ${{ steps.trufflehog-range.outputs.head }}
107+
extra_args: --debug --only-verified
108+
109+
- name: Check for secrets (full scan fallback)
110+
if: steps.trufflehog-range.outputs.mode == 'full'
79111
uses: trufflesecurity/trufflehog@main
80112
with:
81113
path: ./
82-
base: main
83-
head: HEAD
84114
extra_args: --debug --only-verified

0 commit comments

Comments
 (0)