|
| 1 | +name: Sonar |
| 2 | +on: |
| 3 | + workflow_run: |
| 4 | + workflows: [Validate PR] |
| 5 | + types: [completed] |
| 6 | +jobs: |
| 7 | + sonar: |
| 8 | + name: Sonar |
| 9 | + runs-on: ubuntu-latest |
| 10 | + if: github.event.workflow_run.conclusion == 'success' |
| 11 | + steps: |
| 12 | + - name: Download PR number artifact |
| 13 | + if: github.event.workflow_run.event == 'pull_request' |
| 14 | + uses: dawidd6/action-download-artifact@v2 |
| 15 | + with: |
| 16 | + workflow: Validate PR |
| 17 | + run_id: ${{ github.event.workflow_run.id }} |
| 18 | + name: PR_NUMBER |
| 19 | + - name: Read PR_NUMBER.txt |
| 20 | + if: github.event.workflow_run.event == 'pull_request' |
| 21 | + id: pr_number |
| 22 | + uses: juliangruber/read-file-action@v1 |
| 23 | + with: |
| 24 | + path: ./PR_NUMBER.txt |
| 25 | + - name: Request GitHub API for PR data |
| 26 | + if: github.event.workflow_run.event == 'pull_request' |
| 27 | + |
| 28 | + id: get_pr_data |
| 29 | + with: |
| 30 | + route: GET /repos/{full_name}/pulls/{number} |
| 31 | + number: ${{ steps.pr_number.outputs.content }} |
| 32 | + full_name: ${{ github.event.repository.full_name }} |
| 33 | + env: |
| 34 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + - uses: actions/checkout@v3 |
| 36 | + with: |
| 37 | + repository: ${{ github.event.workflow_run.head_repository.full_name }} |
| 38 | + ref: ${{ github.event.workflow_run.head_branch }} |
| 39 | + fetch-depth: 0 |
| 40 | + - name: Checkout base branch |
| 41 | + if: github.event.workflow_run.event == 'pull_request' |
| 42 | + run: | |
| 43 | + git remote add upstream ${{ github.event.repository.clone_url }} |
| 44 | + git fetch upstream |
| 45 | + git checkout -B ${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} upstream/${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} |
| 46 | + git checkout ${{ github.event.workflow_run.head_branch }} |
| 47 | + git clean -ffdx && git reset --hard HEAD |
| 48 | + - name: SonarCloud Scan on PR |
| 49 | + if: github.event.workflow_run.event == 'pull_request' |
| 50 | + uses: sonarsource/sonarcloud-github-action@master |
| 51 | + env: |
| 52 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 54 | + with: |
| 55 | + args: > |
| 56 | + -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} |
| 57 | + -Dsonar.pullrequest.key=${{ fromJson(steps.get_pr_data.outputs.data).number }} |
| 58 | + -Dsonar.pullrequest.branch=${{ fromJson(steps.get_pr_data.outputs.data).head.ref }} |
| 59 | + -Dsonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} |
| 60 | + - name: SonarCloud Scan on push |
| 61 | + if: github.event.workflow_run.event == 'push' && github.event.workflow_run.head_repository.full_name == github.event.repository.full_name |
| 62 | + uses: sonarsource/sonarcloud-github-action@master |
| 63 | + env: |
| 64 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 65 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 66 | + with: |
| 67 | + args: > |
| 68 | + -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} |
| 69 | + -Dsonar.branch.name=${{ github.event.workflow_run.head_branch }} |
0 commit comments