|
| 1 | +name: SonarQube |
| 2 | +on: |
| 3 | + workflow_run: |
| 4 | + workflows: [ "Tests" ] |
| 5 | + types: |
| 6 | + - completed |
| 7 | +jobs: |
| 8 | + sonarqube: |
| 9 | + name: SonarQube |
| 10 | + runs-on: ubuntu-latest |
| 11 | + if: github.event.workflow_run.conclusion == 'success' |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v3 |
| 14 | + with: |
| 15 | + repository: ${{ github.event.workflow_run.head_repository.full_name }} |
| 16 | + ref: ${{ github.event.workflow_run.head_branch }} # checkout commit that triggered this workflow |
| 17 | + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis |
| 18 | + |
| 19 | + # fetch develop so that Sonar can identify new issues in PR builds |
| 20 | + - name: Fetch develop |
| 21 | + if: "github.event.workflow_run.head_branch != 'develop'" |
| 22 | + run: git rev-parse HEAD && git fetch origin develop:develop && git status && git rev-parse HEAD |
| 23 | + |
| 24 | + # There's a 'download artifact' action, but it hasn't been updated for the workflow_run action |
| 25 | + # (https://github.com/actions/download-artifact/issues/60) so instead we get this mess: |
| 26 | + - name: Download Coverage Report |
| 27 | + |
| 28 | + with: |
| 29 | + script: | |
| 30 | + const artifacts = await github.actions.listWorkflowRunArtifacts({ |
| 31 | + owner: context.repo.owner, |
| 32 | + repo: context.repo.repo, |
| 33 | + run_id: ${{ github.event.workflow_run.id }}, |
| 34 | + }); |
| 35 | + const matchArtifact = artifacts.data.artifacts.filter((artifact) => { |
| 36 | + return artifact.name == "coverage" |
| 37 | + })[0]; |
| 38 | + const download = await github.actions.downloadArtifact({ |
| 39 | + owner: context.repo.owner, |
| 40 | + repo: context.repo.repo, |
| 41 | + artifact_id: matchArtifact.id, |
| 42 | + archive_format: 'zip', |
| 43 | + }); |
| 44 | + const fs = require('fs'); |
| 45 | + fs.writeFileSync('${{github.workspace}}/coverage.zip', Buffer.from(download.data)); |
| 46 | +
|
| 47 | + - name: Extract Coverage Report |
| 48 | + run: unzip -d coverage coverage.zip && rm coverage.zip |
| 49 | + |
| 50 | + - name: Read version |
| 51 | + id: version |
| 52 | + uses: WyriHaximus/github-action-get-previous-tag@v1 |
| 53 | + |
| 54 | + - name: SonarCloud Scan |
| 55 | + uses: SonarSource/sonarcloud-github-action@master |
| 56 | + with: |
| 57 | + args: > |
| 58 | + -Dsonar.projectVersion=${{ steps.version.outputs.tag }} |
| 59 | + -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} |
| 60 | + -Dsonar.pullrequest.key=${{ github.event.workflow_run.pull_requests[0].number }} |
| 61 | + -Dsonar.pullrequest.branch=${{ github.event.workflow_run.pull_requests[0].head.ref }} |
| 62 | + -Dsonar.pullrequest.base=${{ github.event.workflow_run.pull_requests[0].base.ref }} |
| 63 | + env: |
| 64 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any |
| 65 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
0 commit comments