ci(sonarcloud): switch to CI-based analysis with Vitest coverage

SonarCloud's Automatic Analysis is off. The new `sonarcloud` job in
ci.yml runs SonarSource/sonarqube-scan-action v8.3.0 after `check`, with
the LCOV report that `check` now uploads; it never installs npm packages,
so SONAR_TOKEN never shares a job with them, and it fails with the
quality gate. Fork and Dependabot PRs skip it (no repository secrets).

sonar-project.properties analyses the tests as tests, imports the
coverage and excludes from it everything Vitest does not measure. Vitest
now also measures src/config, src/store and src/utils, next to the
engine, the Worker and the build plugins. The job passes package.json's
version as sonar.projectVersion, so the "previous version" new-code
period starts again at every release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
poli0981andClaude Opus 5.5 committed 2026-10-24 08:38:24 +07:00
1 parent 1858df90e5
commit d7a86d581e
8 files changed
+194 -63

No files matched your search

+57 -2
View File
@@ -6,8 +6,9 @@ on:
pull_request:
branches: [main]
# Least privilege. The job only reads the repo — it publishes nothing, comments
# nowhere. Declaring it explicitly also silences CodeQL's
# Least privilege. The jobs only read the repo — they publish nothing on
# GitHub and comment nowhere (SonarCloud's own GitHub app reports on PRs, with
# its own permissions). Declaring it explicitly also silences CodeQL's
# `actions/missing-workflow-permissions`, which otherwise flags the implicit
# (and much wider) default token scope.
permissions:
@@ -61,6 +62,14 @@ jobs:
# Coverage thresholds for src/engine and worker live in vitest.config.ts.
- name: Test (with coverage thresholds)
run: npm run test:coverage
# The LCOV report the `sonarcloud` job hands to SonarCloud.
- name: Keep the coverage report for SonarCloud
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: coverage
path: coverage/lcov.info
if-no-files-found: error
retention-days: 1
# --- consistency ------------------------------------------------------
- name: Check formatting
@@ -104,3 +113,49 @@ jobs:
# Builds will — without deploying anything.
- name: Dry-run the Cloudflare deploy
run: npm run cf:check
# SonarCloud, CI-based: issues, duplication and the coverage from `check`,
# judged by the quality gate (settings in sonar-project.properties).
# Automatic Analysis is off in the project's settings, so this is the only
# analysis. A job of its own so that SONAR_TOKEN never shares a job with
# npm packages: it only checks out, takes the coverage report and runs the
# scanner.
#
# PRs from forks and from Dependabot get no repository secrets (Dependabot
# PRs get the Dependabot secrets, which hold no SONAR_TOKEN), so they skip
# it and main is analysed once they merge. The PR author, not
# `github.actor`, decides — the actor can be spoofed (zizmor: bot-conditions).
sonarcloud:
needs: check
if: >-
github.event_name == 'push' ||
(github.event.pull_request.head.repo.full_name == github.repository &&
github.event.pull_request.user.login != 'dependabot[bot]')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Full history: SonarCloud tells new code from old by git blame.
fetch-depth: 0
persist-credentials: false
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: coverage
path: coverage
# New code is "since the previous version": each release starts a new
# period, and SonarCloud learns the version from here.
- name: Read the app version
id: version
run: |
version="$(jq -r .version package.json)"
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::package.json version \"$version\" is not X.Y.Z"
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: SonarCloud scan
uses: SonarSource/sonarqube-scan-action@d209202bc7d53ff1cc128f7f907dac145c9d6ae9 # v8.3.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: -Dsonar.projectVersion=${{ steps.version.outputs.version }}