Skip to content

ci(sonar): run SonarCloud scan and upload coverage#10

Merged
amondnet merged 3 commits into
mainfrom
ci/sonarcloud-scan
Jun 27, 2026
Merged

ci(sonar): run SonarCloud scan and upload coverage#10
amondnet merged 3 commits into
mainfrom
ci/sonarcloud-scan

Conversation

@amondnet

@amondnet amondnet commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Adds SonarCloud static analysis to CI and uploads test coverage to SonarCloud.

Changes

  • sonar-project.properties (new): organization=pleaseai, projectKey=pleaseai_cli-toolkit, sources=src, tests=test, and sonar.javascript.lcov.reportPaths=coverage/lcov.info so SonarCloud ingests the existing coverage report.
  • .github/workflows/ci.yml:
    • new SonarCloud Scan step (runs after test:coverage, so it reuses the generated coverage/lcov.info)
    • action pinned to a full commit SHA: SonarSource/sonarqube-scan-action@713881670b6b3676cda39549040e2d88c70d582e # v8.2.0 (per repo policy)
    • SONAR_HOST_URL: https://sonarcloud.io (required — the unified scanner defaults to a SonarQube host otherwise)
    • fetch-depth: 0 on checkout for accurate new-code attribution / blame
    • continue-on-error: truenon-blocking, matching the Codecov step

Coverage upload

bunfig.toml already emits coverage/lcov.info via bun test --coverage; the same file now feeds both Codecov and SonarCloud.

⚠️ Prerequisites (repo/org settings — not in this PR)

  1. SONAR_TOKEN must be added to repo secrets (Settings → Secrets and variables → Actions).
  2. The project pleaseai_cli-toolkit must exist in the pleaseai SonarCloud org. If your org slug / key differ, update sonar-project.properties.
  3. Disable "Automatic Analysis" for the project in SonarCloud — CI-based analysis conflicts with it (the scan errors out otherwise). Non-blocking here, but the scan won't report until this is off.

Summary by cubic

Add SonarCloud static analysis to CI with type-aware TypeScript analysis and upload coverage from coverage/lcov.info. The scan runs after coverage tests and is non-blocking.

  • New Features

    • Added sonar-project.properties (org pleaseai, key pleaseai_cli-toolkit, src/test paths, test inclusions, sonar.typescript.tsconfigPath=tsconfig.json, lcov path, exclusions).
    • CI: run tests once with coverage; upload coverage/lcov.info to Codecov and SonarCloud; continue on error.
    • CI: checkout with fetch-depth: 0 and persist-credentials: false; run SonarCloud Scan via pinned SonarSource/sonarqube-scan-action with SONAR_HOST_URL=https://sonarcloud.io and SONAR_TOKEN.
  • Migration

    • Add SONAR_TOKEN to repo secrets.
    • Ensure the pleaseai_cli-toolkit project exists in the pleaseai SonarCloud org or update sonar-project.properties.
    • Disable “Automatic Analysis” in SonarCloud for this project.

Written for commit 732c5e4. Summary will update on new commits.

Summary by CodeRabbit

  • Chores
    • Updated CI quality checks to improve blame attribution accuracy and streamline coverage generation.
    • Added a dedicated code analysis step after coverage is produced.
    • Refined code analysis configuration, including organization/project identifiers, source/test/coverage locations, TypeScript settings, and exclusions for build and coverage artifacts.

- add sonar-project.properties (org pleaseai, key pleaseai_cli-toolkit)
- run SonarCloud scan in CI after tests, uploading coverage via
  sonar.javascript.lcov.reportPaths=coverage/lcov.info
- pin SonarSource/sonarqube-scan-action to a full commit SHA (v8.2.0)
- set fetch-depth: 0 so SonarCloud attributes new code accurately
- non-blocking (continue-on-error), like the Codecov upload
@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ee3fe55e-bb40-40e9-aae9-925984402665

📥 Commits

Reviewing files that changed from the base of the PR and between 7ef6043 and 732c5e4.

📒 Files selected for processing (2)
  • .github/workflows/ci.yml
  • sonar-project.properties
