Sonarcloud #10053
This file contains 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
# This workflow executes code analysis with Sonarcloud | |
name: Sonarcloud | |
on: | |
workflow_run: | |
workflows: | |
- Java CI | |
types: | |
- completed | |
jobs: | |
Sonarcloud: | |
name: "Sonarcloud ${{ github.event.workflow_run.head_branch != 'main' && format('PR {0}', github.event.workflow_run.pull_requests[0].number) || 'main' }}" | |
# Do not execute for PRs that origin from forks since we are missing the secrets for the scan | |
# According the official documentation 'workflow_run' has most of the properties of 'check_suite'. | |
# According to the latter you can recognize pull requests from forks by 'null' values of 'head_branch' | |
# https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_run | |
# https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#check_suite | |
if: "github.event.workflow_run.head_branch != null" | |
runs-on: ubuntu-latest | |
timeout-minutes: 60 | |
steps: | |
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4 | |
with: | |
ref: ${{ github.event.workflow_run.head_sha }} # checkout commit that triggered this workflow | |
fetch-depth: 0 # fetch commit log so that Sonar is able to assign committers to issues | |
# fetch main so that Sonar can identify new issues in PR builds | |
- name: Get main | |
if: "github.event.workflow_run.head_branch != 'main'" | |
run: git rev-parse HEAD && git fetch origin main:main && git status && git rev-parse HEAD | |
# Download from previous workflow: https://github.com/dawidd6/action-download-artifact | |
- name: Download artifact | |
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v2 | |
with: | |
workflow: ${{ github.event.workflow_run.workflow_id }} | |
run_id: ${{ github.event.workflow_run.id }} | |
name: ubuntu-latest-17-test-results | |
- name: Set up JDK 17 | |
uses: actions/setup-java@b36c23c0d998641eff861008f374ee103c25ac73 # v4.4.0 | |
with: | |
distribution: 'temurin' | |
java-version: 17 | |
cache: 'gradle' | |
- name: Sonarcloud | |
run: ./gradlew -i -x test sonar -Dsonar.verbose=true | |
env: | |
SONAR_LOGIN_TOKEN: ${{ secrets.SONAR_LOGIN_TOKEN }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GITHUB_PR: ${{ github.event.workflow_run.pull_requests[0].number }} | |
SONAR_SCM_REVISION: ${{ github.event.workflow_run.head_sha }} |