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>
162 lines
7.1 KiB
YAML
162 lines
7.1 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
branches: [main]
|
|
|
|
# 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:
|
|
contents: read
|
|
|
|
# A force-push or a quick follow-up commit makes the older run worthless. Cancel
|
|
# it instead of paying for both — except on `main`, where every commit's result
|
|
# is a historical record the release process reads back.
|
|
concurrency:
|
|
group: ci-${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
|
|
|
|
jobs:
|
|
# `check` is the required status on `main` (ruleset "main-protection") — keep
|
|
# the job id stable.
|
|
check:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
# Actions are pinned by commit SHA (a tag can be moved; a SHA cannot).
|
|
# Dependabot keeps the SHA and the version comment up to date.
|
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
persist-credentials: false
|
|
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
|
with:
|
|
node-version-file: .node-version
|
|
cache: npm
|
|
# No dependency lifecycle scripts, in every workflow. The only packages
|
|
# that have one (esbuild, workerd, fsevents) take their native binary
|
|
# from optionalDependencies; the script only double-checks it.
|
|
- run: npm ci --ignore-scripts
|
|
# `tsc` must be TypeScript 7 (@typescript/native). The `typescript` alias
|
|
# (@typescript/typescript6, the API typescript-eslint loads) pulls in
|
|
# TypeScript 6 as @typescript/old, which ships a `tsc` too — npm links the
|
|
# first one by path order. Fail loudly if that ever flips, instead of
|
|
# silently type-checking with 6.
|
|
- name: TypeScript 7 is the `tsc` on PATH
|
|
run: ./node_modules/.bin/tsc --version | grep -q '^Version 7\.'
|
|
|
|
# --- correctness ------------------------------------------------------
|
|
# `typecheck` covers src/ (what Vite builds); `typecheck:all` adds tests/,
|
|
# scripts/, worker/ and build-plugins/.
|
|
- name: Type check (src)
|
|
run: npm run typecheck
|
|
- name: Type check (tests, scripts, worker, build plugins)
|
|
run: npm run typecheck:all
|
|
- name: Lint
|
|
run: npm run lint
|
|
- name: Validate locales
|
|
run: npm run validate:locales
|
|
# 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
|
|
run: npm run format:check
|
|
- name: Check dead code
|
|
run: npm run knip
|
|
# The release ritual bumps SIX version fields by hand. This is the only
|
|
# thing that notices when one is missed — see scripts/check-version-sync.ts.
|
|
- name: Check version sync
|
|
run: npm run check:version
|
|
# tauri build refuses mismatched npm/crate minors, and CI never runs it.
|
|
- name: Check Tauri npm/crate alignment
|
|
run: npm run check:tauri
|
|
|
|
# --- licensing --------------------------------------------------------
|
|
# Every package bundled into the app has an allowed license, and
|
|
# THIRD_PARTY_NOTICES.md matches what is actually installed.
|
|
- name: Check licenses and third-party notices
|
|
run: npm run check:licenses
|
|
# NOTICE, REUSE.toml and the installers' copyright string state the
|
|
# years ("2026", later "2026-2027"). The first commit in a new year
|
|
# fails here until `npm run update:copyright` extends them.
|
|
- name: Check copyright years
|
|
run: npm run check:copyright
|
|
|
|
# --- security ---------------------------------------------------------
|
|
# Advisory-only: a fresh high-severity advisory in a transitive dep must
|
|
# not turn every unrelated PR red before Dependabot has had a chance to
|
|
# open its fix PR. The Dependabot alerts tab is the source of truth, and
|
|
# dependency-review (security.yml) blocks PRs that *introduce* one.
|
|
- name: Audit dependencies
|
|
run: npm audit --audit-level=high
|
|
continue-on-error: true
|
|
|
|
# --- build ------------------------------------------------------------
|
|
- name: Build
|
|
run: npm run build
|
|
- name: Check bundle budget
|
|
run: npm run check:bundle
|
|
# Validates wrangler.jsonc and bundles the Worker exactly as Workers
|
|
# 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 }}
|