✅ Files skipped from review due to trivial changes (1)
  • sonar-project.properties
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/ci.yml

📝 Walkthrough

Walkthrough

Adds SonarCloud analysis setup to CI and repository config. The workflow now fetches full git history, runs tests with coverage, and executes a SonarCloud scan with environment-provided credentials.

Changes

SonarCloud setup

Layer / File(s) Summary
Project analysis config
sonar-project.properties
Defines the Sonar organization, project key, source and test locations, coverage report path, and analysis exclusions.
Checkout and coverage run
.github/workflows/ci.yml
Updates checkout to fetch full history and consolidates test execution into a single coverage-producing step.
SonarCloud scan
.github/workflows/ci.yml
Adds a pinned SonarCloud scan step after coverage upload with continue-on-error and Sonar env vars.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hop through CI with a sniff and a cheer,
Full history fetched so the blames are clear.
Sonar hums softly in the build tonight,
Coverage and exclusions tucked in just right.

🚥 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 main CI change: adding a SonarCloud scan and coverage upload.
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/sonarcloud-scan

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

@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces the sonar-project.properties file to configure SonarCloud static analysis for the repository. The configuration defines source and test directories, test inclusions, LCOV coverage report paths, and exclusions. The review feedback suggests adding the sonar.typescript.tsconfigPath property to enable TypeScript type-aware rules, which will improve the accuracy of the static analysis.

Comment thread sonar-project.properties
@greptile-apps

greptile-apps Bot commented Jun 27, 2026

Copy link
Copy Markdown

Greptile Summary

