Files
craft-common-actions/.github/workflows/sonar-scan.yml
T
Dylan M. Taylor fc9e47894e ci(sonar): skip SonarCloud scan on fork pull requests (#48)
GitHub does not expose repository secrets (including SONAR_TOKEN) to pull
requests opened from forks. Because the reusable sonarcloud.yml declared
SONAR_TOKEN as a required secret and sonar-scan.yml called it with
`secrets: inherit` on every pull_request, fork PRs failed immediately with:

  Error when evaluating 'secrets' ... Secret SONAR_TOKEN is required, but not
  provided while calling.

This made every fork PR show a failing "SonarCloud Scan" check unrelated to the
PR's contents. (The separate SonarCloud GitHub App check, "SonarCloud Code
Analysis", is unaffected and continues to run.)

Fixes:
- Gate the caller job so it only runs on pushes to main and on same-repo PRs;
  fork PRs now report a neutral skipped status instead of a hard failure.
- Make SONAR_TOKEN optional in the reusable workflow and guard the scan step on
  the token being present, so a missing token never fails the workflow.

Verified with actionlint.
2026-10-21 19:04:08 -04:00

27 lines
716 B
YAML

name: SonarCloud Scan
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
concurrency:
group: sonarcloud-${{ github.ref }}
cancel-in-progress: true
jobs:
sonarcloud:
# SonarCloud needs the SONAR_TOKEN secret, which GitHub does not expose to
# pull requests from forks. Skip the scan for fork PRs so they report a
# neutral "skipped" status instead of a hard failure; it still runs on pushes
# to main and on same-repo pull requests.
if: >-
github.event_name == 'push' ||
github.event.pull_request.head.repo.full_name == github.repository
uses: ./.github/workflows/sonarcloud.yml
secrets: inherit