Sonar #17653
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
| name: 'Sonar' | |
| on: | |
| workflow_run: | |
| workflows: [ 'CI/CD Pipeline' ] | |
| types: | |
| - completed | |
| jobs: | |
| sonar: | |
| name: 'Sonar analysis' | |
| runs-on: ubuntu-latest | |
| environment: sonar | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| permissions: | |
| actions: read # Required to download artifacts | |
| pull-requests: write # Required for PR decoration comments | |
| statuses: write # Required for SonarCloud to post quality gate commit status | |
| steps: | |
| - name: 'Checkout project' | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| repository: ${{ github.event.workflow_run.head_repository.full_name }} | |
| ref: ${{ github.event.workflow_run.head_branch }} | |
| fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of Sonar analysis | |
| - name: 'Download cached artifact' | |
| if: github.event_name == 'workflow_run' | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 | |
| with: | |
| name: sonar-artifact | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| merge-multiple: true | |
| - name: 'Extract output artifact' | |
| if: github.event_name == 'workflow_run' | |
| shell: bash | |
| run: tar -xf output.tar | |
| - name: 'Read pull request event' | |
| if: github.event_name == 'workflow_run' | |
| shell: bash | |
| run: | | |
| echo "pr_number=$(sed '1q;d' pr-event.txt)" >> "$GITHUB_ENV" | |
| echo "pr_head_ref=$(sed '2q;d' pr-event.txt)" >> "$GITHUB_ENV" | |
| echo "pr_base_ref=$(sed '3q;d' pr-event.txt)" >> "$GITHUB_ENV" | |
| - name: 'Run SonarCloud scan' | |
| if: github.event_name == 'workflow_run' | |
| uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 # v7.0.0 | |
| with: | |
| args: > | |
| ${{ github.event.workflow_run.event == 'pull_request' && format('{0}{1}', '-Dsonar.scm.revision=', github.event.workflow_run.head_sha) || '' }} | |
| ${{ github.event.workflow_run.event == 'pull_request' && format('{0}{1}', '-Dsonar.pullrequest.key=', env.pr_number) || '' }} | |
| ${{ github.event.workflow_run.event == 'pull_request' && format('{0}{1}', '-Dsonar.pullrequest.branch=', env.pr_head_ref) || '' }} | |
| ${{ github.event.workflow_run.event == 'pull_request' && format('{0}{1}', '-Dsonar.pullrequest.base=', env.pr_base_ref) || '' }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |