Skip to content

Add GitHub Actions job summary to SonarCloud workflow#63

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-sonarcloud-summary-step
Draft

Add GitHub Actions job summary to SonarCloud workflow#63
Copilot wants to merge 2 commits intomainfrom
copilot/add-sonarcloud-summary-step

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

SonarCloud runs produced no visible output in the GitHub Actions UI — results were only accessible by navigating to sonarcloud.io directly.

Changes

  • .github/workflows/sonarcloud.yml: Added a SonarCloud summary step after End SonarCloud analysis that writes a markdown summary with a direct link to the SonarCloud dashboard into $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

if: always() ensures the summary is written even when earlier steps fail.

Original prompt

In the repository 304NotModified/SLNX-validator, add a GitHub Actions Job Summary step to .github/workflows/sonarcloud.yml.

The current last step in the file is "End SonarCloud analysis". Add the following step after it:

      - 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 adds a visible summary with a link to the SonarCloud dashboard in the GitHub Actions job summary after every run.

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

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:
    types: [created]

Dan check je of de comment /sonar is, of de commenter schrijfrechten heeft (belangrijk!), en dan draai je de analyse. issue_comment draait altijd in de context van het base repo → secrets beschikbaar ✅

Voordeel: Jij typt /sonar in de PR, SonarCloud draait.
Nadeel: Iets meer configuratie, en je moet de juiste branch/SHA ophalen uit de PR context.


Aanbeveling

Gezien je al een approve & run flow hebt, is de workflow_run aanpak (twee workflows) eigenlijk het meest naadloos:

  • Workflow 1 draait automatisch op de PR (geen secrets nodig)
  • Workflow 2 start automatisch ná workflow 1 via workflow_run, in base-context met secrets

Volledig automatisch, geen handmatige stappen, veilig.

Wil je dat ik de twee-workflow aanpak of het /sonar commando als PR uitwerk?

User: Werk twee-workflow uit in een pr

Assistant: Het lijkt erop dat de agent nog geen taaklink heeft teruggegeven. Laat me even checken of de taak is aangemaakt.

User: @copilot Accepted Confirmation: Confirm agent session

Assistant: Copilot is aan het werk! 🚀

data:
    - title: '[WIP] Remove existing sonarcloud wor...

</details>



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

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

Copilot AI changed the title [WIP] Add SonarCloud summary step to GitHub Actions Add GitHub Actions job summary to SonarCloud workflow Apr 6, 2026
Copilot AI requested a review from 304NotModified April 6, 2026 10:43
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.

2 participants