fix(sonarcloud): fail the required SonarCloud check on a failed quality gate
Summary
A failed SonarCloud quality gate did not fail the required SonarCloud check. The Actions job ran sonarqube-scan-action without sonar.qualitygate.wait, so it passed as soon as the analysis uploaded. This PR makes the job wait for the gate on pull requests and fail when it fails.
Evidence (step 1)
GitHub side: across the last 40 PRs of 13 combsmith repos (485 PRs), every SonarCloud Code Analysis run concluded success, so I asked SonarCloud directly (api/project_pull_requests/list) for PRs whose gate status is not OK. It returned 5. In all 5 the Actions SonarCloud job was green:
| PR | Gate (SonarCloud Code Analysis, sonarqubecloud) | SonarCloud (github-actions) | SonarCloud (github-advanced-security) | Outcome |
|---|---|---|---|---|
| combsmith/software-factory#59 | failure โ "Quality Gate failed" | success | success ("No new alerts") | merged 2026-10-15 |
| combsmith/software-factory#67 | failure | success | success ("No new alerts") | merged 2026-10-15 |
| combsmith/software-factory#69 | failure | success | failure (3 high-severity alerts) | merged 2026-10-15 |
| combsmith/broodminder-data#230 | failure | success | failure (1 high-severity alert) | open, BLOCKED |
| combsmith/broodly#51 | failure | failure (an older run, 2026-10-02, not the gate) | success | open, DIRTY |
Notes:
- software-factory does not apply the
code-qualityruleset (itsmainruleset requires onlyverify), so its merges show the job's behaviour, not a ruleset bypass. - broodminder-data#230 applies
code-quality. GraphQLisRequiredmarks bothSonarCloudcheck runs as required (the context has nointegration_id): the Actions run is green, and the code-scanning run from github-advanced-security is red because Sonar's import found a high-severity alert. So today only the code-scanning check can block a Sonar finding, and only for new security alerts. Gate conditions like coverage, duplication or maintainability never block. software-factory#59/#67 had exactly that kind of failure ("No new alerts"). In acode-qualityrepo both required runs would have passed (inferred: nocode-qualityrepo had such a PR). - The claim in
ci-standards.mdthat the gate blocks the required check (bmad-bgreat-suite#334, and the dev-lead adoption note) held only because S7637 is a security finding, which fails the code-scanning check. The doc now says so.
Fix
The other option was to require SonarCloud Code Analysis bound to the sonarqubecloud app. I didn't take it because that check comes from an external app, not from a workflow that triggers on merge_group. merge-group.bats rejects such a required context, and a fresh repo with no SONAR_TOKEN would also be blocked from day 0.
Changes in .github/workflows/sonarcloud.yml and standards/workflows/sonarcloud.yml:
- Scan and retry pass
-Dsonar.qualitygate.wait=trueonpull_requestonly. Onpush, a main-branch verdict could only fail a run after the merge. Onmerge_group, it would stall the queue on main's long-term gate. - The retry now runs only when no analysis was uploaded:
hashFiles('.scannerwork/report-task.txt') == ''. The scanner writes that file right after upload and before it waits for the gate (ReportPublisher.execute()โQualityGateCheck.await()inSpringProjectScanContainer, checked in SonarSource/sonarqubebranch-10.8). So a gate failure is not re-analysed, and a CDN blip still gets its retry. - New step
Fail on SonarCloud quality gate: it runs when the first attempt failed and the retry was skipped, and exits 1. Without it,continue-on-erroron the first attempt would leave the job green. - No new actions and no pin changes.
Docs: standards/ci-standards.md ยง3 adds the gate wait, a table of the three Sonar check runs, and the corrected retry rationale. The ยง3 snippet is synced to the template's current pins (it still showed checkout v6.0.3 / scan v8.1.0). The S7637 spike note and the dev-lead adoption note are corrected.
Tests: new test/workflows/required-checks/sonarcloud-quality-gate.bats covers both files: the wait on scan and retry, the wait limited to pull_request, the retry guard and the fail step. I ran it against two broken versions (retry guard removed, fail step removed) and it failed both times. required-checks-tests.yml now also triggers on the template.
Not verified
- No PR has run the new wiring against a failing gate yet. This PR's own Sonar run will exercise the passing path only.
- Repos that copied the template need the change synced.
sonarcloud.ymlis set up per repo, not swept bydeploy-standard-workflows.
Test plan
-
bats test/workflows/required-checks/(16/16 locally) -
actionlinton the changed workflows - CI green on this PR, including
SonarCloudwith the gate wait
๐ค Generated with Claude Code