1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
name: SonarQube Cloud
# Static analysis on sonarcloud.io (free plan for public repos, #284).
# Project binding lives in sonar-project.properties; the analysis is CI-based
# (Rust needs a real `cargo clippy` run, which SonarQube Cloud's automatic
# analysis cannot do), so Automatic Analysis must stay OFF in the SonarCloud
# project settings or every scan fails with a conflict.
#
# Every step is gated on SONAR_TOKEN so the job is a green no-op on fork PRs
# (secrets are withheld there) and on checkouts where the secret has not been
# configured yet - analysis coverage degrades, CI does not break.
on:
push:
branches:
pull_request:
# The scan authenticates to SonarQube Cloud with SONAR_TOKEN and PR decoration
# goes through SonarCloud's own GitHub App, so the workflow token only has to
# read the checkout.
permissions:
contents: read
jobs:
sonarcloud:
name: SonarQube Cloud analysis
runs-on: ubuntu-latest
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
steps:
- name: Skip without a token
if: env.SONAR_TOKEN == ''
run: echo "::notice::SONAR_TOKEN is not available (fork PR, or the secret is not configured); skipping SonarQube Cloud analysis."
- uses: actions/checkout@v7
if: env.SONAR_TOKEN != ''
with:
# Full history: SonarQube Cloud needs blame data to attribute issues
# and to tell new code from old on PRs.
fetch-depth: 0
# rust-toolchain.toml is the single source of truth; `rustup show`
# installs exactly the pinned channel and its components (clippy
# included). The scanner's own Clippy execution is disabled in
# sonar-project.properties precisely so this pinned run is the only one.
- name: Install the pinned toolchain
if: env.SONAR_TOKEN != ''
run: rustup show
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
if: env.SONAR_TOKEN != ''
with:
key: sonarcloud
- name: Generate the Clippy report
if: env.SONAR_TOKEN != ''
# No `-D warnings` here: the `clippy + tests` job in ci.yml is the
# gate. This run only produces the JSON report SonarQube imports, so
# warnings must land in the report, not kill the job.
#
# `|| true`: a compile error is already reported by ci.yml's gate job;
# failing here too would only add a second red X and skip the import
# of whatever diagnostics Clippy did emit before dying.
run: cargo clippy --all-targets --message-format=json > clippy-report.json || true
- name: SonarQube Cloud scan
if: env.SONAR_TOKEN != ''
# Pinned to a commit, not the v8 tag: this step can read SONAR_TOKEN,
# and a tag can be moved to different code. .github/dependabot.yml
# keeps the pin current.
uses: SonarSource/sonarqube-scan-action@ba9859eae8dd6bd29e412f25ddbbef3d032000f4 # v8.2.2