Skip to content

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

Open
balajinvda wants to merge 3 commits into
mainfrom
ci/codeql-per-language-gating
Open

ci: per-language CodeQL - Go scans on main and weekly, buildless languages on PRs#254
balajinvda wants to merge 3 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).

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

📝 Walkthrough

Walkthrough

The 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 main and scheduled runs continue analyzing both languages.

Changes

CodeQL language routing

Layer / File(s) Summary
Changed-language detection
.github/workflows/codeql.yml
Adds a detect job that queries pull request files, identifies Go and Rust changes, handles 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#234: Modifies the same workflow’s language-specific matrix handling and analysis outputs.
  • NVIDIA/nvcf#253: Modifies the same workflow’s language matrix behavior and Go analysis configuration.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: per-language CodeQL gating with different behavior on PRs versus main and weekly runs.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 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
Comment thread .github/workflows/codeql.yml Outdated
Comment on lines +67 to +68
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 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.

Suggested change
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.

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
Comment on lines +72 to +73
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 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.

@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).

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.

2 participants