1- # This workflow will build a Java project with Gradle
2- # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
3-
4- name : SonarQube analysis - Linux
5-
1+ name : Sonar
62on :
7- push :
8- branches : [ main ]
9- pull_request :
10- branches : [ main ]
11-
3+ workflow_run :
4+ workflows : ["Java CI with Gradle - Linux"]
5+ types :
6+ - completed
127jobs :
13- build-linux :
8+ build :
9+ name : Sonar
1410 runs-on : ubuntu-latest
15-
1611 steps :
17- - uses : actions/checkout@v2
18- - name : Set up JDK 11
19- uses : actions/setup-java@v1
20- with :
21- java-version : 11
22- - name : Run Sonar analysis
23- env :
12+ - uses : actions/checkout@v2
13+ with :
14+ fetch-depth : 0 # Shallow clones should be disabled for a better relevancy of analysis
15+ ref : ${{github.event.workflow_run.head_sha}}
16+ - name : Set up JDK 11
17+ uses : actions/setup-java@v1
18+ with :
19+ java-version : 11
20+ - name : Download artifacts
21+ 22+ with :
23+ script : |
24+ var artifacts = await github.actions.listWorkflowRunArtifacts({
25+ owner: context.repo.owner,
26+ repo: context.repo.repo,
27+ run_id: ${{github.event.workflow_run.id}},
28+ });
29+ for (var artifact of artifacts.data.artifacts) {
30+ if (artifact.name == 'linux-integration-test-reports' || artifact.name == 'ubuntu-latest-test-reports' || artifact.name == 'prInfo') {
31+ var zipfile = await github.actions.downloadArtifact({
32+ owner: context.repo.owner,
33+ repo: context.repo.repo,
34+ artifact_id: artifact.id,
35+ archive_format: 'zip',
36+ });
37+ var fs = require('fs');
38+ var path = require('path');
39+ var pathFile = path.format({
40+ root: '${{github.workspace}}/',
41+ name: artifact.name,
42+ ext: '.zip'
43+ });
44+ fs.writeFileSync(pathFile, Buffer.from(zipfile.data));
45+ }
46+ }
47+ - name : Unzip artifacts
48+ run : |
49+ find . -name '*.zip' -exec sh -c 'unzip -d "${{github.workspace}}/build" "$1"' _ {} \;
50+ - name : Run Sonar analysis
51+ env :
2452 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
2553 SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
26- run : ./gradlew sonarqube
54+ run : |
55+ if [ '${{github.event.workflow_run.event}}' == 'pull_request' ]; then
56+ PR_NUMBER=$(<build/PR)
57+ BASE_REF=$(<build/base_ref)
58+ HEAD_REF=$(<build/head_ref)
59+ ./gradlew sonarqube -Dsonar.pullrequest.base=$BASE_REF -Dsonar.pullrequest.branch=$HEAD_REF -Dsonar.pullrequest.key=$PR_NUMBER -Dsonar.pullrequest.provider=GitHub -Dsonar.pullrequest.github.repository=${{github.repository}}
60+ else
61+ ./gradlew sonarqube
62+ fi
63+ shell : bash
64+
0 commit comments