@@ -3,14 +3,8 @@ name: Secret Scan (Gitleaks) [Report-Only]
33on :
44 push :
55 branches : [main, develop]
6- paths :
7- - " **/*"
8- - " .github/workflows/secret-scan-gitleaks.yml"
96 pull_request :
107 branches : [main, develop]
11- paths :
12- - " **/*"
13- - " .github/workflows/secret-scan-gitleaks.yml"
148 workflow_dispatch :
159
1610concurrency :
@@ -28,10 +22,12 @@ jobs:
2822 timeout-minutes : 15
2923
3024 env :
31- OUT_DIR : " secret-scan-reports"
32- OUT_SARIF : " gitleaks.sarif"
33- OUT_JSON : " gitleaks.json"
34- OUT_LOG : " gitleaks.log"
25+ GITLEAKS_VERSION : " 8.30.0"
26+ OUT_DIR : secret-scan-reports
27+ OUT_SARIF : gitleaks.sarif
28+ OUT_JSON : gitleaks.json
29+ OUT_LOG : gitleaks.log
30+ CONFIG_FILE : .gitleaks.toml
3531
3632 steps :
3733 - name : Checkout (full history)
@@ -40,86 +36,56 @@ jobs:
4036 fetch-depth : 0
4137
4238 - name : Ensure output folder exists
43- shell : bash
44- run : |
45- set -euo pipefail
46- mkdir -p "${OUT_DIR}"
39+ run : mkdir -p "${{ env.OUT_DIR }}"
4740
48- - name : Initialize SARIF baseline (always create file)
41+ - name : Initialize empty SARIF baseline
4942 if : always()
50- shell : bash
5143 run : |
52- set -euo pipefail
53- cat > "${OUT_DIR}/${OUT_SARIF}" << 'EOF'
44+ cat > "${{ env.OUT_DIR }}/${{ env.OUT_SARIF }}" << 'EOF'
5445 {
5546 "$schema": "https://json.schemastore.org/sarif-2.1.0.json",
5647 "version": "2.1.0",
5748 "runs": [
58- {
59- "tool": { "driver": { "name": "gitleaks", "version": "0" } },
60- "results": []
61- }
49+ { "tool": { "driver": { "name": "gitleaks", "version": "0" } }, "results": [] }
6250 ]
6351 }
6452 EOF
6553
66- - name : Run Gitleaks (report-only)
67- if : always()
68- uses : gitleaks/gitleaks-action@v2
69- continue-on-error : true
70- env :
71- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
72- GITLEAKS_ARGS : >-
73- detect
74- --source=.
75- --redact
76- --report-format=sarif
77- --report-path=${{ env.OUT_DIR }}/${{ env.OUT_SARIF }}
78- --report-path=${{ env.OUT_DIR }}/${{ env.OUT_SARIF }}
79-
80- # NOTE:
81- # gitleaks-action focuses on SARIF; to also produce JSON/log reliably,
82- # we run a second invocation via the gitleaks binary (pinned) below.
83-
8454 - name : Install Gitleaks (pinned)
8555 if : always()
86- shell : bash
8756 run : |
8857 set -euo pipefail
89- # Pinned version for repeatability
90- VER="8.21.2"
58+ VER="${{ env.GITLEAKS_VERSION }}"
9159 curl -sSL -o /tmp/gitleaks.tar.gz "https://github.com/gitleaks/gitleaks/releases/download/v${VER}/gitleaks_${VER}_linux_x64.tar.gz"
9260 tar -xzf /tmp/gitleaks.tar.gz -C /tmp gitleaks
9361 sudo mv /tmp/gitleaks /usr/local/bin/gitleaks
9462 gitleaks version
9563
96- - name : Run Gitleaks JSON + Log (report-only)
64+ - name : Run Gitleaks (SARIF + JSON + Log) [Report-Only]
9765 if : always()
98- shell : bash
9966 run : |
100- set -euo pipefail
10167 set +e
10268
103- gitleaks detect \
104- --source="." \
105- --redact \
106- --report-format="json" \
107- --report-path="${OUT_DIR}/${OUT_JSON}" \
108- 2>&1 | tee "${OUT_DIR}/${OUT_LOG}"
69+ CFG=""
70+ if [ -f "${{ env.CONFIG_FILE }}" ]; then
71+ CFG="--config=${{ env.CONFIG_FILE }}"
72+ fi
10973
110- # Never fail CI (report-only)
111- exit 0
74+ # SARIF
75+ gitleaks detect --source="." --redact $CFG \
76+ --report-format=sarif \
77+ --report-path="${{ env.OUT_DIR }}/${{ env.OUT_SARIF }}" \
78+ 2>&1 | tee "${{ env.OUT_DIR }}/${{ env.OUT_LOG }}"
11279
113- - name : Pre-upload diagnostics
114- if : always()
115- shell : bash
116- run : |
117- set -euo pipefail
118- echo "Workspace: ${GITHUB_WORKSPACE}"
119- echo "OUT_DIR: ${OUT_DIR}"
120- ls -la "${OUT_DIR}" || true
80+ # JSON (second report output; keep report-only)
81+ gitleaks detect --source="." --redact $CFG \
82+ --report-format=json \
83+ --report-path="${{ env.OUT_DIR }}/${{ env.OUT_JSON }}" \
84+ >/dev/null 2>&1
85+
86+ exit 0
12187
122- - name : Upload secret scan artifacts (never fail if empty )
88+ - name : Upload artifacts (reports )
12389 if : always()
12490 uses : actions/upload-artifact@v4
12591 with :
12894 if-no-files-found : warn
12995 retention-days : 30
13096
131- - name : Upload SARIF to GitHub Code Scanning (report-only)
97+ - name : Upload SARIF to GitHub Code Scanning
13298 if : always() && hashFiles(format('{0}/{1}', env.OUT_DIR, env.OUT_SARIF)) != ''
13399 uses : github/codeql-action/upload-sarif@v4
134100 with :
0 commit comments