Skip to content

Commit 3183305

Browse files
perf(trufflehog): scan all PR changed files in one process
Run a single trufflehog filesystem invocation with the filtered path list instead of one process per file, avoiding repeated startup cost that dominated wall time on large diffs. Made-with: Cursor
1 parent 07958e8 commit 3183305

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

.github/workflows/reusable-trufflehog.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,33 @@ jobs:
147147
fi
148148
149149
if [[ -s changed-files.txt ]]; then
150+
# One TruffleHog process for all changed paths (same flags as non-PR scan). The
151+
# previous per-file loop paid full startup cost for every path, which dominated
152+
# runtime on large PRs. Paths are still filtered for excludes and missing files
153+
# (e.g. deletions in the diff).
154+
paths=()
150155
while IFS= read -r file; do
151156
if [[ -s /tmp/exclude-regexes.txt ]] && echo "$file" | grep -qEf /tmp/exclude-regexes.txt 2>/dev/null; then
152157
echo "Skipping: ${file} (matches exclude pattern)"
153158
continue
154159
fi
155-
156160
if [[ -f "${file}" ]]; then
157-
echo "Scanning: ${file}"
158-
trufflehog filesystem "${file}" --exclude-paths /tmp/trufflehog-exclude.txt --concurrency 16 --json --no-update --results=verified,unverified >> results.ndjson || true
161+
paths+=("${file}")
159162
fi
160163
done < changed-files.txt
164+
165+
if ((${#paths[@]} > 0)); then
166+
echo "Running TruffleHog on ${#paths[@]} changed file(s) in a single invocation..."
167+
trufflehog filesystem \
168+
--exclude-paths /tmp/trufflehog-exclude.txt \
169+
--concurrency 16 \
170+
--json \
171+
--no-update \
172+
--results=verified,unverified \
173+
"${paths[@]}" > results.ndjson || true
174+
else
175+
echo "No files to scan after excludes (only deletions or excluded paths)"
176+
fi
161177
else
162178
echo "No files changed"
163179
fi
@@ -379,7 +395,7 @@ jobs:
379395
id-token: write
380396
steps:
381397
- name: Get Prometheus secrets from Vault
382-
uses: grafana/shared-workflows/actions/get-vault-secrets@f1614b210386ac420af6807a997ac7f6d96e477a # get-vault-secrets/v1.3.1
398+
uses: grafana/shared-workflows/actions/get-vault-secrets@078c4a8af09e06d646077550f9e0f68171d5881e # get-vault-secrets/v1.3.1
383399
with:
384400
common_secrets: |
385401
PROMETHEUS_URL=grafana-bench:prometheus_url

0 commit comments

Comments
 (0)