1111
1212permissions :
1313 contents : read
14+ # FIX: gitleaks-action v2 calls GET /repos/{owner}/{repo}/pulls/{n}/commits
15+ # on pull_request events to determine which commits to scan. Without this
16+ # permission the API returns HTTP 403 "Resource not accessible by integration"
17+ # crashing the action before any scan runs.
18+ pull-requests : read
1419
1520jobs :
1621 gitleaks :
@@ -23,24 +28,30 @@ jobs:
2328 fetch-depth : 0
2429
2530 - name : Run Gitleaks
31+ id : gitleaks
2632 uses : gitleaks/gitleaks-action@ff98106e4c7b2bc287b24eaf42907196329070c7 # v2.3.9
2733 env :
2834 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
29- # Fix: In gitleaks-action v2, report format/path are controlled via
30- # GITLEAKS_REPORT_FORMAT and GITLEAKS_REPORT_PATH env vars, NOT via
31- # the `with.args` parameter (which is ignored by this action version).
32- GITLEAKS_REPORT_FORMAT : sarif
33- GITLEAKS_REPORT_PATH : results.sarif
35+ # GITLEAKS_CONFIG points to your custom rules file at repo root.
3436 GITLEAKS_CONFIG : .gitleaks.toml
35- # Note: `with.args` has been removed — gitleaks-action v2 does not
36- # expose an `args` input; using it silently had no effect, which is
37- # why results.sarif was never created and the upload step failed.
37+ # FIX: gitleaks-action v2 auto-generates a SARIF file internally and
38+ # handles its own artifact upload when GITLEAKS_ENABLE_UPLOAD_ARTIFACT=true
39+ # (the default). The `with.args` parameter does not exist in this action
40+ # and was silently ignored — that is why results.sarif was never written
41+ # to disk, causing the upload step to fail with "file not found".
42+ # Uploading SARIF to the code-scanning API also requires GitHub Advanced
43+ # Security (GHAS), which is not available on private free-plan repos.
44+ # We therefore disable the built-in artifact upload and instead capture
45+ # the report ourselves below using actions/upload-artifact (no GHAS needed).
46+ GITLEAKS_ENABLE_UPLOAD_ARTIFACT : false
3847
39- - name : Upload Gitleaks SARIF report
40- if : always()
41- uses : github/codeql-action/upload-sarif@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6
42- # Fix: was using unpinned `@v4` tag — now pinned to the same commit
43- # SHA used by the rest of the workflow for supply-chain consistency.
48+ - name : Upload Gitleaks report as workflow artifact
49+ # Run even when gitleaks finds secrets (exit code 1) so the report is
50+ # always available for review — but skip when the step was cancelled.
51+ if : always() && steps.gitleaks.outcome != 'cancelled'
52+ uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
4453 with :
45- sarif_file : results.sarif
46- continue-on-error : true
54+ name : gitleaks-report
55+ # gitleaks-action v2 writes the SARIF to this fixed path
56+ path : results.sarif
57+ if-no-files-found : ignore
0 commit comments