Skip to content

Commit b30fd46

Browse files
committed
sonar on pr
1 parent 267da7e commit b30fd46

File tree

7 files changed

+122
-213
lines changed

7 files changed

+122
-213
lines changed

.github/actions/download-artifact/action.yml

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ runs:
2222

2323
- name: Extract artifacts
2424
run: |
25-
ls -R .
2625
for t in ${{ inputs.name }}*.tar
2726
do
2827
tar -xvf "${t}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Prepare code analysis
2+
description: Prepare the working directory for SonarQube code analysis
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Get reports
8+
uses: ./.github/actions/download-artifact
9+
with:
10+
name: reports
11+
12+
- name: Get coverage
13+
uses: ./.github/actions/download-artifact
14+
with:
15+
name: merged-coverage
16+
17+
- name: Get classes
18+
uses: ./.github/actions/download-artifact
19+
with:
20+
name: classes
21+
22+
- name: Create paths for JUnit reporting
23+
id: junit_paths
24+
shell: bash
25+
run: |
26+
report_paths=""
27+
check_name=""
28+
for file in target/surefire-reports-*
29+
do
30+
report_paths="${file}/TEST-*.xml"$'\n'"${report_paths}"
31+
check_name="JUnit Report ${file##target/surefire-reports-}"$'\n'"${check_name}"
32+
done
33+
echo "report_paths<<EOF"$'\n'"${report_paths}EOF" >> $GITHUB_OUTPUT
34+
echo "check_name<<EOF"$'\n'"${check_name}EOF" >> $GITHUB_OUTPUT
35+
36+
- name: Publish Test Report
37+
uses: mikepenz/action-junit-report@v3
38+
with:
39+
commit: ${{ github.event.workflow_run.head_sha }}
40+
report_paths: ${{ steps.junit_paths.outputs.report_paths }}
41+
check_name: ${{ steps.junit_paths.outputs.check_name }}
42+
require_tests: true
43+
check_retries: true
44+
detailed_summary: true

.github/workflows/analyze.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Analyze PR
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
- 'Build'
7+
types:
8+
- completed
9+
10+
permissions:
11+
pull-requests: read
12+
contents: read
13+
checks: write
14+
15+
jobs:
16+
analyze:
17+
name: Analyze Code
18+
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_repository.fork
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: echo
22+
run: echo "${{ toJson(github.event) }}"
23+
24+
- name: Checkout base
25+
uses: actions/checkout@v3
26+
with:
27+
repository: ${{ github.event.head_repository.full_name }}
28+
ref: ${{ github.event.workflow_run.head_sha }}
29+
path: base
30+
31+
- name: Checkout PR
32+
uses: actions/checkout@v3
33+
with:
34+
repository: ${{ github.event.workflow_run.repository.full_name }}
35+
# for Sonar
36+
fetch-depth: 0
37+
38+
- name: Get analysis data
39+
uses: ./base/.github/actions/prepare-analysis
40+
41+
- name: Set up JDK
42+
uses: actions/setup-java@v3
43+
with:
44+
java-version: ${{ env.BUILD_JAVA_VERSION }}
45+
distribution: temurin
46+
47+
- name: Run SonarQube
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
51+
shell: bash
52+
run: |
53+
cp -f base/pom.xml .
54+
mvn -B \
55+
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} \
56+
-Dsonar.pullrequest.key=${{ github.event.workflow_run.pull_requests[0].number }} \
57+
-Dsonar.pullrequest.branch=${{ github.event.workflow_run.pull_requests[0].head.ref }} \
58+
-Dsonar.pullrequest.base=${{ github.event.workflow_run.pull_requests[0].base.ref }} \
59+
org.sonarsource.scanner.maven:sonar-maven-plugin:sonar

.github/workflows/build-pr.yml

-51
This file was deleted.

.github/workflows/build.yml

+19-45
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
5656
- name: Upload classes
5757
uses: ./.github/actions/upload-artifact
58-
if: matrix.java == env.BUILD_JAVA_VERSION && matrix.arch == 'x64' && matrix.os == 'ubuntu-latest'
58+
if: always() && matrix.java == env.BUILD_JAVA_VERSION && matrix.arch == 'x64' && matrix.os == 'ubuntu-latest'
5959
with:
6060
name: classes
6161
path: target/*classes
@@ -102,67 +102,41 @@ jobs:
102102
name: classes
103103

104104
- name: Merge and output
105-
run: |
106-
mvn -B jacoco:merge jacoco:report
107-
ls -R target
105+
run: mvn -B jacoco:merge jacoco:report
108106

109107
- name: Upload
110108
uses: ./.github/actions/upload-artifact
111109
with:
112110
name: merged-coverage
113-
path: target/site/jacoco/jacoco.xml
111+
path: |
112+
target/site/jacoco
113+
target/jacoco.exec
114+
115+
- name: Save PR number to file
116+
if: github.event_name == 'pull_request'
117+
run: echo ${{ github.event.number }} > pr_number.txt
118+
119+
- name: Archive PR number
120+
if: github.event_name == 'pull_request'
121+
uses: actions/upload-artifact@v3
122+
with:
123+
name: pr_number
124+
path: pr_number.txt
114125

115126
analyze:
116127
name: Analyze Code
117128
runs-on: ubuntu-latest
118129
needs: coverage
130+
if: github.event_name == 'push'
119131
steps:
120132
- name: Checkout
121133
uses: actions/checkout@v3
122134
with:
123135
# for Sonar
124136
fetch-depth: 0
125137

126-
- name: Get reports
127-
uses: ./.github/actions/download-artifact
128-
with:
129-
name: reports
130-
131-
- name: Get coverage
132-
uses: ./.github/actions/download-artifact
133-
with:
134-
name: merged-coverage
135-
136-
- name: Get classes
137-
uses: ./.github/actions/download-artifact
138-
with:
139-
name: classes
140-
141-
- name: Display structure of downloaded files
142-
run: ls -R
143-
144-
- name: Create paths for JUnit reporting
145-
id: junit_paths
146-
run: |
147-
report_paths=""
148-
check_name=""
149-
for file in target/surefire-reports-*
150-
do
151-
report_paths="${file}/TEST-*.xml"$'\n'"${report_paths}"
152-
check_name="JUnit Report ${file##target/surefire-reports-}"$'\n'"${check_name}"
153-
done
154-
echo "report_paths<<EOF"$'\n'"${report_paths}EOF" >> $GITHUB_OUTPUT
155-
echo "check_name<<EOF"$'\n'"${check_name}EOF" >> $GITHUB_OUTPUT
156-
157-
- name: Publish Test Report
158-
uses: mikepenz/action-junit-report@v3
159-
with:
160-
commit: ${{ github.event.workflow_run.head_sha }}
161-
report_paths: ${{ steps.junit_paths.outputs.report_paths }}
162-
check_name: ${{ steps.junit_paths.outputs.check_name }}
163-
require_tests: true
164-
check_retries: true
165-
detailed_summary: true
138+
- name: Get analysis data
139+
uses: ./.github/actions/prepare-analysis
166140

167141
- name: Set up JDK
168142
uses: actions/setup-java@v3

.github/workflows/junit-report.yml

-41
This file was deleted.

.github/workflows/sonar-pr.yml

-75
This file was deleted.

0 commit comments

Comments
 (0)