Skip to content

[None][infra] Add SonarQube code analysis in github action - #10677

Closed
yuanjingx87 wants to merge 3 commits into
mainfrom
user/yuanjingx/support_sonar_scanning
Closed

yuanjingx87 wants to merge 3 commits into
mainfrom
user/yuanjingx/support_sonar_scanning

Conversation

@yuanjingx87

@yuanjingx87 yuanjingx87 commented Jan 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Chores
    • Integrated SonarQube code analysis into the CI/CD pipeline to provide automated scanning for code quality and security on all pull requests and commits to the main branch.
    • Automated analysis runs in parallel with existing continuous integration workflows, enabling early detection of code quality issues and potential vulnerabilities throughout the development cycle.

✏️ Tip: You can customize this high-level summary in your review settings.

Description

Add SonarQube code analysis in github action

Test Coverage

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

Details

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

For guidance on mapping tests to stage names, see docs/source/reference/ci-overview.md
and the scripts/test_to_stage_mapping.py helper.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

Signed-off-by: Yuanjing Xue <197832395+yuanjingx87@users.noreply.github.com>
Signed-off-by: Yuanjing Xue <197832395+yuanjingx87@users.noreply.github.com>
@yuanjingx87
yuanjingx87 requested a review from a team January 14, 2026 19:05
@yuanjingx87
yuanjingx87 requested a review from a team as a code owner January 14, 2026 19:05
Comment thread .github/workflows/sonarqube-code-analysis.yml Fixed
@coderabbitai

coderabbitai Bot commented Jan 14, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

SonarQube code analysis integration is being introduced to the CI pipeline. A new dedicated workflow (sonarqube-code-analysis.yml) is created to run parallel analysis, while existing CI workflows are updated with integrated SonarQube steps. A SonarQube project configuration file is added with project key settings.

Changes

Cohort / File(s) Summary
GitHub Actions Workflows
.github/workflows/blossom-ci.yml
Added two "Run SonarQube Code Analysis" steps (using SonarSource/sonarqube-scan-action@v4) to Authorization and Vulnerability-scan jobs, configured with SONAR_TOKEN and SONAR_HOST_URL environment variables
GitHub Actions Workflows
.github/workflows/sonarqube-code-analysis.yml
New workflow file that triggers on pushes to main, pull requests, and manual dispatch; performs checkout with full history (fetch-depth: 0) and runs SonarQube analysis with optional quality gate check step (currently commented out)
SonarQube Configuration
sonar-project.properties
Added sonar.projectKey property with value GPUSW_TensorRT-LLM-Team_TensorRT-LLM_tensorrt-llm

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description lacks substantive detail about the implementation. Beyond '@coderabbitai summary' and a one-line summary, it only contains the boilerplate template without addressing the 'Description' section that explains what was changed and why. Expand the 'Description' section to explain what SonarQube analysis does, why it's being added, and any configuration details or dependencies introduced in this PR.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding SonarQube code analysis integration into GitHub Actions. It follows the required template format [None][infra] and concisely summarizes the primary objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @.github/workflows/sonarqube-code-analysis.yml:
- Around line 15-18: The workflow is missing an explicit permissions block; add
a top-level permissions block in the workflow (above or alongside "jobs" /
"build") that grants least-privilege scopes required for analysis—for example
set contents: read and security-events: write (and actions: read if needed by
used actions) so the "build" job and SonarQube/code-scanning actions have
explicit, minimal permissions.
🧹 Nitpick comments (2)
sonar-project.properties (1)

1-1: Consider adding additional SonarQube properties for more precise analysis.

The minimal configuration will work, but you may want to consider adding properties such as sonar.sources, sonar.exclusions, or sonar.python.version to improve analysis accuracy and exclude irrelevant files (e.g., third-party code, build artifacts).

Example enhanced configuration
 sonar.projectKey=GPUSW_TensorRT-LLM-Team_TensorRT-LLM_tensorrt-llm
