|
1 | 1 | name: Sonar |
2 | 2 | on: |
3 | | - workflow_run: |
4 | | - workflows: [Build] |
5 | | - types: [completed] |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - master |
6 | 6 | jobs: |
7 | 7 | sonar: |
8 | 8 | name: Sonar |
9 | 9 | permissions: |
10 | | - pull-requests: read |
| 10 | + contents: read |
11 | 11 | runs-on: ubuntu-latest |
12 | | - if: github.repository == 'EclipseFdn/open-vsx.org' && github.event.workflow_run.conclusion == 'success' |
| 12 | + if: github.repository == 'EclipseFdn/open-vsx.org' |
13 | 13 | steps: |
14 | | - - name: Create artifacts directory |
15 | | - run: mkdir -p ${{ runner.temp }}/artifacts |
16 | | - - name: Download PR number artifact |
17 | | - if: github.event.workflow_run.event == 'pull_request' |
18 | | - uses: dawidd6/action-download-artifact@0bd50d53a6d7fb5cb921e607957e9cc12b4ce392 # v12 |
| 14 | + - name: Checkout |
| 15 | + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 |
19 | 16 | with: |
20 | | - workflow: Build |
21 | | - run_id: ${{ github.event.workflow_run.id }} |
22 | | - path: ${{ runner.temp }}/artifacts |
23 | | - name: PR_NUMBER |
24 | | - - name: Read PR_NUMBER.txt |
25 | | - if: github.event.workflow_run.event == 'pull_request' |
26 | | - id: pr_number |
27 | | - uses: juliangruber/read-file-action@b549046febe0fe86f8cb4f93c24e284433f9ab58 # v1.1.7 |
28 | | - with: |
29 | | - path: ${{ runner.temp }}/artifacts/PR_NUMBER.txt |
30 | | - - name: Request GitHub API for PR data |
31 | | - if: github.event.workflow_run.event == 'pull_request' |
32 | | - uses: octokit/request-action@dad4362715b7fb2ddedf9772c8670824af564f0d # v2.4.0 |
33 | | - id: get_pr_data |
34 | | - with: |
35 | | - route: GET /repos/{full_name}/pulls/{number} |
36 | | - number: ${{ steps.pr_number.outputs.content }} |
37 | | - full_name: ${{ github.event.repository.full_name }} |
38 | | - env: |
39 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
40 | | - - name: Checkout head branch |
41 | | - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
42 | | - with: |
43 | | - repository: ${{ github.event.workflow_run.head_repository.full_name }} |
44 | | - ref: ${{ github.event.workflow_run.head_branch }} |
45 | | - fetch-depth: 0 |
46 | 17 | persist-credentials: false |
47 | | - - name: Checkout head branch of pull_request |
48 | | - if: github.event.workflow_run.event == 'pull_request' |
49 | | - env: |
50 | | - HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} |
51 | | - CLONE_URL: ${{ github.event.repository.clone_url }} |
52 | | - run: | |
53 | | - BASE_REF="${{ fromJson(steps.get_pr_data.outputs.data).base.ref }}" |
54 | | -
|
55 | | - git remote add upstream ${CLONE_URL} |
56 | | - git fetch upstream |
57 | | - git checkout -B ${BASE_REF} upstream/${BASE_REF} |
58 | | - git checkout ${HEAD_BRANCH} |
59 | | - git clean -ffdx && git reset --hard HEAD |
60 | | - - name: SonarCloud Scan on PR |
61 | | - if: github.event.workflow_run.event == 'pull_request' |
62 | | - uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 # v7.0.0 |
63 | | - env: |
64 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
65 | | - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 18 | + fetch-depth: 0 |
| 19 | + - name: Cache SonarCloud packages |
| 20 | + uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1 |
66 | 21 | with: |
67 | | - args: > |
68 | | - -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} |
69 | | - -Dsonar.pullrequest.key=${{ fromJson(steps.get_pr_data.outputs.data).number }} |
70 | | - -Dsonar.pullrequest.branch=${{ fromJson(steps.get_pr_data.outputs.data).head.ref }} |
71 | | - -Dsonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} |
72 | | - - name: SonarCloud Scan on push |
73 | | - if: github.event.workflow_run.event == 'push' && github.event.workflow_run.head_repository.full_name == github.event.repository.full_name |
74 | | - uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 # v7.0.0 |
| 22 | + path: ~/.sonar/cache |
| 23 | + key: ${{ runner.os }}-sonar |
| 24 | + restore-keys: ${{ runner.os }}-sonar |
| 25 | + - name: SonarCloud Scan |
| 26 | + uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 # v7.0.0 |
75 | 27 | env: |
76 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
77 | 28 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
78 | | - with: |
79 | | - args: > |
80 | | - -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} |
81 | | - -Dsonar.branch.name=${{ github.event.workflow_run.head_branch }} |
0 commit comments