Skip to content

SonarCloud Fork PR Analysis #1

SonarCloud Fork PR Analysis

SonarCloud Fork PR Analysis #1

Workflow file for this run

name: SonarCloud Fork PR Analysis
on:
workflow_run:
workflows: ["CI/CD Pipeline"]
types: [completed]
permissions:
contents: read
pull-requests: read
jobs:
sonarcloud-fork:
name: SonarCloud Analysis (Fork PR)
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_repository.full_name != github.repository
steps:
- name: Checkout fork PR code
uses: actions/checkout@v4
with:
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_sha }}
fetch-depth: 0
- name: Fetch base branch for diff
run: |
git remote add upstream https://github.com/${{ github.repository }}.git
git fetch upstream
- name: Get PR number
uses: actions/github-script@v7
id: pr-number
with:
script: |
const pulls = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: `${context.payload.workflow_run.head_repository.owner.login}:${context.payload.workflow_run.head_branch}`,
state: 'open'
});
return pulls.data[0]?.number || '';
result-encoding: string
- name: Set up JDK 25
uses: actions/setup-java@v4
with:
java-version: '25'
distribution: 'temurin'
cache: 'maven'
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Build modules
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.pullrequest.key=${{ steps.pr-number.outputs.result }} \
-Dsonar.pullrequest.branch=${{ github.event.workflow_run.head_branch }} \
-Dsonar.pullrequest.base=${{ github.event.workflow_run.pull_requests[0].base.ref || 'main' }} \
-Dsonar.coverage.jacoco.xmlReportPaths=**/target/site/jacoco/jacoco.xml