fix(sonarcloud): fail the required SonarCloud check on a failed quality gate

Merged
DO
20d ago
+233-18

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:

PRGate (SonarCloud Code Analysis, sonarqubecloud)SonarCloud (github-actions)SonarCloud (github-advanced-security)Outcome
combsmith/software-factory#59failure โ€” "Quality Gate failed"successsuccess ("No new alerts")merged 2026-10-15
combsmith/software-factory#67failuresuccesssuccess ("No new alerts")merged 2026-10-15
combsmith/software-factory#69failuresuccessfailure (3 high-severity alerts)merged 2026-10-15
combsmith/broodminder-data#230failuresuccessfailure (1 high-severity alert)open, BLOCKED
combsmith/broodly#51failurefailure (an older run, 2026-10-02, not the gate)successopen, DIRTY

Notes:

  • software-factory does not apply the code-quality ruleset (its main ruleset requires only verify), so its merges show the job's behaviour, not a ruleset bypass.
  • broodminder-data#230 applies code-quality. GraphQL isRequired marks both SonarCloud check runs as required (the context has no integration_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 a code-quality repo both required runs would have passed (inferred: no code-quality repo had such a PR).
  • The claim in ci-standards.md that 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=true on pull_request only. On push, a main-branch verdict could only fail a run after the merge. On merge_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() in SpringProjectScanContainer, checked in SonarSource/sonarqube branch-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-error on 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.yml is set up per repo, not swept by deploy-standard-workflows.

Test plan

  • bats test/workflows/required-checks/ (16/16 locally)
  • actionlint on the changed workflows
  • CI green on this PR, including SonarCloud with the gate wait

๐Ÿค– Generated with Claude Code