Skip to content

Commit 83331bf

Browse files
authored
Merge pull request #3803 from amvanbaren/update-sonar-workflow
Update Sonar workflow
2 parents e0ee7bd + 7687205 commit 83331bf

File tree

2 files changed

+8
-84
lines changed

2 files changed

+8
-84
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

.github/workflows/sonar.yml

Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,19 @@
11
name: Sonar
22
on:
3-
workflow_run:
4-
workflows: [Build]
5-
types: [completed]
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
types: [opened, synchronize, reopened]
68
jobs:
79
sonar:
810
name: Sonar
911
runs-on: ubuntu-latest
10-
if: github.event.workflow_run.conclusion == 'success'
1112
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 }}
3813
- uses: actions/checkout@v4
3914
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
5618
env:
57-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5819
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

Comments
 (0)