Analysis matrix
Fork pull requests still run the complete test coverage and coverage-regression
checks in the unprivileged CI workflow. Their reports are not imported by the
privileged SonarCloud workflow, so SonarCloud does not calculate a coverage
metric for those pull requests.
The fork scan still reports static bugs, vulnerabilities, security hotspots,
and code smells. Scanner-side Clippy and software composition analysis are
disabled; Clippy remains part of the regular CI checks.
How it runs
.github/workflows/sonar.yml runs after the complete CI workflow succeeds.
Keeping it separate prevents SONAR_TOKEN from being available to jobs that
build or test contributor code.
- The workflow validates the pull request number, state, head SHA, repositories, and branches against the GitHub API. Invalid or stale context fails closed instead of becoming a branch analysis.
- It checks out the exact commit tested by CI. Fork source is read only by the scanner and is never built, installed, or used as tooling.
- It replaces
sonar-project.propertieswith the default branch’s trusted copy, preventing a fork from changing the server or enabling build tools. The analysed version comes from the same trusted checkout of.version, so that new code is measured since the previous release rather than since a constant version. - For a pull request, it fetches the target branch from the trusted upstream
repository and pins it locally under the name passed as
sonar.pullrequest.base. SonarCloud derives the changed-file set from git, so without the correct upstream base reference it may attribute unrelated changes to the pull request. A fork’s local base reference may be outdated. The step logs the analysed commit, base repository and branch, base commit, and merge-base, and fails closed if the reference cannot be resolved. - For internal changes, it downloads the coverage artifact from the triggering CI run. For forks, report paths are cleared and all sources are excluded only from the coverage calculation.
- Only the scanner step receives
SONAR_TOKEN.
Trust boundary
- Keep Automatic Analysis disabled and SonarCloud checks non-required.
- Restrict
SONAR_TOKENto analysis of this project. - Keep scanner-side Clippy and software composition analysis disabled.
- Do not import artifacts produced by a fork into the privileged scan.