Skip to content

Sonarcloud

Sonarcloud #1628

Workflow file for this run

# 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 != 'master' && format('PR {0}', github.event.workflow_run.pull_requests[0].number) || 'master' }}"
# 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@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
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 master so that Sonar can identify new issues in PR builds
- name: Get master
if: "github.event.workflow_run.head_branch != 'master'"
run: git rev-parse HEAD && git fetch origin master:master && 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@v10
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
run_id: ${{ github.event.workflow_run.id }}
name: java-ci-test-results
path: ./build
- name: Set up JDK
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
with:
distribution: 'temurin'
java-version: 21
cache: 'gradle'
- name: Sonarcloud
run: ./gradlew -i -x test sonar -Dsonar.verbose=true --stacktrace
env:
SONAR_LOGIN_TOKEN: ${{ secrets.SONAR_LOGIN_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PR: ${{ github.event.workflow_run.pull_requests[0].number }}
GITHUB_BRANCH: ${{ github.event.workflow_run.head_branch }}
SONAR_SCM_REVISION: ${{ github.event.workflow_run.head_sha }}