+sonar.sources=.
+sonar.exclusions=**/third_party/**,**/build/**,**/dist/**
.github/workflows/blossom-ci.yml (1)

372-376: SonarQube integration looks good; consider version consistency.

The SonarQube scan step is correctly placed after checkout and properly uses secrets via environment variables. However, note that this workflow uses actions/checkout@v2 (line 366) while the new sonarqube-code-analysis.yml uses actions/checkout@v6. Consider aligning versions for consistency and to benefit from security/performance improvements.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c99faae and aa5c314.

📒 Files selected for processing (3)
  • .github/workflows/blossom-ci.yml
  • .github/workflows/sonarqube-code-analysis.yml
  • sonar-project.properties
🧰 Additional context used
🪛 GitHub Check: CodeQL
.github/workflows/sonarqube-code-analysis.yml

[warning] 17-37: Workflow does not contain permissions
Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {{contents: read}}

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Pre-commit Check
  • GitHub Check: Analyze (python)
🔇 Additional comments (2)
.github/workflows/sonarqube-code-analysis.yml (2)

26-29: SonarQube scan configuration is correct.

The scan action is properly configured with secrets passed via environment variables. The fetch-depth: 0 on checkout ensures full git history is available for accurate blame analysis.


21-24: No action needed — actions/checkout@v6 is a valid, released version.

The version reference is correct. v6 is officially available with documented release notes.

Likely an incorrect or invalid review comment.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment on lines +15 to +18
jobs:
build:
name: Build and analyze
runs-on: ubuntu-latest

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.

⚠️ Potential issue | 🟡 Minor

Add explicit permissions block to follow security best practices.

As flagged by CodeQL, the workflow lacks an explicit permissions block. Adding minimal permissions follows the principle of least privilege and improves security posture.

Proposed fix
 jobs:
   build:
     name: Build and analyze
     runs-on: ubuntu-latest
+    permissions:
+      contents: read
+      pull-requests: read
📝 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
jobs:
build:
name: Build and analyze
runs-on: ubuntu-latest
jobs:
build:
name: Build and analyze
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
🤖 Prompt for AI Agents
In @.github/workflows/sonarqube-code-analysis.yml around lines 15 - 18, The
workflow is missing an explicit permissions block; add a top-level permissions
block in the workflow (above or alongside "jobs" / "build") that grants
least-privilege scopes required for analysis—for example set contents: read and
security-events: write (and actions: read if needed by used actions) so the
"build" job and SonarQube/code-scanning actions have explicit, minimal
permissions.

Comment thread .github/workflows/sonarqube-code-analysis.yml Fixed
@yuanjingx87
yuanjingx87 marked this pull request as draft January 14, 2026 19:21
@yuanjingx87
yuanjingx87 force-pushed the user/yuanjingx/support_sonar_scanning branch from c765eac to 364bb00 Compare January 14, 2026 19:38
Comment thread .github/workflows/sonarqube-code-analysis.yml Fixed
@yuanjingx87
yuanjingx87 force-pushed the user/yuanjingx/support_sonar_scanning branch from 364bb00 to 8aac65b Compare January 14, 2026 19:39
Signed-off-by: Yuanjing Xue <197832395+yuanjingx87@users.noreply.github.com>
@yuanjingx87
yuanjingx87 force-pushed the user/yuanjingx/support_sonar_scanning branch from 8aac65b to 436edef Compare January 14, 2026 19:46
Comment on lines +17 to +36
name: Build and analyze
runs-on: blossom
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.ref || github.ref }}

- uses: SonarSource/sonarqube-scan-action@v4
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
# If you wish to fail your job when the Quality Gate is red, uncomment the
# following lines. This would typically be used to fail a deployment.
# We do not recommend to use this in a pull request. Prefer using pull request
# decoration instead.
# - uses: SonarSource/sonarqube-quality-gate-action@v1
# timeout-minutes: 5
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 10 months ago

In general, the fix is to explicitly declare a permissions: block so the GITHUB_TOKEN has only the minimal access required. For this job, it only needs to read repository contents and metadata for analysis, so setting contents: read is appropriate. This can be done either at the workflow root (applies to all jobs) or at the job level (just for build). Since CodeQL flags the job, the clearest fix is to add permissions: under jobs.build.

Concretely, in .github/workflows/sonarqube-code-analysis.yml, add a permissions: section under jobs.build (between runs-on: blossom and steps:), indented two spaces further than build:. Set contents: read inside it. No imports or additional methods are needed; this is purely a YAML configuration change and will not alter existing step behavior, except that it tightens the default token privileges.

Suggested changeset 1
.github/workflows/sonarqube-code-analysis.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/sonarqube-code-analysis.yml b/.github/workflows/sonarqube-code-analysis.yml
--- a/.github/workflows/sonarqube-code-analysis.yml
+++ b/.github/workflows/sonarqube-code-analysis.yml
@@ -16,6 +16,8 @@
   build:
     name: Build and analyze
     runs-on: blossom
+    permissions:
+      contents: read
     steps:
       - uses: actions/checkout@v6
         with:
EOF
@@ -16,6 +16,8 @@
build:
name: Build and analyze
runs-on: blossom
permissions:
contents: read
steps:
- uses: actions/checkout@v6
with:
Copilot is powered by AI and may make mistakes. Always verify output.
jobs:
build:
name: Build and analyze
runs-on: blossom

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We probably won't be able to use the blossom runner for these actions, since they have some special configuration designed to work only with the blossom workflow. I think the standard ubuntu-latest runner should work for this, unless the SonarQube server requires special network access.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this needs to hit internal sonarqube API like: https://sonar.nvidia.com/api/server/version
I closed this PR for now and play with it in my fork, now I set up a new runner with my dev-box in my fork to get it running

@yuanjingx87
yuanjingx87 deleted the user/yuanjingx/support_sonar_scanning branch January 14, 2026 20:02
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