ci: run SonarCloud PR analysis for fork pull requests#24214
Open
stian-sandvold wants to merge 2 commits into
Open
ci: run SonarCloud PR analysis for fork pull requests#24214stian-sandvold wants to merge 2 commits into
stian-sandvold wants to merge 2 commits into
Conversation
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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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.