π§ ci: skip CodeQL on fork PRs (upload cannot write security-events)#156
Merged
Conversation
β¦events) Fork PRs run with a restricted GITHUB_TOKEN that cannot write `security-events` back to the upstream repo, so the analyze step's SARIF upload fails with "Resource not accessible by integration" for every external contributor PR (e.g. PR #150 from tony-nexartis). Add a job-level `if:` that skips the entire analyze job when the pull_request's head repo differs from the workflow's repository. CodeQL still runs on: - push events to develop/master (post-merge, full write token) - same-repo PRs (full write token) - the weekly schedule so no scanning coverage is lost β only the redundant, upload-failing fork-PR run is skipped. No behavior change for non-fork workflows.
This was referenced Jul 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
CodeQL fails on every fork pull request with:
Root cause: fork PRs run with a restricted GITHUB_TOKEN that cannot write
security-eventsback to the upstream repo. The workflow'spermissions: security-events: writeblock doesn't help β GitHub deliberately uses a separate, reduced-scope token for fork PR runs (security measure to prevent untrusted code from exfiltrating write scopes).This caused the confusing red X on PR #150 (from @tony-nexartis) even though the analysis itself completed successfully and the post-merge CodeQL run on
developpassed.Fix
Add a job-level
if:that skips the entireanalyzejob when the pull request's head repo differs from the workflow's repository:Coverage retained
CodeQL still runs on:
Only the redundant fork-PR run (which always failed to upload anyway) is skipped. No scanning coverage is lost.
Verification
python -c "import yaml; yaml.safe_load(...)")git diffis +9 β0 (comment + 1-lineif:condition)