Skip to content

Commit 7e7d0d4

Browse files
yotamleoclaude
andauthored
fix(ci): [OPS-732] replace gitleaks-action with CLI for fork PR support (#32)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8c52d5a commit 7e7d0d4

1 file changed

Lines changed: 32 additions & 9 deletions

File tree

.github/workflows/gitleaks.yaml

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ jobs:
99
runs-on: ubuntu-latest
1010
permissions:
1111
contents: read
12-
pull-requests: read
13-
actions: read
14-
checks: write
1512
steps:
13+
# Fork PRs need pull_request_target so GITLEAKS_LICENSE is available
14+
# (regular pull_request from a fork has no access to repo secrets).
15+
# gitleaks-action@v2 rejects pull_request_target ("event is not yet
16+
# supported"), so we run the gitleaks CLI directly. Pattern mirrors
17+
# kirin_auto/.github/workflows/gitleaks.yaml.
18+
#
19+
# Safety with pull_request_target: explicitly check out the fork's HEAD
20+
# SHA, drop persisted credentials, restrict permissions to contents:read.
21+
# Gitleaks only reads files — no fork code is executed.
1622
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4.2.2
1723
with:
1824
fetch-depth: 0
25+
filter: blob:none
1926
persist-credentials: false
2027
ref: ${{ github.event.pull_request.head.sha || github.sha }}
2128
- name: Set scan range
@@ -28,14 +35,30 @@ jobs:
2835
run: |
2936
NULL_SHA="0000000000000000000000000000000000000000"
3037
if [ "$EVENT" = "pull_request_target" ]; then
31-
echo "log_opts=${BASE_SHA}..HEAD" >> $GITHUB_OUTPUT
38+
echo "log_opts=${BASE_SHA}..HEAD" >> "$GITHUB_OUTPUT"
3239
elif [ "$BEFORE_SHA" = "$NULL_SHA" ] || [ -z "$BEFORE_SHA" ] || [ "$FORCED" = "true" ]; then
33-
echo "log_opts=" >> $GITHUB_OUTPUT
40+
echo "log_opts=" >> "$GITHUB_OUTPUT"
3441
else
35-
echo "log_opts=${BEFORE_SHA}..HEAD" >> $GITHUB_OUTPUT
42+
echo "log_opts=${BEFORE_SHA}..HEAD" >> "$GITHUB_OUTPUT"
3643
fi
37-
- uses: gitleaks/gitleaks-action@ff98106e4c7b2bc287b24eaf42907196329070c7 # v2.3.9
44+
- name: Install gitleaks
45+
env:
46+
# renovate: datasource=github-releases depName=gitleaks/gitleaks
47+
GITLEAKS_VERSION: v8.30.1
48+
run: |
49+
VERSION="${GITLEAKS_VERSION#v}"
50+
curl -sSfL \
51+
"https://github.com/gitleaks/gitleaks/releases/download/${GITLEAKS_VERSION}/gitleaks_${VERSION}_linux_x64.tar.gz" \
52+
| tar -xz gitleaks
53+
sudo mv gitleaks /usr/local/bin/gitleaks
54+
gitleaks version
55+
- name: Run gitleaks
3856
env:
39-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4057
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}
41-
GITLEAKS_LOG_OPTS: ${{ steps.range.outputs.log_opts }}
58+
LOG_OPTS: ${{ steps.range.outputs.log_opts }}
59+
run: |
60+
if [ -n "$LOG_OPTS" ]; then
61+
gitleaks detect --source . --log-opts "$LOG_OPTS" --exit-code 1
62+
else
63+
gitleaks detect --source . --exit-code 1
64+
fi

0 commit comments

Comments
 (0)