|
| 1 | +# SonarCloud quality gate + coverage upload. |
| 2 | +# |
| 3 | +# Triggers: push to main (full-history scan) and PRs (incremental scan |
| 4 | +# against the base branch). Concurrency-gated per-ref so reruns cancel |
| 5 | +# in-flight scans. |
| 6 | +# |
| 7 | +# Coverage is collected fresh in this workflow rather than reused from |
| 8 | +# CI — Sonar needs both go-coverprofile and lcov in the same workspace |
| 9 | +# pass, and the existing CI job runs `go test` without -coverprofile. |
| 10 | +# Adding coverage there would slow every PR build; keeping it here |
| 11 | +# isolates the cost to the Sonar job. |
| 12 | + |
| 13 | +name: SonarCloud |
| 14 | + |
| 15 | +on: |
| 16 | + push: |
| 17 | + branches: [main] |
| 18 | + pull_request: |
| 19 | + types: [opened, synchronize, reopened] |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: read |
| 23 | + pull-requests: read |
| 24 | + |
| 25 | +concurrency: |
| 26 | + group: sonar-${{ github.workflow }}-${{ github.ref }} |
| 27 | + cancel-in-progress: true |
| 28 | + |
| 29 | +jobs: |
| 30 | + scan: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + steps: |
| 33 | + - name: Checkout |
| 34 | + uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + # Sonar uses git blame for new-code detection — shallow |
| 37 | + # checkouts (default fetch-depth=1) attribute every line to |
| 38 | + # the latest commit, breaking the quality-gate "new code" |
| 39 | + # signal. fetch-depth: 0 grabs the full history. |
| 40 | + fetch-depth: 0 |
| 41 | + |
| 42 | + - name: Set up Go |
| 43 | + uses: actions/setup-go@v5 |
| 44 | + with: |
| 45 | + go-version-file: go.mod |
| 46 | + |
| 47 | + - name: Set up pnpm |
| 48 | + # Pinned to commit SHA (v4) per supply-chain hygiene — third-party |
| 49 | + # actions can be rewritten under a moving tag. Bump by re-running |
| 50 | + # `gh api repos/pnpm/action-setup/git/refs/tags/v4`. |
| 51 | + uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4 |
| 52 | + with: |
| 53 | + version: 10.33.0 |
| 54 | + |
| 55 | + - name: Set up Node |
| 56 | + uses: actions/setup-node@v4 |
| 57 | + with: |
| 58 | + node-version: 22 |
| 59 | + cache: pnpm |
| 60 | + cache-dependency-path: ui/pnpm-lock.yaml |
| 61 | + |
| 62 | + - name: Build UI bundle |
| 63 | + # Required before any Go test run: //go:embed all:dist in |
| 64 | + # internal/serve/assets.go errors out if internal/serve/dist/ |
| 65 | + # is empty. Same as ci.yml. |
| 66 | + run: make ui |
| 67 | + |
| 68 | + - name: Go test with coverage |
| 69 | + run: | |
| 70 | + go test -tags sqlite_fts5 \ |
| 71 | + -coverprofile=coverage.out \ |
| 72 | + -covermode=atomic \ |
| 73 | + ./... |
| 74 | +
|
| 75 | + - name: UI install |
| 76 | + # --ignore-scripts: refuse to execute lifecycle scripts from |
| 77 | + # transitive deps (Sonar S6505). vitest + the React stack don't |
| 78 | + # require any postinstall; esbuild ships per-platform binaries |
| 79 | + # via optional deps. If a future dep needs a build step, add it |
| 80 | + # to `pnpm.onlyBuiltDependencies` in ui/package.json instead. |
| 81 | + run: pnpm -C ui install --frozen-lockfile --ignore-scripts |
| 82 | + |
| 83 | + - name: UI test with coverage |
| 84 | + run: pnpm -C ui exec vitest run --coverage |
| 85 | + |
| 86 | + - name: Detect SONAR_TOKEN |
| 87 | + id: token |
| 88 | + env: |
| 89 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 90 | + run: | |
| 91 | + if [ -n "$SONAR_TOKEN" ]; then |
| 92 | + echo "present=true" >> "$GITHUB_OUTPUT" |
| 93 | + else |
| 94 | + echo "present=false" >> "$GITHUB_OUTPUT" |
| 95 | + echo "::warning::SONAR_TOKEN secret is not set; skipping SonarCloud scan. Add the token in repo Settings → Secrets and variables → Actions." |
| 96 | + fi |
| 97 | +
|
| 98 | + - name: SonarCloud Scan |
| 99 | + if: steps.token.outputs.present == 'true' |
| 100 | + # v6 — v5 emits a deprecation/security warning on every run. |
| 101 | + # Pinned to commit SHA per supply-chain hygiene. Bump by |
| 102 | + # re-running `gh api repos/SonarSource/sonarqube-scan-action/git/refs/tags/v6`. |
| 103 | + uses: SonarSource/sonarqube-scan-action@fd88b7d7ccbaefd23d8f36f73b59db7a3d246602 # v6 |
| 104 | + env: |
| 105 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
0 commit comments