From b9a59ba6f771a0aa5b77d8aa22b207443021834c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederico=20Gon=C3=A7alves?= Date: Thu, 15 Feb 2024 09:21:10 -0300 Subject: [PATCH] ci: Enabling SonarCloud for forks (#641) This pull request modifies the SonarCloud workflow to function with forked repositories as well. The `pull_request_target` event works similarly to `pull_request`, but runs on the base branch and allows using secrets. Therefore, the PR ref version needs to be specified in the workflow script. --- .github/workflows/sonarcloud.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 82f12cf10f..68549809c9 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -3,9 +3,11 @@ on: push: branches: - main - # PRs from forks are unsupported, therefore this is pointless. - # pull_request: - # types: [opened, synchronize, reopened] + pull_request_target: + types: + - opened + - reopened + - synchronize jobs: build: name: Build and analyze @@ -14,6 +16,7 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + ref: ${{ github.event.pull_request.head.sha }} - name: Set up JDK 17 uses: actions/setup-java@v4 with: @@ -37,4 +40,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: mvn -B -Psonarcloud-analysis validate org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.organization=timefold -Dsonar.projectKey=ai.timefold:timefold-solver -Dsonar.host.url=https://sonarcloud.io \ No newline at end of file + run: mvn -B -Psonarcloud-analysis validate org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.organization=timefold -Dsonar.projectKey=ai.timefold:timefold-solver -Dsonar.host.url=https://sonarcloud.io -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} \ No newline at end of file