|
| 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 | + uses: pnpm/action-setup@v4 |
| 49 | + with: |
| 50 | + version: 10.33.0 |
| 51 | + |
| 52 | + - name: Set up Node |
| 53 | + uses: actions/setup-node@v4 |
| 54 | + with: |
| 55 | + node-version: 22 |
| 56 | + cache: pnpm |
| 57 | + cache-dependency-path: ui/pnpm-lock.yaml |
| 58 | + |
| 59 | + - name: Build UI bundle |
| 60 | + # Required before any Go test run: //go:embed all:dist in |
| 61 | + # internal/serve/assets.go errors out if internal/serve/dist/ |
| 62 | + # is empty. Same as ci.yml. |
| 63 | + run: make ui |
| 64 | + |
| 65 | + - name: Go test with coverage |
| 66 | + run: | |
| 67 | + go test -tags sqlite_fts5 \ |
| 68 | + -coverprofile=coverage.out \ |
| 69 | + -covermode=atomic \ |
| 70 | + ./... |
| 71 | +
|
| 72 | + - name: UI install |
| 73 | + run: pnpm -C ui install --frozen-lockfile |
| 74 | + |
| 75 | + - name: UI test with coverage |
| 76 | + run: pnpm -C ui exec vitest run --coverage |
| 77 | + |
| 78 | + - name: Detect SONAR_TOKEN |
| 79 | + id: token |
| 80 | + env: |
| 81 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 82 | + run: | |
| 83 | + if [ -n "$SONAR_TOKEN" ]; then |
| 84 | + echo "present=true" >> "$GITHUB_OUTPUT" |
| 85 | + else |
| 86 | + echo "present=false" >> "$GITHUB_OUTPUT" |
| 87 | + echo "::warning::SONAR_TOKEN secret is not set; skipping SonarCloud scan. Add the token in repo Settings → Secrets and variables → Actions." |
| 88 | + fi |
| 89 | +
|
| 90 | + - name: SonarCloud Scan |
| 91 | + if: steps.token.outputs.present == 'true' |
| 92 | + uses: SonarSource/sonarqube-scan-action@v5 |
| 93 | + env: |
| 94 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
0 commit comments