SonarCloud Analysis (fork PRs) #21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: SonarCloud Analysis (fork PRs) | |
| on: | |
| workflow_run: | |
| workflows: ["CI/CD Pipeline"] | |
| types: [completed] | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| checks: write | |
| statuses: write | |
| jobs: | |
| sonar: | |
| name: SonarCloud Analysis | |
| runs-on: ubuntu-latest | |
| if: > | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.event == 'pull_request' && | |
| github.event.workflow_run.head_repository.full_name != github.repository | |
| steps: | |
| - name: Checkout PR head | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_sha }} | |
| fetch-depth: 0 | |
| - name: Set up JDK 25 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '25' | |
| distribution: 'temurin' | |
| cache: 'maven' | |
| - name: Cache SonarCloud packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.sonar/cache | |
| key: ${{ runner.os }}-sonar | |
| restore-keys: ${{ runner.os }}-sonar | |
| - name: Resolve PR metadata | |
| id: pr | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const prs = await github.rest.pulls.list({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| head: `${{ github.event.workflow_run.head_repository.owner.login }}:${{ github.event.workflow_run.head_branch }}`, | |
| }); | |
| if (prs.data.length === 0) { | |
| core.setFailed('No open PR found for this workflow_run'); | |
| return; | |
| } | |
| const pr = prs.data[0]; | |
| core.setOutput('number', pr.number); | |
| core.setOutput('base', pr.base.ref); | |
| core.setOutput('branch', pr.head.ref); | |
| - name: Build modules for SonarCloud | |
| run: mvn clean verify -pl openespi-common,openespi-datacustodian,openespi-thirdparty -am | |
| - name: Analyze with SonarCloud | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| run: | | |
| mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \ | |
| -Dsonar.projectKey=GreenButtonAlliance_OpenESPI-GreenButton-Java \ | |
| -Dsonar.organization=greenbuttonalliance \ | |
| -Dsonar.host.url=https://sonarcloud.io \ | |
| -Dsonar.coverage.jacoco.xmlReportPaths=**/target/site/jacoco/jacoco.xml \ | |
| -Dsonar.pullrequest.key=${{ steps.pr.outputs.number }} \ | |
| -Dsonar.pullrequest.branch=${{ steps.pr.outputs.branch }} \ | |
| -Dsonar.pullrequest.base=${{ steps.pr.outputs.base }} |