1+ name : Manual SonarCloud Analysis
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ pr_id :
7+ description : ' Pull Request ID to analyze'
8+ required : true
9+ type : string
10+
11+ jobs :
12+ sonar-analysis :
13+ name : SonarCloud Analysis for PR
14+ runs-on : ubuntu-latest
15+
16+ steps :
17+ - name : Get PR details
18+ id : pr
19+ uses : actions/github-script@v7
20+ with :
21+ script : |
22+ const pr = await github.rest.pulls.get({
23+ owner: context.repo.owner,
24+ repo: context.repo.repo,
25+ pull_number: ${{ inputs.pr_id }}
26+ });
27+ core.setOutput('head_ref', pr.data.head.ref);
28+ core.setOutput('base_ref', pr.data.base.ref);
29+ core.setOutput('head_sha', pr.data.head.sha);
30+
31+ - uses : actions/checkout@v4
32+ with :
33+ ref : ${{ steps.pr.outputs.head_sha }}
34+ fetch-depth : 0
35+
36+ - name : Set up JDK 17
37+ uses : actions/setup-java@v4
38+ with :
39+ java-version : 17
40+ distribution : ' temurin'
41+ cache : maven
42+
43+ - name : Build/Test & SonarCloud Scan
44+ env :
45+ SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
46+ if : env.SONAR_TOKEN != ''
47+ run : |
48+ mvn -B clean verify -Pcoverage,sonar \
49+ -Dsonar.token=${{ secrets.SONAR_TOKEN }} \
50+ -Dsonar.pullrequest.key=${{ inputs.pr_id }} \
51+ -Dsonar.pullrequest.branch=${{ steps.pr.outputs.head_ref }} \
52+ -Dsonar.pullrequest.base=${{ steps.pr.outputs.base_ref }}
0 commit comments