@@ -30,12 +30,12 @@ jobs:
30
30
with :
31
31
fetch-depth : 0
32
32
submodules : ' true'
33
-
34
33
- name : Set up JDK 17
35
34
uses : actions/setup-java@v3
36
35
with :
37
36
distribution : ' zulu'
38
37
java-version : ' 17'
38
+
39
39
- name : Cache SonarCloud packages
40
40
uses : actions/cache@v3
41
41
with :
@@ -49,20 +49,37 @@ jobs:
49
49
key : ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
50
50
restore-keys : ${{ runner.os }}-m2
51
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-validator \
57
+ -Dsonar.organization=com-pas )"
52
58
- name : Create custom Maven Settings.xml
53
59
uses : whelk-io/maven-settings-xml-action@v20
54
60
with :
55
61
output_file : custom_maven_settings.xml
56
62
servers : ' [{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'
57
- - 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' }}
58
78
env :
59
- GITHUB_USERNAME : " OWNER"
60
79
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
61
80
SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
62
81
run : |
63
- ./mvnw -s custom_maven_settings.xml -B -Psonar \
64
- -Dsonar.projectKey=com-pas_compas-scl-validator \
65
- -Dsonar.organization=com-pas \
66
- -Dsonar.host.url=https://sonarcloud.io \
67
- -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} \
68
- 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