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