Skip to content

ci: run SonarCloud PR analysis for fork pull requests#24214

Open
stian-sandvold wants to merge 2 commits into
dhis2:masterfrom
stian-sandvold:ci/sonar-fork-pr-analysis
Open

ci: run SonarCloud PR analysis for fork pull requests#24214
stian-sandvold wants to merge 2 commits into
dhis2:masterfrom
stian-sandvold:ci/sonar-fork-pr-analysis

Conversation

@stian-sandvold

Copy link
Copy Markdown
Contributor

PRs opened from forks fail the SonarCloud check: GitHub does not expose repository secrets (DHIS2_BOT_SONARCLOUD_TOKEN) to pull_request runs triggered by a fork, so the token guard in analyse-pr.yml hard-fails.

Split the PR path into the two-workflow pattern SonarSource recommends for forks:

  • analyse-pr.yml (pull_request, no secrets): builds the PR and uploads the built workspace + PR metadata + sibling SNAPSHOT module artifacts as an artifact. The long-living-branch (push/dispatch) analysis still runs inline, where secrets are available.
  • analyse-pr-sonar.yml (workflow_run): runs in the base-repo context with the token, downloads the artifact and runs mvn sonar:sonar, decorating the originating PR.

The untrusted PR build runs without the token. workflow_run always uses the default-branch workflow definition, so a fork cannot alter the analysis steps.

PRs opened from forks fail the SonarCloud check: GitHub does not expose
repository secrets (DHIS2_BOT_SONARCLOUD_TOKEN) to pull_request runs
triggered by a fork, so the token guard in analyse-pr.yml hard-fails.

Split the PR path into the two-workflow pattern SonarSource recommends
for forks:

- analyse-pr.yml (pull_request, no secrets): builds the PR and uploads
  the built workspace + PR metadata + sibling SNAPSHOT module artifacts
  as an artifact. The long-living-branch (push/dispatch) analysis still
  runs inline, where secrets are available.
- analyse-pr-sonar.yml (workflow_run): runs in the base-repo context
  with the token, downloads the artifact and runs `mvn sonar:sonar`,
  decorating the originating PR.

The untrusted PR build runs without the token. workflow_run always uses
the default-branch workflow definition, so a fork cannot alter the
analysis steps.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@stian-sandvold stian-sandvold requested a review from a team as a code owner June 14, 2026 12:21
Keep the secrets out of build-pr, which builds untrusted fork PR code —
they belong only to analyse-branch (push/dispatch, never a fork).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant