Skip to content

ci: per-language CodeQL - Go scans on main and weekly, buildless languages on PRs#254

Merged
balajinvda merged 4 commits into
mainfrom
ci/codeql-per-language-gating
Jul 21, 2026
Merged

ci: per-language CodeQL - Go scans on main and weekly, buildless languages on PRs#254
balajinvda merged 4 commits into
mainfrom
ci/codeql-per-language-gating

Conversation

@balajinvda

@balajinvda balajinvda commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

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: none is supported for C/C++, C#, Java, and Rust, but not Go (the
CLI 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 for
non-blocking feedback.

What changed

.github/workflows/codeql.yml gains a detect job (GitHub API file listing,
no third-party action per the org allowlist) that emits a dynamic analyze
matrix:

  • Pull requests: only buildless languages scan. Today that is Rust (~2.5 min),
    and only when the PR touches Rust files or this workflow. Go never scans on
    PRs. Java joins as build-mode: none when it lands in the mirror.
  • Pushes to main and the weekly schedule: unconditional full scan of all
    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-level if cannot reference
the matrix context, which caused this branch's earlier startup failure - now
also guarded repo-wide by the actionlint gate in #255).

Testing

  • Detect logic simulated locally for all cases: Go-only PR scans nothing,
    Rust-touching PR scans rust only, codeql.yml PR scans rust only, push and
    schedule scan both.
  • Workflow passes the ci: lint GitHub workflows with actionlint #255 actionlint gate (expressions + shellcheck) locally.
  • This PR's own run is the live proof: detect selected rust only, and the
    checks list shows CodeQL (rust) with no 21-minute Go leg.

References

NO-REF (CI efficiency change; no associated issue).

Summary by CodeRabbit

  • Bug Fixes
    • Improved CodeQL scanning so pull requests analyze only affected supported languages.
    • Ensured security analysis still runs for workflow changes and when changed-file detection is unavailable.
    • Preserved full Go and Rust analysis for direct updates to the main branch.

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>
@balajinvda
balajinvda requested a review from a team as a code owner July 19, 2026 04:15
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 266b334a-7124-4d16-aac6-5fb895bef25d

📥 Commits

Reviewing files that changed from the base of the PR and between 1c061ae and 620cc21.

📒 Files selected for processing (1)
  • .github/workflows/codeql.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/codeql.yml

📝 Walkthrough

Walkthrough

The CodeQL workflow narrows its source path filters, detects changed Go and Rust files for pull requests, publishes a dynamic analysis matrix, and skips analysis when neither language changes. Non-PR runs continue analyzing both languages.

Changes

CodeQL language routing

Layer / File(s) Summary
Changed-language detection and workflow triggers
.github/workflows/codeql.yml
Narrows push and pull_request path filters, adds a detect job that identifies changed Go and Rust files, handles lookup failures and workflow changes, and publishes a dynamic matrix with an any flag.
Conditional CodeQL execution
.github/workflows/codeql.yml
Makes analyze depend on detect, gates execution on the any output, and runs the selected matrix languages while retaining both languages for non-PR events.

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
Loading

Possibly related PRs

  • NVIDIA/nvcf#274: Modifies the same CodeQL workflow’s trigger logic and language matrix configuration.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the per-language CodeQL gating and the different scan behavior for main, weekly, and PR runs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ci/codeql-per-language-gating

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between c79102d and 9d7eb45.

📒 Files selected for processing (1)
  • .github/workflows/codeql.yml

Comment thread .github/workflows/codeql.yml Outdated
Comment thread .github/workflows/codeql.yml Outdated
Comment thread .github/workflows/codeql.yml Outdated
…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>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9d7eb45 and 13b9f10.

📒 Files selected for processing (1)
  • .github/workflows/codeql.yml

Comment thread .github/workflows/codeql.yml Outdated
@github-actions

Copy link
Copy Markdown

🛡️ CodeQL Analysis

🚨 Found 2 issue(s)

Severity Breakdown:

  • 🔴 Errors: 0
  • 🟡 Warnings: 0
  • 🔵 Notes: 0
📋 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>
@balajinvda balajinvda changed the title ci: run CodeQL only for the languages a PR changes ci: per-language CodeQL - Go scans on main and weekly, buildless languages on PRs Jul 19, 2026

@balaji-g balaji-g left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed: verification evidence in the PR description checks out (local + CI runs).

Address review feedback on the per-language gating:
- Do not swallow the changed-file lookup failure. Previously `gh api ... || true`
  left `files` empty on an API error, which the PR path treated as "no code
  changed" and silently skipped both scans. Now a lookup failure falls back to
  scanning all languages (fail-open), so a transient error never drops coverage.
- Match repository-root manifests. gh api filenames are repo-relative with no
  leading slash, so anchor Cargo.toml/Cargo.lock (and the workflow self-match)
  with (^|/) to catch both root and nested files.
- Do not run CodeQL on docs-only changes. Drop the broad "src/**" path trigger;
  code is already covered by the *.go/*.rs + manifest globs, so a Markdown or
  other non-code change under src/ no longer starts the workflow.

Co-authored-by: Balaji Ganesan <bganesan@nvidia.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@balajinvda

Copy link
Copy Markdown
Contributor Author

Addressed the review feedback in the latest commit:

  • Changed-file lookup no longer swallows failures. gh api ... || true is replaced with a if ! files=$(...) guard that falls back to scanning all languages on a lookup error, so a transient API failure can never silently skip the scan.
  • Manifest matching now anchors with (^|/) so root-level Cargo.toml/Cargo.lock (and the workflow self-match) are caught, not just nested ones.
  • CodeQL no longer runs on docs-only changes: dropped the broad src/** path trigger (code is already covered by the *.go/*.rs + manifest globs), so a Markdown or other non-code change under src/ no longer starts the workflow.

@balajinvda
balajinvda added this pull request to the merge queue Jul 21, 2026
Merged via the queue into main with commit 38721fa Jul 21, 2026
18 checks passed
@kristinapathak
kristinapathak deleted the ci/codeql-per-language-gating branch July 21, 2026 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants