Skip to content

Add SonarCloud Job Summary to Actions workflow#62

Merged
304NotModified merged 3 commits intomainfrom
copilot/add-github-actions-job-summary
Apr 7, 2026
Merged

Add SonarCloud Job Summary to Actions workflow#62
304NotModified merged 3 commits intomainfrom
copilot/add-github-actions-job-summary

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

SonarCloud results were not surfaced anywhere in the GitHub Actions UI after a workflow run. This adds a Job Summary step so each run links directly to the SonarCloud results.

Changes

  • .github/workflows/sonarcloud.yml — appended a SonarCloud summary step after End SonarCloud analysis:
    • Runs with if: always() to ensure the summary is written even if analysis fails
    • On pull request runs, links to the PR-specific SonarCloud results page (/summary/new_code?id=slnx-validator&pullRequest=<number>)
    • On push/manual runs, links to the general project overview (/project/overview?id=slnx-validator)
- name: SonarCloud summary
  if: always()
  env:
    PR_NUMBER: ${{ github.event.pull_request.number }}
  run: |
    echo "## 🔍 SonarCloud Analysis" >> $GITHUB_STEP_SUMMARY
    echo "" >> $GITHUB_STEP_SUMMARY
    if [ -n "$PR_NUMBER" ]; then
      echo "View full results: [sonarcloud.io/summary/new_code?id=slnx-validator&pullRequest=${PR_NUMBER}](https://sonarcloud.io/summary/new_code?id=slnx-validator&pullRequest=${PR_NUMBER})" >> $GITHUB_STEP_SUMMARY
    else
      echo "View full results: [sonarcloud.io/project/overview?id=slnx-validator](https://sonarcloud.io/project/overview?id=slnx-validator)" >> $GITHUB_STEP_SUMMARY
    fi
Original prompt

Goal

Add a GitHub Actions Job Summary to the SonarCloud workflow so that after each analysis, a summary with a link to the SonarCloud results is shown in the Actions tab.

Change

In .github/workflows/sonarcloud.yml, add a step after the "End SonarCloud analysis" step that writes a Job Summary to $GITHUB_STEP_SUMMARY:

      - name: SonarCloud summary
        if: always()
        run: |
          echo "## 🔍 SonarCloud Analysis" >> $GITHUB_STEP_SUMMARY
          echo "" >> $GITHUB_STEP_SUMMARY
          echo "View full results: [sonarcloud.io/project/overview?id=slnx-validator](https://sonarcloud.io/project/overview?id=slnx-validator)" >> $GITHUB_STEP_SUMMARY

This step should be appended at the end of the steps list in the sonarcloud job, after the existing "End SonarCloud analysis" step.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Ik heb dit probleem. Kan ik dit fixen zodat dat sq zomaar code enzo kan pushen? @304NotModified/SLNX-validator/issues/59

Assistant: Het probleem is duidelijk: SonarCloud rapporteert niet op pull requests omdat de workflow onvoldoende permissies heeft. Dit is een bekende beperking van SonarCloud met GitHub Actions.

Oorzaak

SonarCloud heeft de permissie pull-requests: write nodig om comments te kunnen plaatsen op een PR. Die ontbreekt nu in je workflow. Daarnaast is er nog een tweede probleem: bij PR's van forks heeft SonarCloud geen toegang tot secrets, maar dat speelt hier waarschijnlijk minder.

Fix

Voeg pull-requests: write toe aan de permissions in je sonarcloud.yml:

    permissions:
      contents: read
      id-token: write
      pull-requests: write   # ← dit toevoegen

Wil je dat ik een PR aanmaak om dit te fixen in 304NotModified/SLNX-validator?

User: Ja pr

Assistant: We wachten op jouw reactie op het dialoogvenster om verder te gaan met het aanmaken van de PR.

User: @copilot Accepted Confirmation: Confirm agent session

Assistant: Copilot is aan het werk! Je kunt de voortgang hier volgen:

data:
    - title: '[WIP] Add pull-requests: write permission in SonarCloud workflow'
      repository: 304NotModified/SLNX-validator
      url: https://github.com/copilot/tasks/pull/PR_kwDORgUFCs7QK_Df?session_id=1829fa61-9e73-4502-baf2-bf6e6b1c118b
      state: queued

Zodra de PR klaar is, kun je hem reviewen en mergen. 🚀

User: Is dat 2de probleem oplosbaar zonder security issues?

Assistant: Je doelt op het probleem met PRs van forks — daar hebben workflows geen toegang tot secrets (zoals SONAR_TOKEN), wat een bewuste GitHub-beveiligingsmaatregel is.

Het probleem

Bij fork-PR's draait de workflow in de context van de fork, zonder toegang tot secrets van het originele repo. SonarCloud kan dan niet authenticeren en rapporteert dus niet.

Oplossing: pull_request_target

Je kunt pull_request_target gebruiken in plaats van pull_request. Dit event draait de workflow in de context van het base repo (met toegang tot secrets), ook voor fork-PR's.

⚠️ Beveiligingsrisico: Als je zomaar code uit de fork uitvoert (build, test, etc.) met pull_request_target, kan een aanvaller kwaadaardige code injecteren die jouw secrets steelt.

Veilige aanpak: twee-stappen workflow

De aanbevolen veilige aanpak is een gesplitste workflow:

  1. Workflow 1 — draait op pull_request (geen secrets), voert build & tests uit en slaat het resultaat op als artifact.
  2. Workflow 2 — draait op workflow_run (heeft secrets), pakt het artifact op en stuurt het naar SonarCloud.

Dit is precies de aanpak die SonarCloud zelf aanbeveelt. Zie: SonarCloud docs – Automatic analysis with GitHub Actions (forks).


Kort antwoord: Ja, het is oplosbaar zonder security issues, maar het vereist een wat complexere twee-workflow setup. Wil je dat ik daar ook een PR voor maak?

User: Workflow 2 doe ik dan handmatig starten? Kan ik niet een soort commando geven in de pr om sq te draaien? Er is nu ook al een approve workflows run?

Assistant: Goede vraag! Je hebt een paar opties:

Optie 1: Approve & run (wat je nu al hebt)

GitHub heeft ingebouwd dat je voor fork-PR's de workflow handmatig kunt approven. Dit is al veilig — jij keurt de code goed voordat er iets draait. Als je na approve de workflow runt, heeft die wél toegang tot secrets.

Nadeel: Je moet elke keer handmatig approven via de GitHub UI.


Optie 2: /sonar commando via issue_comment trigger

Ja, dit kan! Je maakt een workflow die luistert naar een comment op een PR, bijvoorbeeld /sonar, en dan de analyse draait. Dit heet een slash command of ChatOps patroon.

on:
  issue_comment:
...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

Agent-Logs-Url: https://github.com/304NotModified/SLNX-validator/sessions/317ec9e9-0ffd-4326-9b98-20c4631bca49

Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
Copilot AI changed the title [WIP] Add GitHub Actions job summary to SonarCloud workflow Add SonarCloud Job Summary to Actions workflow Apr 6, 2026
Copilot AI requested a review from 304NotModified April 6, 2026 10:38
Copilot AI requested a review from 304NotModified April 7, 2026 21:09
@304NotModified 304NotModified marked this pull request as ready for review April 7, 2026 21:17
@304NotModified 304NotModified added the build CI build stuff label Apr 7, 2026
@304NotModified 304NotModified merged commit 8fb9fa8 into main Apr 7, 2026
5 checks passed
@304NotModified 304NotModified deleted the copilot/add-github-actions-job-summary branch April 7, 2026 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build CI build stuff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants