Skip to content

feat: SonarCloud + CodeQL upgrade#65

Merged
kienbui1995 merged 1 commit intomainfrom
feat/sonarcloud-codeql
Apr 14, 2026
Merged

feat: SonarCloud + CodeQL upgrade#65
kienbui1995 merged 1 commit intomainfrom
feat/sonarcloud-codeql

Conversation

@kienbui1995
Copy link
Copy Markdown
Owner

@kienbui1995 kienbui1995 commented Apr 14, 2026

Code Scanning Setup

SonarCloud (NEW)

  • Coverage report via cargo-tarpaulin
  • Clippy report integration
  • Quality gate enforcement
  • Runs on push + PRs

Setup required:

  1. Go to sonarcloud.io → Import kienbui1995/mc-code
  2. Copy the SONAR_TOKEN
  3. Add to repo: Settings → Secrets → SONAR_TOKEN

CodeQL (UPGRADED)

  • Added security-and-quality query suite (more thorough)
  • Category tagging for dashboard

Full scanning stack

Tool What it checks
CodeQL SAST — vulnerabilities, code quality
SonarCloud Bugs, code smells, coverage, duplication
cargo-audit Known CVEs in dependencies
cargo-deny License compliance, supply chain
dependency-review New dep risk on PRs
Secret scanning Leaked credentials

274 tests, 0 fail.

Summary by CodeRabbit

Release Notes

  • Chores
    • Added SonarCloud integration for continuous code quality monitoring with automated test coverage analysis and reporting
    • Enhanced CodeQL security scanning workflow with improved configuration for Rust language analysis and quality gate validation

1. SonarCloud workflow:
   - Coverage via cargo-tarpaulin (XML report)
   - Clippy report in JSON format
   - Quality gate enforcement
   - Runs on push to main + PRs

2. sonar-project.properties:
   - Project: kienbui1995_mc-code
   - Sources: mc/crates
   - Coverage + clippy report paths

3. CodeQL upgraded:
   - Added 'security-and-quality' query suite (was default only)
   - Added category tag for better dashboard grouping
   - Added explicit permissions

NOTE: SonarCloud requires SONAR_TOKEN secret.
Setup: https://sonarcloud.io → Import repo → Copy token →
GitHub repo Settings → Secrets → New: SONAR_TOKEN

274 tests, 0 fail.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

📝 Walkthrough

Walkthrough

The changes introduce code quality and security scanning infrastructure by updating the CodeQL workflow with Rust-specific analysis configuration, adding a new SonarCloud integration workflow that performs coverage analysis and quality gate checks, and configuring the SonarQube project settings for comprehensive code scanning.

Changes

Cohort / File(s) Summary
CodeQL Analysis Enhancement
.github/workflows/codeql.yml
Moved permissions to workflow-level, renamed job to CodeQL Analysis, configured init step with queries: security-and-quality, and added category: "/language:rust" to the analyze step for Rust-specific scanning.
SonarCloud Integration
.github/workflows/sonarcloud.yml, sonar-project.properties
Added new SonarCloud workflow triggered on push and pull requests to main, configured with Rust toolchain, tarpaulin coverage reporting, and Clippy static analysis integration; added project configuration specifying source directories, test scope, exclusions, and quality gate enforcement.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through code so bright,
With SonarCloud and CodeQL's light,
Quality gates and Clippy's keen eye,
Help our Rust projects soar up high! 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides context for SonarCloud setup, CodeQL upgrades, and the full scanning stack, but diverges from the template structure and omits required sections like explicit 'How' implementation details and testing checklist items. Restructure the description to follow the template: add 'What', 'Why', 'How' sections and include the checklist with test verification status for cargo fmt, cargo test, and cargo clippy.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: SonarCloud + CodeQL upgrade' clearly and specifically summarizes the main changes: adding SonarCloud integration and upgrading CodeQL configuration.
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.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/sonarcloud-codeql

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

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a sonar-project.properties configuration file to integrate SonarCloud analysis into the project. The review feedback highlights several configuration issues: the properties for Rust coverage and Clippy reports are not supported by the official SonarCloud analyzer and should be replaced with generic report paths. Furthermore, it is recommended to remove the redundant sonar.tests definition to avoid overlapping with sonar.sources, relying instead on the inclusion patterns.


# Coverage
sonar.coverage.exclusions=**/tests/**,**/test_*
sonar.rust.tarpaulin.reportPaths=cobertura.xml
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The property sonar.rust.tarpaulin.reportPaths is not supported by the official SonarCloud Rust analyzer, as it belongs to a community plugin not available on the hosted service. To import coverage, you should use sonar.coverageReportPaths. Note that SonarCloud requires the report to be in the Generic Test Data XML format; you will likely need to convert your cobertura.xml (e.g., using a tool like cargo-sonar) before the scan.

sonar.coverageReportPaths=coverage-sonar.xml

sonar.rust.tarpaulin.reportPaths=cobertura.xml

# Clippy
sonar.rust.clippy.reportPaths=clippy-report.json
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The property sonar.rust.clippy.reportPaths is not recognized by SonarCloud's official analyzer. To import Clippy issues, use sonar.externalIssuesReportPaths. This property expects the Generic Issue Import Format. You will need to add a step in your CI pipeline to convert Clippy's native JSON output into the format expected by SonarCloud.

sonar.externalIssuesReportPaths=clippy-sonar.json

