Split SonarCloud workflow into two stages to support fork PRs#61
Draft
Split SonarCloud workflow into two stages to support fork PRs#61
Conversation
… support Agent-Logs-Url: https://github.com/304NotModified/SLNX-validator/sessions/893398da-ac70-4e25-a8e8-fd958d8df37f Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
… env vars Agent-Logs-Url: https://github.com/304NotModified/SLNX-validator/sessions/893398da-ac70-4e25-a8e8-fd958d8df37f Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Remove existing sonarcloud workflow and add new analysis workflows
Split SonarCloud workflow into two stages to support fork PRs
Apr 6, 2026
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.
SonarCloud analysis silently fails on fork PRs because
pull_requestworkflows don't have access to secrets. The fix is a two-stage workflow split so the secret-dependent analysis runs in the base repo context viaworkflow_run.Changes
.github/workflows/sonarcloud.yml.github/workflows/sonarcloud-build.yml— triggers onpush/pull_request, runs build + tests with coverage, serializes PR metadata (number, SHA, branch) to files, and uploads everything as asonar-artifactsartifact. No secrets required..github/workflows/sonarcloud-analyze.yml— triggers viaworkflow_runon completion of the build workflow. Downloads the artifact, conditionally sets PR vs. push sonarscanner args, then runs begin → build → end. Has access toSONAR_TOKENbecause it always executes in the base repo context.Security
PR number and branch are passed to
dotnet sonarscanner beginvia environment variables (not inline${{ }}expressions) to prevent code injection from attacker-controlled artifact content:Original prompt
Context
SonarCloud does not report on fork PRs because secrets are not available in
pull_requestworkflows from forks. The solution is to split the SonarCloud analysis into two workflows:sonarcloud-build.yml) — triggers onpull_requestandpushto main. Runs build, tests with coverage, and uploads the coverage XML + PR metadata as an artifact. No secrets needed.sonarcloud-analyze.yml) — triggers onworkflow_runcompleted from workflow 1. Downloads the artifact and runs the actual SonarCloud analysis with theSONAR_TOKENsecret. Runs in base repo context so secrets are available, even for fork PRs.What to do
1. Delete the existing
.github/workflows/sonarcloud.ymlRemove this file entirely — it will be replaced by the two new workflows below.
2. Create
.github/workflows/sonarcloud-build.yml3. Create
.github/workflows/sonarcloud-analyze.yml