ci: per-language CodeQL - Go scans on main and weekly, buildless languages on PRs#254
ci: per-language CodeQL - Go scans on main and weekly, buildless languages on PRs#254balajinvda wants to merge 3 commits into
Conversation
The Go CodeQL job autobuilds the whole umbrella (~25 min). Today both the go and rust legs run on every code PR, so a Rust-only PR pays the full Go build for nothing. Add a detect job (GitHub API, no third-party actions per the org allowlist) that gates each language leg: on a PR only the changed language runs; pushes to main and the weekly schedule still run both for a complete baseline. A change to codeql.yml re-scans both. Go stays build-mode autobuild: CodeQL 2.26 confirmed Go does not support build-mode none. Co-authored-by: Balaji Ganesan <bganesan@nvidia.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe CodeQL workflow detects changed Go and Rust files for pull requests, publishes a dynamic analysis matrix, and skips analysis when neither language changes. Pushes to ChangesCodeQL language routing
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant PullRequest
participant GitHubAPI
participant detect
participant analyze
PullRequest->>GitHubAPI: Request changed files
GitHubAPI-->>detect: Return file list
detect->>detect: Build selected language matrix and any flag
detect->>analyze: Provide selected language matrix
analyze->>analyze: Run matching CodeQL analysis
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/codeql.yml:
- Around line 67-68: Update the Go and Rust file-detection regexes in the
workflow so manifest alternatives match either the repository root or a path
separator, using (^|/) before go.mod, go.sum, Cargo.toml, and Cargo.lock.
Preserve the existing extension matching and language-flag behavior.
- Line 61: Update the pull-request file lookup around the gh api invocation to
avoid suppressing command failures via “|| true”. Ensure an API error causes the
workflow step to fail, or explicitly fall back to scanning both languages rather
than treating an empty files value as no matching changes.
- Around line 75-81: Update the analyze job’s matrix gating so its if condition
does not reference matrix.language before matrix expansion. Use detect’s
generated matrix output, or split the job into language-specific jobs gated by
needs.detect.outputs.go and needs.detect.outputs.rust, while preserving the
behavior of running changed languages on pull requests and both languages on
pushes or schedules.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: bcdcbaeb-9999-4d9f-bfd1-bc2450af32db
📒 Files selected for processing (1)
.github/workflows/codeql.yml
| printf '%s\n' "$files" | grep -qE '(\.go|/go\.mod|/go\.sum)$' && go=true || true | ||
| printf '%s\n' "$files" | grep -qE '(\.rs|/Cargo\.toml|/Cargo\.lock)$' && rust=true || true |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Match repository-root manifests.
The /go.mod, /go.sum, /Cargo.toml, and /Cargo.lock alternatives require a preceding slash, so root-level manifests are missed. A PR changing only go.mod or Cargo.toml can therefore skip its language analysis. Use (^|/) for manifest matching.
Proposed regex fix
- printf '%s\n' "$files" | grep -qE '(\.go|/go\.mod|/go\.sum)$' && go=true || true
- printf '%s\n' "$files" | grep -qE '(\.rs|/Cargo\.toml|/Cargo\.lock)$' && rust=true || true
+ printf '%s\n' "$files" | grep -qE '(\.go$|(^|/)(go\.mod|go\.sum)$)' && go=true || true
+ printf '%s\n' "$files" | grep -qE '(\.rs$|(^|/)(Cargo\.toml|Cargo\.lock)$)' && rust=true || true📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| printf '%s\n' "$files" | grep -qE '(\.go|/go\.mod|/go\.sum)$' && go=true || true | |
| printf '%s\n' "$files" | grep -qE '(\.rs|/Cargo\.toml|/Cargo\.lock)$' && rust=true || true | |
| printf '%s\n' "$files" | grep -qE '(\.go$|(^|/)(go\.mod|go\.sum)$)' && go=true || true | |
| printf '%s\n' "$files" | grep -qE '(\.rs$|(^|/)(Cargo\.toml|Cargo\.lock)$)' && rust=true || true |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/codeql.yml around lines 67 - 68, Update the Go and Rust
file-detection regexes in the workflow so manifest alternatives match either the
repository root or a path separator, using (^|/) before go.mod, go.sum,
Cargo.toml, and Cargo.lock. Preserve the existing extension matching and
language-flag behavior.
…ob if matrix context is not available in a job-level if, which caused a workflow startup failure. Have the detect job emit the matrix JSON (only the changed languages) and gate analyze on a simple needs output instead. Co-authored-by: Balaji Ganesan <bganesan@nvidia.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/codeql.yml:
- Around line 72-73: Update the file-detection regexes in the workflow’s
language-selection logic to match repository-root go.mod, go.sum, Cargo.toml,
and Cargo.lock files as well as nested manifests; remove the requirement for a
preceding slash in those manifest alternatives while preserving source-file
matching.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: c52efdb0-83d3-4627-b989-5fb8b1490e3d
📒 Files selected for processing (1)
.github/workflows/codeql.yml
| if printf '%s\n' "$files" | grep -qE '(\.go|/go\.mod|/go\.sum)$'; then go=true; fi | ||
| if printf '%s\n' "$files" | grep -qE '(\.rs|/Cargo\.toml|/Cargo\.lock)$'; then rust=true; fi |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Match repository-root manifests.
The /go.mod, /go.sum, /Cargo.toml, and /Cargo.lock alternatives require a preceding slash, so PRs changing only root-level manifests can skip the corresponding CodeQL analysis.
Proposed regex fix
- if printf '%s\n' "$files" | grep -qE '(\.go|/go\.mod|/go\.sum)$'; then go=true; fi
- if printf '%s\n' "$files" | grep -qE '(\.rs|/Cargo\.toml|/Cargo\.lock)$'; then rust=true; fi
+ if printf '%s\n' "$files" | grep -qE '(\.go$|(^|/)(go\.mod|go\.sum)$)'; then go=true; fi
+ if printf '%s\n' "$files" | grep -qE '(\.rs$|(^|/)(Cargo\.toml|Cargo\.lock)$)'; then rust=true; fi🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/codeql.yml around lines 72 - 73, Update the file-detection
regexes in the workflow’s language-selection logic to match repository-root
go.mod, go.sum, Cargo.toml, and Cargo.lock files as well as nested manifests;
remove the requirement for a preceding slash in those manifest alternatives
while preserving source-file matching.
🛡️ CodeQL Analysis🚨 Found 2 issue(s) Severity Breakdown:
📋 Top Issues🔗 View full details in Security tab 🕐 Last updated: 2026-07-19 04:27:31 UTC | Commit: 13b9f10 |
Go is the only language in the stack whose CodeQL analysis requires a traced build (build-mode none is supported for C/C++, C#, Java, and Rust, but not Go), and its autobuild compiles the whole umbrella (~21 min) for advisory-only PR feedback (fail-on-findings is false). Exclude Go from PR scans: every push to main and the weekly schedule still scan Go fully, so the security baseline is unchanged and detection moves from pre-merge to at-merge. Rust (buildless, ~2.5 min) keeps scanning on PRs, and Java can join as build-mode none when it lands. Co-authored-by: Balaji Ganesan <bganesan@nvidia.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
balaji-g
left a comment
There was a problem hiding this comment.
Reviewed: verification evidence in the PR description checks out (local + CI runs).
Why
The Go CodeQL job autobuilds the entire umbrella (~21 min per run). Go is the
only language in the stack whose analysis requires a traced build: CodeQL's
build-mode: noneis supported for C/C++, C#, Java, and Rust, but not Go (theCLI rejects it, and #253 proved that live). The scan is also advisory on PRs
(
fail-on-findings: false), so every Go-touching PR paid 21 minutes fornon-blocking feedback.
What changed
.github/workflows/codeql.ymlgains adetectjob (GitHub API file listing,no third-party action per the org allowlist) that emits a dynamic analyze
matrix:
and only when the PR touches Rust files or this workflow. Go never scans on
PRs. Java joins as
build-mode: nonewhen it lands in the mirror.languages, Go included. The Security-tab baseline is unchanged; Go detection
moves from pre-merge to at-merge.
The matrix is emitted as JSON by
detect(a job-levelifcannot referencethe
matrixcontext, which caused this branch's earlier startup failure - nowalso guarded repo-wide by the actionlint gate in #255).
Testing
Rust-touching PR scans rust only, codeql.yml PR scans rust only, push and
schedule scan both.
detectselected rust only, and thechecks list shows CodeQL (rust) with no 21-minute Go leg.
References
NO-REF (CI efficiency change; no associated issue).