1
- # SPDX-FileCopyrightText: 2021 Alliander N.V.
1
+ # SPDX-FileCopyrightText: 2022 Alliander N.V.
2
2
#
3
3
# SPDX-License-Identifier: Apache-2.0
4
4
30
30
with :
31
31
fetch-depth : 0
32
32
33
- - name : Set up JDK 17
34
- uses : actions/setup-java@v3
35
- with :
36
- distribution : ' zulu'
37
- java-version : ' 17'
38
33
- name : Cache SonarCloud packages
39
34
uses : actions/cache@v3
40
35
with :
@@ -48,20 +43,43 @@ jobs:
48
43
key : ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
49
44
restore-keys : ${{ runner.os }}-m2
50
45
46
+ - name : Set up JDK 17
47
+ uses : actions/setup-java@v3
48
+ with :
49
+ distribution : ' zulu'
50
+ java-version : ' 17'
51
+
52
+ - name : Set Common Sonar Variables
53
+ id : sonar_env
54
+ run : |
55
+ echo "##[set-output name=sonar_opts;]$(echo -Dsonar.host.url=https://sonarcloud.io \
56
+ -Dsonar.projectKey=com-pas_compas-scl-data-service \
57
+ -Dsonar.organization=com-pas )"
51
58
- name : Create custom Maven Settings.xml
52
59
uses : whelk-io/maven-settings-xml-action@v20
53
60
with :
54
61
output_file : custom_maven_settings.xml
55
62
servers : ' [{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'
56
- - name : Build and analyze
63
+ - name : Build and analyze (Pull Request)
64
+ if : ${{ github.event_name == 'pull_request' || (github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target') }}
65
+ env :
66
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
67
+ SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
68
+ run : |
69
+ ./mvnw -B -s custom_maven_settings.xml -Psonar \
70
+ ${{ steps.sonar_env.outputs.sonar_opts }} \
71
+ -Dsonar.pullrequest.branch=${{ github.ref_name }} \
72
+ -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} \
73
+ -Dsonar.pullrequest.base=${{ github.base_ref }} \
74
+ -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} \
75
+ clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
76
+ - name : Build and analyze (Push)
77
+ if : ${{ github.event_name == 'push' }}
57
78
env :
58
- GITHUB_USERNAME : " OWNER"
59
79
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
60
80
SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
61
81
run : |
62
- ./mvnw -s custom_maven_settings.xml -B -Psonar \
63
- -Dsonar.projectKey=com-pas_compas-scl-data-service \
64
- -Dsonar.organization=com-pas \
65
- -Dsonar.host.url=https://sonarcloud.io \
66
- -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} \
67
- clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
82
+ ./mvnw -B -s custom_maven_settings.xml -Psonar \
83
+ ${{ steps.sonar_env.outputs.sonar_opts }} \
84
+ -Dsonar.branch.name=${{ github.ref_name }} \
85
+ clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
0 commit comments