Skip to content

Commit a7cca78

Browse files
committed
ci: update CodeQL and Gitleaks workflows to improve handling of private repositories and artifact uploads
1 parent e20a634 commit a7cca78

2 files changed

Lines changed: 34 additions & 19 deletions

File tree

.github/workflows/codeql-analysis.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ jobs:
5656
uses: github/codeql-action/analyze@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6
5757
with:
5858
category: "/language:${{ matrix.language }}"
59-
# upload: false is NOT set — we attempt upload normally.
60-
# On private repos without GHAS the upload will warn but the job still passes
61-
# because the action only hard-errors when security-events write is explicitly denied.
62-
continue-on-error: false
59+
# FIX: Disable SARIF upload to GitHub's code-scanning API.
60+
# This repo is private without GitHub Advanced Security, so the upload
61+
# endpoint returns "Code scanning is not enabled" and fails the job.
62+
# The scan itself completes successfully — disabling upload lets the
63+
# job pass while preserving full analysis coverage.
64+
# To re-enable: remove this line and enable Code Scanning at
65+
# Settings → Code security → Code scanning (requires GHAS).
66+
upload: false

.github/workflows/gitleaks.yml

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ on:
1111

1212
permissions:
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

1520
jobs:
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

Comments
 (0)