Skip to content

Commit abeb4cd

Browse files
Set url for sonar.
1 parent 56186e8 commit abeb4cd

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

.github/actions/perform-static-analysis/action.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ inputs:
1515
description: "Whether to fail the build if the quality gate fails"
1616
default: 'false'
1717

18+
outputs:
19+
sonar_report_url:
20+
description: "URL to the SonarCloud report for this branch"
21+
value: ${{ steps.report.outputs.url }}
22+
1823
runs:
1924
using: "composite"
2025
steps:
@@ -30,6 +35,7 @@ runs:
3035
run: echo "secret_exist=${{ inputs.sonar_token != '' }}" >> $GITHUB_OUTPUT
3136
- name: "Perform static analysis"
3237
shell: bash
38+
id: sonar
3339
if: steps.check.outputs.secret_exist == 'true'
3440
continue-on-error: ${{ fromJSON(inputs.ignore_sonar_failure) }}
3541
env:
@@ -39,3 +45,20 @@ runs:
3945
run: |
4046
export BRANCH_NAME=${GITHUB_HEAD_REF:-$(echo $GITHUB_REF | sed 's#refs/heads/##')}
4147
./scripts/reports/perform-static-analysis.sh
48+
- name: "Add SonarCloud report link to step summary"
49+
shell: bash
50+
id: report
51+
if: steps.sonar.outcome == 'success' || (steps.sonar.outcome == 'failure' && fromJSON(inputs.ignore_sonar_failure))
52+
env:
53+
SONAR_ORGANISATION_KEY: ${{ inputs.sonar_organisation_key }}
54+
SONAR_PROJECT_KEY: ${{ inputs.sonar_project_key }}
55+
run: |
56+
export BRANCH_NAME=${GITHUB_HEAD_REF:-$(echo $GITHUB_REF | sed 's#refs/heads/##')}
57+
ENCODED_BRANCH=$(echo "$BRANCH_NAME" | sed 's/\//%2F/g')
58+
SONAR_URL="https://sonarcloud.io/summary/overall?id=${SONAR_PROJECT_KEY}&branch=${ENCODED_BRANCH}"
59+
echo "url=${SONAR_URL}" >> $GITHUB_OUTPUT
60+
echo "### :bar_chart: SonarCloud Analysis Report" >> $GITHUB_STEP_SUMMARY
61+
echo "" >> $GITHUB_STEP_SUMMARY
62+
echo "**Branch:** \`${BRANCH_NAME}\`" >> $GITHUB_STEP_SUMMARY
63+
echo "" >> $GITHUB_STEP_SUMMARY
64+
echo "[View detailed SonarCloud report →]($SONAR_URL)" >> $GITHUB_STEP_SUMMARY

.github/workflows/stage-2-test.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,14 @@ jobs:
214214
name: python-coverage-reports
215215
path: .
216216
- name: "Perform static analysis"
217+
id: static-analysis
217218
uses: ./.github/actions/perform-static-analysis
218219
with:
219220
sonar_organisation_key: "${{ vars.SONAR_ORGANISATION_KEY }}"
220221
sonar_project_key: "${{ vars.SONAR_PROJECT_KEY }}"
221222
sonar_token: "${{ secrets.SONAR_TOKEN }}"
222223
ignore_sonar_failure: "${{ inputs.ignore_sonar_failure}}"
224+
- name: "Output SonarCloud report URL"
225+
if: steps.static-analysis.outputs.sonar_report_url != ''
226+
run: |
227+
echo "SonarCloud Report: ${{ steps.static-analysis.outputs.sonar_report_url }}"

0 commit comments

Comments
 (0)