Files
vectorcraft/.github/workflows/sonarcloud.yml
T
dotCooCoo 1bc0c5ba78 CI: analyze main in SonarCloud only at the nightly's commit
SonarCloud ran a full instrumented analysis for every merge commit on main
(about 90 a day, 97 to 191 minutes each). Stage 2 only reads the analysis
of the commit the nightly builds, so main is now analyzed once a day:

- sonarcloud.yml drops the push trigger and starts when the unsigned
  nightly starts (workflow_run, requested). A first job fails the run when
  main has moved past the nightly's commit, so the analysis is never of
  another commit. Pull request analysis is unchanged.
- nightly-dispatch.yml waits, for up to 280 minutes, for the SonarCloud
  check on the producer's commit to complete before it dispatches the
  signer. A SonarCloud run that ended without a check stops the wait after
  20 minutes. The job gains checks: read and a 300-minute timeout.
- packaging/nightly-release-tests.py runs the dispatch script against a
  fake API: it dispatches only after the check completes, and refuses when
  the SonarCloud run ended without one or when the deadline passes.
- docs/nightly-release-preparation.md describes both workflows.
2026-12-05 08:06:12 -08:00

56 lines
2.2 KiB
YAML

name: SonarCloud
# Main is analyzed once a day, at the commit the nightly builds: Stage 2 admits a nightly only on
# that commit's own analysis, and nightly-dispatch.yml waits for it before dispatching the signer.
on:
workflow_dispatch:
workflow_run:
workflows: [VectorCraft unsigned nightly]
types: [requested]
branches: [main]
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
concurrency:
group: ${{ github.ref == 'refs/heads/main' && format('sonarcloud-main-{0}', github.sha) || format('sonarcloud-{0}', github.ref) }}
# A main run is the analysis a nightly waits for; superseded runs there would never finish.
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
nightly-commit:
name: Nightly commit is main's head
# A workflow_run checks out and analyzes main's head, so main must not have moved since the
# nightly started.
if: github.event_name == 'workflow_run'
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- name: Require main's head to be the nightly's commit
env:
NIGHTLY_SHA: ${{ github.event.workflow_run.head_sha }}
RUN_SHA: ${{ github.sha }}
run: |
if [ "$NIGHTLY_SHA" != "$RUN_SHA" ]; then
echo "::error::main moved from $NIGHTLY_SHA to $RUN_SHA after the nightly started; this run would not analyze the nightly's commit"
exit 1
fi
sonarcloud:
needs: nightly-commit
if: ${{ !cancelled() && contains(fromJSON('["success","skipped"]'), needs.nightly-commit.result) }}
# Tracked at @main so org-wide CI improvements propagate without PR churn.
# The reusable workflow defaults build-jobs to 2 so a cold instrumented
# archive stays within hosted-runner memory (craft-common-actions#333).
uses: storytold/craft-common-actions/.github/workflows/sonarcloud.yml@main
with:
python-coverage-source: .github/scripts
python-coverage-script: .github/scripts/tests/test_release_rpm_smoke.py
secrets: inherit