@@ -10,39 +10,67 @@ jobs:
1010 build :
1111 name : Build
1212 runs-on : ubuntu-latest
13+ timeout-minutes : 15
14+
15+ if : ${{ (github.event_name != 'pull_request_target' && github.actor != 'dependabot[bot]') || (github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target') }}
1316 steps :
14- - uses : actions/checkout@v3
17+ - name : Checkout
18+ uses : actions/checkout@v3
1519 with :
1620 fetch-depth : 0
17- - name : Set up JDK 17
18- uses : actions/setup-java@v3
19- with :
20- distribution : ' zulu'
21- java-version : ' 17'
21+
2222 - name : Cache SonarCloud packages
2323 uses : actions/cache@v3
2424 with :
2525 path : ~/.sonar/cache
2626 key : ${{ runner.os }}-sonar
2727 restore-keys : ${{ runner.os }}-sonar
28+
2829 - name : Cache Maven packages
2930 uses : actions/cache@v3
3031 with :
3132 path : ~/.m2
3233 key : ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
3334 restore-keys : ${{ runner.os }}-m2
35+
36+ - name : Set up JDK 17
37+ uses : actions/setup-java@v3
38+ with :
39+ distribution : ' zulu'
40+ java-version : ' 17'
41+
42+ - name : Set Common Sonar Variables
43+ id : sonar_env
44+ run : |
45+ echo "##[set-output name=sonar_opts;]$(echo -Dsonar.host.url=https://sonarcloud.io \
46+ -Dsonar.projectKey=com-pas_compas-core \
47+ -Dsonar.organization=com-pas )"
3448 - name : Create custom Maven Settings.xml
35- uses : whelk-io/maven-settings-xml-action@v18
49+ uses : whelk-io/maven-settings-xml-action@v21
3650 with :
3751 output_file : custom_maven_settings.xml
3852 servers : ' [{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'
39- - name : Build and analyze
53+
54+ - name : Build and analyze (Pull Request)
55+ if : ${{ github.event_name == 'pull_request' || (github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target') }}
56+ env :
57+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
58+ SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
59+ run : |
60+ mvn -B -s custom_maven_settings.xml \
61+ ${{ steps.sonar_env.outputs.sonar_opts }} \
62+ -Dsonar.pullrequest.branch=${{ github.ref_name }} \
63+ -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} \
64+ -Dsonar.pullrequest.base=${{ github.base_ref }} \
65+ -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} \
66+ clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
67+ - name : Build and analyze (Push)
68+ if : ${{ github.event_name == 'push' }}
4069 env :
4170 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
4271 SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
4372 run : |
4473 mvn -B -s custom_maven_settings.xml \
45- -Dsonar.projectKey=com-pas_compas-sct \
46- -Dsonar.organization=com-pas \
47- -Dsonar.host.url=https://sonarcloud.io \
48- verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
74+ ${{ steps.sonar_env.outputs.sonar_opts }} \
75+ -Dsonar.branch.name=${{ github.ref_name }} \
76+ clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
0 commit comments