Skip to content

Commit 585248a

Browse files
fix(trufflehog): fall back to workflow ref when fetching exclude patterns
The fetch step now tries main first, then the ref the calling workflow was pinned to (e.g. feature/trufflehog-global-excludes). This lets exclude patterns work during testing before the branch is merged. Made-with: Cursor
1 parent e6a675a commit 585248a

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

.github/workflows/reusable-trufflehog.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,28 @@ jobs:
5858
REPO=grafana/security-github-actions
5959
FILE_PATH=trufflehog/exclude-paths.txt
6060
61-
if gh api "repos/${REPO}/contents/${FILE_PATH}?ref=main" \
62-
-H "Accept: application/vnd.github.v3.raw" -o "${DEST}" 2>/dev/null && [[ -s "${DEST}" ]]; then
63-
echo "Loaded exclude patterns from ${REPO}@main (GitHub API)"
64-
elif curl -fsSL "https://raw.githubusercontent.com/${REPO}/main/${FILE_PATH}" \
65-
-o "${DEST}" 2>/dev/null && [[ -s "${DEST}" ]]; then
66-
echo "Loaded exclude patterns from raw.githubusercontent.com"
67-
else
68-
echo "::warning::Could not fetch TruffleHog exclude patterns from ${REPO}. Scanning without exclusions."
61+
# Resolve the ref the calling workflow used (e.g. @main, @feature/branch, @v1).
62+
CALLER_REF="main"
63+
if [[ -n "${{ github.workflow_ref }}" ]]; then
64+
CALLER_REF=$(echo "${{ github.workflow_ref }}" | sed 's|.*@||; s|^refs/heads/||; s|^refs/tags/||')
65+
fi
66+
67+
LOADED=false
68+
for REF in main "${CALLER_REF}"; do
69+
[[ "$LOADED" == "true" ]] && break
70+
if gh api "repos/${REPO}/contents/${FILE_PATH}?ref=${REF}" \
71+
-H "Accept: application/vnd.github.v3.raw" -o "${DEST}" 2>/dev/null && [[ -s "${DEST}" ]]; then
72+
echo "Loaded exclude patterns from ${REPO}@${REF} (GitHub API)"
73+
LOADED=true
74+
elif curl -fsSL "https://raw.githubusercontent.com/${REPO}/${REF}/${FILE_PATH}" \
75+
-o "${DEST}" 2>/dev/null && [[ -s "${DEST}" ]]; then
76+
echo "Loaded exclude patterns from raw.githubusercontent.com@${REF}"
77+
LOADED=true
78+
fi
79+
done
80+
81+
if [[ "$LOADED" != "true" ]]; then
82+
echo "::warning::Could not fetch TruffleHog exclude patterns from ${REPO} (tried main and ${CALLER_REF}). Scanning without exclusions."
6983
touch "${DEST}"
7084
fi
7185

0 commit comments

Comments
 (0)