This PR integrates SonarCloud static analysis into CI by adding sonar-project.properties and a new non-blocking scan step that reuses the coverage/lcov.info already produced by the Codecov upload step.

  • The checkout is updated to fetch-depth: 0 + persist-credentials: false so SonarCloud gets accurate blame history without leaving credentials in .git/config.
  • The separate "Run tests" and "Generate coverage report" steps are collapsed into a single bun run test:coverage invocation, and the SonarCloud scan is appended after Codecov upload with continue-on-error: true to keep the job non-blocking.
  • sonar-project.properties correctly scopes analysis to src/, points tests to test/**/*.test.ts, wires in the lcov report path, and excludes dist/** and coverage/**.

Confidence Score: 5/5

Safe to merge; both new steps are non-blocking and the sonar-project.properties config is correct for the repo layout.

The changes are purely additive CI configuration. All existing test, lint, type-check, and build steps are preserved unchanged. The SonarCloud action is pinned to a full commit SHA, the lcov path matches what bunfig.toml emits, and continue-on-error is applied consistently with the existing Codecov step. No production code is touched.

No files require special attention.

Important Files Changed

Filename Overview
.github/workflows/ci.yml Consolidates test + coverage into a single step, adds fetch-depth=0 and persist-credentials=false to checkout, and appends a non-blocking SonarCloud scan step after Codecov upload.
sonar-project.properties New SonarCloud config file with correct org/project key, src/test path separation, TypeScript tsconfig pointer, lcov coverage path, and dist/coverage exclusions.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant GH as GitHub Actions
    participant Bun as Bun Runtime
    participant Codecov as Codecov
    participant Sonar as SonarCloud

    GH->>GH: "checkout (fetch-depth=0, persist-credentials=false)"
    GH->>Bun: setup-bun
    GH->>Bun: bun install
    GH->>Bun: bun run lint
    GH->>Bun: bun run type-check
    GH->>Bun: bun run test:coverage
    Note over Bun: generates coverage/lcov.info
    Bun-->>GH: coverage/lcov.info ready
    GH->>Codecov: upload coverage/lcov.info (continue-on-error)
    GH->>Sonar: SonarCloud Scan (continue-on-error)
    Note over Sonar: reads sonar-project.properties, ingests coverage/lcov.info
    Sonar-->>GH: analysis complete
    GH->>Bun: bun run build
    GH->>GH: check dist/index.js + dist/index.d.ts
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant GH as GitHub Actions
    participant Bun as Bun Runtime
    participant Codecov as Codecov
    participant Sonar as SonarCloud

    GH->>GH: "checkout (fetch-depth=0, persist-credentials=false)"
    GH->>Bun: setup-bun
    GH->>Bun: bun install
    GH->>Bun: bun run lint
    GH->>Bun: bun run type-check
    GH->>Bun: bun run test:coverage
    Note over Bun: generates coverage/lcov.info
    Bun-->>GH: coverage/lcov.info ready
    GH->>Codecov: upload coverage/lcov.info (continue-on-error)
    GH->>Sonar: SonarCloud Scan (continue-on-error)
    Note over Sonar: reads sonar-project.properties, ingests coverage/lcov.info
    Sonar-->>GH: analysis complete
    GH->>Bun: bun run build
    GH->>GH: check dist/index.js + dist/index.d.ts
Loading

Reviews (3): Last reviewed commit: "chore: apply AI code review suggestions" | Re-trigger Greptile

Comment thread .github/workflows/ci.yml
Comment on lines +48 to +53
- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@713881670b6b3676cda39549040e2d88c70d582e # v8.2.0
continue-on-error: true
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: https://sonarcloud.io

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Without GITHUB_TOKEN in the step's env, the SonarCloud action cannot authenticate with the GitHub API to post inline analysis comments or the PR status check decoration. The dashboard upload still succeeds, but reviewers won't see any SonarCloud feedback directly on the PR.

Suggested change
- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@713881670b6b3676cda39549040e2d88c70d582e # v8.2.0
continue-on-error: true
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: https://sonarcloud.io
- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@713881670b6b3676cda39549040e2d88c70d582e # v8.2.0
continue-on-error: true
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: https://sonarcloud.io
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Prompt To Fix With AI
This is a comment left during a code review.
Path: .github/workflows/ci.yml
Line: 48-53

Comment:
Without `GITHUB_TOKEN` in the step's `env`, the SonarCloud action cannot authenticate with the GitHub API to post inline analysis comments or the PR status check decoration. The dashboard upload still succeeds, but reviewers won't see any SonarCloud feedback directly on the PR.

```suggestion
      - name: SonarCloud Scan
        uses: SonarSource/sonarqube-scan-action@713881670b6b3676cda39549040e2d88c70d582e # v8.2.0
        continue-on-error: true
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          SONAR_HOST_URL: https://sonarcloud.io
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

How can I resolve this? If you propose a fix, please make it concise.

Fix in Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks — I checked the official SonarSource/sonarqube-scan-action README (pinned v8.2.0). For SonarQube Cloud, the only required env is SONAR_TOKEN; SONAR_HOST_URL is needed only for self-hosted Server, and GITHUB_TOKEN is not among the action's documented inputs for Cloud. PR decoration (status check + inline comments) on SonarCloud is handled by the SonarCloud GitHub App installed during project onboarding — not by passing GITHUB_TOKEN to the scanner. Adding it would also re-expose the token to this third-party action that the coderabbit/cubic threads just had us remove via persist-credentials: false. So I'm leaving it out and relying on the GitHub App for decoration. Happy to revisit if decoration doesn't appear after onboarding.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You're right, and I apologize for the incorrect guidance. PR decoration on SonarCloud is indeed handled by the GitHub App installed during project onboarding — GITHUB_TOKEN is not a documented input for the cloud variant of the action, and adding it would contradict the persist-credentials: false posture already established. Your current setup is correct.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

@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

🧹 Nitpick comments (1)
.github/workflows/ci.yml (1)

48-53: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Skip the Sonar step when the token is unavailable.

This step always runs, so forked PRs or any repo without SONAR_TOKEN configured will emit a known failure on every CI run even though the job is marked non-blocking. Guarding it on secret presence keeps CI signal cleaner.

Suggested change
       - name: SonarCloud Scan
+        if: ${{ secrets.SONAR_TOKEN != '' }}
         uses: SonarSource/sonarqube-scan-action@713881670b6b3676cda39549040e2d88c70d582e # v8.2.0
         continue-on-error: true
         env:
           SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
           SONAR_HOST_URL: https://sonarcloud.io
🤖 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/ci.yml around lines 48 - 53, The SonarCloud Scan step in
the CI workflow always executes even when SONAR_TOKEN is missing, causing
avoidable failures on forks or repos without the secret. Update the workflow
condition for the SonarCloud Scan job step so it only runs when SONAR_TOKEN is
present, keeping the existing SonarSource/sonarqube-scan-action step and
continue-on-error behavior intact.
🤖 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/ci.yml:
- Around line 17-20: The checkout step in the CI workflow is leaving Git
credentials available to later steps. Update the actions/checkout usage in the
workflow so the checkout configuration for the existing checkout step includes
persist-credentials set to false while preserving the current fetch-depth
setting for SonarCloud attribution.

---

Nitpick comments:
In @.github/workflows/ci.yml:
- Around line 48-53: The SonarCloud Scan step in the CI workflow always executes
even when SONAR_TOKEN is missing, causing avoidable failures on forks or repos
without the secret. Update the workflow condition for the SonarCloud Scan job
step so it only runs when SONAR_TOKEN is present, keeping the existing
SonarSource/sonarqube-scan-action step and continue-on-error behavior intact.
🪄 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 Plus

Run ID: da6190cc-73eb-4a8a-a871-18a07fc2258c

📥 Commits

Reviewing files that changed from the base of the PR and between caa4d68 and 29f7999.

📒 Files selected for processing (2)
  • .github/workflows/ci.yml
  • sonar-project.properties

Comment thread .github/workflows/ci.yml

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 2 files

Architecture diagram
sequenceDiagram
    participant CI as CI Workflow
    participant Checkout as Checkout (fetch-depth:0)
    participant Test as Test (bun test --coverage)
    participant Coverage as coverage/lcov.info
    participant Sonar as SonarCloud Scan Action
    participant SC as SonarCloud Server

    CI->>Checkout: Check out repository
    Checkout->>Checkout: Full history for blame attribution

    CI->>Test: Run test:coverage
    Test->>Coverage: Generate lcov.info

    CI->>Sonar: SonarCloud Scan (continue-on-error: true)
    Note over Sonar: Uses SONAR_TOKEN from repo secrets
    Note over Sonar: SONAR_HOST_URL = https://sonarcloud.io
    Sonar->>Sonar: Read sonar-project.properties
    Sonar->>Sonar: Resolve org=pleaseai, projectKey=pleaseai_cli-toolkit
    Sonar->>Coverage: Read coverage/lcov.info
    Sonar->>SC: Upload analysis with coverage
    SC-->>Sonar: Analysis acknowledged
    Sonar-->>CI: Scan completed (failure ignored)
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread .github/workflows/ci.yml
bun test ran, then bun test --coverage re-ran the whole suite. The coverage
run already executes and gates on the same tests, so the standalone step was
duplicate work. Keep only the coverage run.
@amondnet

Copy link
Copy Markdown
Contributor Author

Added a small related CI cleanup in 7ef6043: removed the redundant standalone bun test step. The job ran bun test and then bun test --coverage, which re-ran the whole suite — the coverage step already runs and gates on the same tests.

Re: the new parallel-steps Actions feature — it's technically applicable (single job, independent lint/type-check/test/build steps) but the benefit is marginal for this ~18s job and the feature is too new to verify (exact background/wait-all syntax + failure semantics). Holding off for now; the dedupe is the higher-value, zero-risk win.

- ci.yml: set persist-credentials: false on checkout so the GITHUB_TOKEN is
  not persisted in .git/config for the third-party SonarCloud action (zizmor
  artipacked)
- sonar-project.properties: add sonar.typescript.tsconfigPath for type-aware
  TypeScript analysis
@sonarqubecloud

Copy link
Copy Markdown

@amondnet
amondnet merged commit 0c8350c into main Jun 27, 2026
8 checks passed
@amondnet
amondnet deleted the ci/sonarcloud-scan branch June 27, 2026 08:31
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.

1 participant