|
4 | 4 | workflows: [ "Tests" ] |
5 | 5 | types: |
6 | 6 | - completed |
| 7 | +concurrency: |
| 8 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 9 | + cancel-in-progress: true |
7 | 10 | jobs: |
8 | | - sonarqube: |
9 | | - name: SonarQube |
10 | | - runs-on: ubuntu-latest |
11 | | - if: github.event.workflow_run.conclusion == 'success' |
12 | | - steps: |
13 | | - - name: "🧮 Checkout code" |
14 | | - uses: actions/checkout@v3 |
15 | | - with: |
16 | | - repository: ${{ github.event.workflow_run.head_repository.full_name }} |
17 | | - ref: ${{ github.event.workflow_run.head_branch }} # checkout commit that triggered this workflow |
18 | | - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis |
19 | | - |
20 | | - # fetch develop so that Sonar can identify new issues in PR builds |
21 | | - - name: "📕 Fetch develop" |
22 | | - if: "github.event.workflow_run.head_branch != 'develop'" |
23 | | - run: git rev-parse HEAD && git fetch origin develop:develop && git status && git rev-parse HEAD |
24 | | - |
25 | | - # There's a 'download artifact' action, but it hasn't been updated for the workflow_run action |
26 | | - # (https://github.com/actions/download-artifact/issues/60) so instead we get this mess: |
27 | | - - name: "📥 Download Coverage Report" |
28 | | - |
29 | | - with: |
30 | | - script: | |
31 | | - const artifacts = await github.actions.listWorkflowRunArtifacts({ |
32 | | - owner: context.repo.owner, |
33 | | - repo: context.repo.repo, |
34 | | - run_id: ${{ github.event.workflow_run.id }}, |
35 | | - }); |
36 | | - const matchArtifact = artifacts.data.artifacts.filter((artifact) => { |
37 | | - return artifact.name == "coverage" |
38 | | - })[0]; |
39 | | - const download = await github.actions.downloadArtifact({ |
40 | | - owner: context.repo.owner, |
41 | | - repo: context.repo.repo, |
42 | | - artifact_id: matchArtifact.id, |
43 | | - archive_format: 'zip', |
44 | | - }); |
45 | | - const fs = require('fs'); |
46 | | - fs.writeFileSync('${{github.workspace}}/coverage.zip', Buffer.from(download.data)); |
47 | | -
|
48 | | - - name: "🗃️ Extract Coverage Report" |
49 | | - run: unzip -d coverage coverage.zip && rm coverage.zip |
50 | | - |
51 | | - - name: "🔍 Read latest tag" |
52 | | - id: version |
53 | | - uses: WyriHaximus/github-action-get-previous-tag@v1 |
| 11 | + prdetails: |
| 12 | + name: ℹ️ PR Details |
| 13 | + if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' |
| 14 | + uses: matrix-org/matrix-js-sdk/.github/workflows/pr_details.yml@develop |
| 15 | + with: |
| 16 | + owner: ${{ github.event.workflow_run.head_repository.owner.login }} |
| 17 | + branch: ${{ github.event.workflow_run.head_branch }} |
54 | 18 |
|
55 | | - - name: "🔍 Read PR details" |
56 | | - id: prdetails |
57 | | - if: github.event.workflow_run.event == 'pull_request' |
58 | | - # We need to find the PR number that corresponds to the branch, which we do by searching the GH API |
59 | | - # The workflow_run event includes a list of pull requests, but it doesn't get populated for |
60 | | - # forked PRs: https://docs.github.com/en/rest/reference/checks#create-a-check-run |
61 | | - run: | |
62 | | - head_branch='${{github.event.workflow_run.head_repository.owner.login}}:${{github.event.workflow_run.head_branch}}' |
63 | | - echo "Head branch: $head_branch" |
64 | | - pulls_uri="https://api.github.com/repos/${{ github.repository }}/pulls?head=$(jq -Rr '@uri' <<<$head_branch)" |
65 | | - pr_data=$(curl -s -H 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' "$pulls_uri") |
66 | | -
|
67 | | - pr_number=$(jq -r '.[] | .number' <<< "$pr_data") |
68 | | - echo "PR number: $pr_number" |
69 | | - echo "::set-output name=prnumber::$pr_number" |
70 | | -
|
71 | | - head_ref=$(jq -r '.[] | .head.ref' <<< "$pr_data") |
72 | | - echo "Head ref: $head_ref" |
73 | | - echo "::set-output name=headref::$head_ref" |
74 | | -
|
75 | | - base_ref=$(jq -r '.[] | .base.ref' <<< "$pr_data") |
76 | | - echo "Base ref: $base_ref" |
77 | | - echo "::set-output name=baseref::$base_ref" |
78 | | -
|
79 | | - - name: "🩻 SonarCloud Scan" |
80 | | - uses: SonarSource/sonarcloud-github-action@master |
81 | | - with: |
82 | | - args: > |
83 | | - -Dsonar.projectVersion=${{ steps.version.outputs.tag }} |
84 | | - -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} |
85 | | - -Dsonar.pullrequest.key=${{ steps.prdetails.outputs.prnumber }} |
86 | | - -Dsonar.pullrequest.branch=${{ steps.prdetails.outputs.headref }} |
87 | | - -Dsonar.pullrequest.base=${{ steps.prdetails.outputs.baseref }} |
88 | | - env: |
89 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any |
90 | | - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 19 | + sonarqube: |
| 20 | + name: 🩻 SonarQube |
| 21 | + needs: prdetails |
| 22 | + # Only wait for prdetails if it isn't skipped |
| 23 | + if: | |
| 24 | + always() && |
| 25 | + (needs.prdetails.result == 'success' || needs.prdetails.result == 'skipped') && |
| 26 | + github.event.workflow_run.conclusion == 'success' |
| 27 | + uses: matrix-org/matrix-js-sdk/.github/workflows/sonarcloud.yml@develop |
| 28 | + with: |
| 29 | + repo: ${{ github.event.workflow_run.head_repository.full_name }} |
| 30 | + pr_id: ${{ needs.prdetails.outputs.pr_id }} |
| 31 | + head_branch: ${{ needs.prdetails.outputs.head_branch || github.event.workflow_run.head_branch }} |
| 32 | + base_branch: ${{ needs.prdetails.outputs.base_branch }} |
| 33 | + revision: ${{ github.event.workflow_run.head_sha }} |
| 34 | + coverage_workflow_name: tests.yml |
| 35 | + coverage_run_id: ${{ github.event.workflow_run.id }} |
| 36 | + secrets: |
| 37 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
0 commit comments