Skip to content

Commit fdb27bf

Browse files
fix: skip SARIF upload on a private repository instead of failing
zizmor-action and codeql-action/analyze both upload their SARIF to GitHub code scanning, which needs GitHub Advanced Security — absent on a private repository, so both jobs failed with a 403 on every run of the walkthrough's own recommended `--private` setup, for a reason that has nothing to do with the code being scanned. zizmor: advanced-security: false plus annotations: true reports the same findings as workflow annotations instead of a SARIF upload. zizmor's own exit code still fails the job on a real finding either way, so this is applied unconditionally rather than gated on visibility — no downside on a public repo, and no need to detect which one this is (github.event.repository.private is absent on a schedule trigger, one of this workflow's own triggers). codeql: CodeQL has no local pass/fail — the Advanced Security upload is the only signal its action produces, so gating it needs to know the repository's real visibility. Read via `gh api repos/<owner>/<repo>`, which works under every trigger including schedule. upload: never on a private repo keeps the database build and query run, just skips the call that gets rejected — a private repo gets no code-scanning signal here, same tradeoff as gitleaks and zizmor's exit code can't stand in for. A public repo keeps the full Security-tab upload, which GitHub does not require Advanced Security for. Claude-Session: https://claude.ai/code/session_01J4HB8qJjdZwaAv42k6HMpv
1 parent 3483552 commit fdb27bf

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

‎.github/workflows/app-security.yml‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,47 @@ jobs:
3232
else
3333
echo "present=false" >> "$GITHUB_OUTPUT"
3434
fi
35+
# SARIF upload needs GitHub Advanced Security, which a private repository
36+
# does not have — uploading there fails the job on a 403 for a reason
37+
# that has nothing to do with the code. `private` isn't in the event
38+
# payload for a schedule trigger, so it's read from the API instead of
39+
# `github.event.repository.private`, which that trigger leaves empty.
40+
- id: visibility
41+
if: steps.has-javascript.outputs.present == 'true'
42+
env:
43+
GH_TOKEN: ${{ github.token }}
44+
run: echo "private=$(gh api "repos/${GITHUB_REPOSITORY}" --jq .private)" >> "$GITHUB_OUTPUT"
3545
- if: steps.has-javascript.outputs.present == 'true'
3646
uses: github/codeql-action/init@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9
3747
with:
3848
languages: ${{ matrix.language }}
49+
# upload: never keeps the database build and query run but skips the
50+
# call a private repo gets rejected for. CodeQL only fails a build
51+
# through that upload (there is no local pass/fail), so a private repo
52+
# gets the scan with no signal from it — accepted, not solved.
3953
- if: steps.has-javascript.outputs.present == 'true'
4054
uses: github/codeql-action/analyze@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9
55+
with:
56+
upload: ${{ steps.visibility.outputs.private == 'true' && 'never' || 'always' }}
4157

4258
zizmor:
4359
runs-on: ubuntu-latest
4460
permissions:
4561
contents: read
46-
security-events: write
4762
steps:
4863
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
4964
with:
5065
persist-credentials: false
66+
# advanced-security uploads SARIF to code scanning, which a private repo
67+
# rejects with a 403 (no Advanced Security license). annotations gets the
68+
# same findings onto the run as workflow annotations instead — zizmor's
69+
# own exit code still fails the job on a real finding either way, so
70+
# this trades the Security tab for something that works on both
71+
# visibilities without needing to detect which one this is.
5172
- uses: zizmorcore/zizmor-action@3dc1ecc9bcb9e94e9b2c709687979e1298497054 # v0.6.2
73+
with:
74+
advanced-security: "false"
75+
annotations: "true"
5276

5377
gitleaks:
5478
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)