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