Skip to content

Commit db61c03

Browse files
authored
Merge pull request #3806 from amvanbaren/revert-sonar-workflow
Revert to previous sonar workflow
2 parents 83331bf + 3efc862 commit db61c03

File tree

2 files changed

+83
-7
lines changed

2 files changed

+83
-7
lines changed

.github/workflows/main.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Build
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
jobs:
9+
pr:
10+
name: Save PR Info
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Save PR number to file
14+
if: github.event_name == 'pull_request'
15+
run: echo ${{ github.event.number }} > PR_NUMBER.txt
16+
- name: Archive PR number
17+
if: github.event_name == 'pull_request'
18+
uses: actions/upload-artifact@v4
19+
with:
20+
name: PR_NUMBER
21+
path: PR_NUMBER.txt

.github/workflows/sonar.yml

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,74 @@
11
name: Sonar
22
on:
3-
push:
4-
branches:
5-
- main
6-
pull_request:
7-
types: [opened, synchronize, reopened]
3+
workflow_run:
4+
workflows: [Build]
5+
types: [completed]
86
jobs:
97
sonar:
108
name: Sonar
119
runs-on: ubuntu-latest
10+
if: github.event.workflow_run.conclusion == 'success'
1211
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+
uses: octokit/[email protected]
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 }}
1338
- uses: actions/checkout@v4
1439
with:
15-
fetch-depth: 0
16-
- name: SonarCloud Scan
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/sonarqube-scan-action@master
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
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
1767
uses: SonarSource/sonarqube-scan-action@master
1868
env:
69+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1970
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

Comments
 (0)