Skip to content

ci: add SonarCloud analysis for the monorepo - #272

Merged
Battambang merged 13 commits into
mainfrom
feat/sonarcloud-setup
Sep 4, 2026
Merged

ci: add SonarCloud analysis for the monorepo#272
Battambang merged 13 commits into
mainfrom
feat/sonarcloud-setup

Conversation

@Battambang

Copy link
Copy Markdown
Contributor

Explanation

The archived snap-solana-wallet repo used SonarCloud to analyze every PR (the sonarqubecloud bot comment with quality gate, issues, coverage, and duplication). After migrating to this monorepo, that analysis was lost. The SonarCloud project MetaMask_internal-snaps and GitHub App have been set up, but the project currently runs Automatic Analysis, which cannot import coverage and does not read any in-repo configuration.
This PR switches the repo to CI-based analysis, matching the pattern used by metamask-extension and metamask-mobile:

  • Root sonar-project.properties — one SonarCloud project covering all published packages under packages/. sample-snap is excluded (private hello-world fixture not in the CI test matrix), along with tests, build artifacts, images, snapshots, and mocks. The projectKey is MetaMask_internal-snaps, confirmed against the live PR decoration.
  • Coverage from the test matrix — the test job in lint-build-test.yml now rewrites Jest's package-relative SF: paths to repo-root-relative paths and uploads packages/<dir>/coverage/lcov.info as a per-package artifact, but only for one Node version (22.x) so lcov files are never merged across runs. stellar-wallet-snap now collects coverage (collectCoverage: true); the other packages already did.
  • New reusable sonarcloud.yml workflow — downloads the coverage artifacts and runs SonarSource/sonarqube-scan-action (v7.1.0, SHA-pinned, same as extension) with fetch-depth: 0. Called from main.yml on same-repo PRs and pushes to main; skipped for forks (no SONAR_TOKEN) and merge-queue commits.
    The scan is deliberately non-blocking: it is not part of all-jobs-complete, so a SonarCloud outage cannot block merges.

References

Checklist

  • [] I've updated the test suite for new or updated code as appropriate
  • [] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • [] I've communicated my changes to consumers by updating changelogs for packages I've changed
  • [] I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Configure a single SonarCloud project covering all packages in the
monorepo, adapted from the archived snap-solana-wallet setup.
Collect and upload lcov reports from the test matrix (one Node version)
with repo-root-relative paths, and enable coverage collection for the
Stellar snap.
Reusable workflow that downloads per-package lcov artifacts and uploads a CI-based analysis, called from main.yml on same-repo PRs and pushes to main. Non-blocking for now (not part of all-jobs-complete).
@Battambang
Battambang requested review from a team as code owners September 4, 2026 12:52
@Battambang
Battambang deployed to default-branch September 4, 2026 12:52 — with GitHub Actions Active
@Battambang Battambang changed the title Feat/sonarcloud setup ci: add SonarCloud analysis for the monorepo Sep 4, 2026
Comment thread .github/workflows/lint-build-test.yml Fixed
Comment thread .github/workflows/sonarcloud.yml Fixed
Comment thread .github/workflows/sonarcloud.yml Fixed
Comment thread .github/workflows/sonarcloud.yml Fixed
Comment thread .github/workflows/lint-build-test.yml Fixed
Comment thread .github/workflows/lint-build-test.yml Fixed
Comment thread .github/workflows/sonarcloud.yml Fixed
Pass the package directory through an env var instead of inline `${{ }}`
expansion in the `run` block, addressing the zizmor code-injection finding.
Pin actions/upload-artifact and actions/download-artifact to their v7
hashes to satisfy the repo blanket policy for unpinned action references.
Move pull-requests and checks write permissions from the workflow level
into the sonarcloud-scan job to satisfy the zizmor overly-broad-
permissions findings.
Comment thread .github/workflows/main.yml Fixed
gabrieledm
gabrieledm previously approved these changes Sep 4, 2026
@Battambang
Battambang enabled auto-merge September 4, 2026 13:43
@Battambang
Battambang disabled auto-merge September 4, 2026 13:53
@Battambang
Battambang enabled auto-merge September 4, 2026 13:53
ulissesferreira
ulissesferreira previously approved these changes Sep 4, 2026
mikesposito
mikesposito previously approved these changes Sep 4, 2026
@Battambang
Battambang disabled auto-merge September 4, 2026 14:22
@Battambang
Battambang enabled auto-merge September 4, 2026 14:22
The `uses:` caller job must explicitly grant the write scopes the
reusable sonarcloud.yml workflow requests (pull-requests, checks).
Removing them in 07d8201 made the Main workflow fail at startup, so
"All jobs pass" never reported. Restore them at the job level (not
workflow level) to keep the zizmor overbroad-permissions finding
resolved.
Single-file artifact uploads drop the source directory, and
merge-multiple flattened all lcov.info files into packages/, so the
scan found no coverage. Download each artifact into its own folder and
move it back to packages/<dir>/coverage/lcov.info to match
sonar.javascript.lcov.reportPaths.
@sonarqubecloud

sonarqubecloud Bot commented Sep 4, 2026

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@Battambang
Battambang added this pull request to the merge queue Sep 4, 2026
Merged via the queue into main with commit ecf7eea Sep 4, 2026
96 checks passed
@Battambang
Battambang deleted the feat/sonarcloud-setup branch September 4, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants