Skip to content

Sonarcloud

Sonarcloud #3128

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 != '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@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.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 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@80620a5d27ce0ae443b965134db88467fc607b43 # tag=v7
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@7a6d8a8234af8eb26422e24e3006232cccaa061b
with:
distribution: 'temurin'
java-version: 17
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 }}