Comment on lines +6 to +7
sonar.tests=mc/crates
sonar.test.inclusions=**/tests/**,**/*test*
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Setting sonar.tests to the same directory as sonar.sources creates an overlap that can lead to inconsistent analysis results in SonarCloud. When test files are located within the source tree, the recommended approach is to define the root in sonar.sources and use sonar.test.inclusions to identify the test files. SonarCloud will automatically move files matching the inclusion pattern from the source set to the test set.

sonar.test.inclusions=**/tests/**,**/*test*

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/sonarcloud.yml:
- Around line 27-36: The workflow is suppressing failures for the "Run tests
with coverage" and "Run clippy for SonarCloud" steps; remove the tolerance so
SonarCloud gates fail when reports are missing or invalid by deleting the
continue-on-error: true from the "Run tests with coverage" step and removing the
"|| true" suffix from the "cargo clippy ... > ../clippy-report.json 2>&1 ||
true" command in the "Run clippy for SonarCloud" step; ensure the commands run
with fail-fast behavior (e.g., rely on shell default exit codes or add set -e at
top of run blocks) so tarpaulin and cargo clippy errors surface and cause the
job to fail when reports are invalid or missing.
- Line 38: Replace the vulnerable GitHub Action reference
SonarSource/sonarqube-scan-action@v5 with the patched release
SonarSource/sonarqube-scan-action@v6.0.0; locate the usage of
SonarSource/sonarqube-scan-action in the workflow (the line currently using `@v5`)
and update the version tag to `@v6.0.0` so the workflow uses the fixed action.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4b8a2b41-4f76-4a4c-9f9d-d90c4627d954

📥 Commits

Reviewing files that changed from the base of the PR and between 8958210 and 48f0622.

📒 Files selected for processing (3)
  • .github/workflows/codeql.yml
  • .github/workflows/sonarcloud.yml
  • sonar-project.properties

Comment on lines +27 to +36
- name: Run tests with coverage
run: |
cargo install cargo-tarpaulin --locked
cargo tarpaulin --workspace --skip-clean --out xml --output-dir ../
continue-on-error: true

- name: Run clippy for SonarCloud
run: |
cargo clippy --workspace --all-targets --message-format=json > ../clippy-report.json 2>&1 || 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.

⚠️ Potential issue | 🟠 Major

Stop suppressing coverage/clippy failures in a gate-enforced workflow.

Line 31 (continue-on-error: true) and Line 35 (|| true) can produce “successful” scans with missing or invalid reports, weakening the intended quality gate.

✅ Suggested fail-fast pattern
       - name: Run tests with coverage
         run: |
+          set -euo pipefail
           cargo install cargo-tarpaulin --locked
           cargo tarpaulin --workspace --skip-clean --out xml --output-dir ../
-        continue-on-error: true
+          test -s ../cobertura.xml

       - name: Run clippy for SonarCloud
         run: |
-          cargo clippy --workspace --all-targets --message-format=json > ../clippy-report.json 2>&1 || true
+          set -euo pipefail
+          cargo clippy --workspace --all-targets --message-format=json > ../clippy-report.json 2>&1
+          test -s ../clippy-report.json
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/sonarcloud.yml around lines 27 - 36, The workflow is
suppressing failures for the "Run tests with coverage" and "Run clippy for
SonarCloud" steps; remove the tolerance so SonarCloud gates fail when reports
are missing or invalid by deleting the continue-on-error: true from the "Run
tests with coverage" step and removing the "|| true" suffix from the "cargo
clippy ... > ../clippy-report.json 2>&1 || true" command in the "Run clippy for
SonarCloud" step; ensure the commands run with fail-fast behavior (e.g., rely on
shell default exit codes or add set -e at top of run blocks) so tarpaulin and
cargo clippy errors surface and cause the job to fail when reports are invalid
or missing.

cargo clippy --workspace --all-targets --message-format=json > ../clippy-report.json 2>&1 || true

- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@v5
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

What is the first patched version for GHSA-5xq9-5g24-4g6f in SonarSource/sonarqube-scan-action, and what exact tag/SHA should GitHub Actions pin to?

💡 Result:

The first patched version for GHSA-5xq9-5g24-4g6f in SonarSource/sonarqube-scan-action is v6.0.0. GitHub Actions should pin to the tag v6.0.0 (uses: SonarSource/sonarqube-scan-action@v6.0.0). For extra security, pin to the commit SHA of the release tag, though the full SHA is not directly listed in search results; the tag is stable and recommended in official docs.

Citations:


Upgrade vulnerable Sonar scan action to v6.0.0 immediately.

Line 38 uses SonarSource/sonarqube-scan-action@v5, which is affected by GHSA-5xq9-5g24-4g6f (high severity). Upgrade to v6.0.0, the first patched release.

Suggested change
-      - name: SonarCloud Scan
-        uses: SonarSource/sonarqube-scan-action@v5
+      - name: SonarCloud Scan
+        uses: SonarSource/sonarqube-scan-action@v6.0.0
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/sonarcloud.yml at line 38, Replace the vulnerable GitHub
Action reference SonarSource/sonarqube-scan-action@v5 with the patched release
SonarSource/sonarqube-scan-action@v6.0.0; locate the usage of
SonarSource/sonarqube-scan-action in the workflow (the line currently using `@v5`)
and update the version tag to `@v6.0.0` so the workflow uses the fixed action.

@github-advanced-security
Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

@sonarqubecloud
Copy link
Copy Markdown

@kienbui1995 kienbui1995 merged commit ea3a55c into main Apr 14, 2026
15 of 18 checks passed
@kienbui1995 kienbui1995 deleted the feat/sonarcloud-codeql branch April 14, 2026 07:35
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