SonarCloud Analysis #9281
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
name: SonarCloud Analysis | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
types: [opened, synchronize, reopened] | |
workflow_dispatch: | |
schedule: | |
- cron: '00 6 * * *' # 06:00 UTC every day | |
env: | |
# Workaround for kotlin sample multithreading issue: https://youtrack.jetbrains.com/issue/KT-43894 | |
MAVEN_OPTS: "-Didea.home.path=${{ vars.RUNNER_TEMP }} -Didea.ignore.disabled.plugins=true" | |
jobs: | |
sonar: | |
name: Build with Sonar | |
runs-on: ubuntu-20.04 | |
# Sonar Token can't be passed to PRs from forks. Disable Sonar workflow unless PR is from a branch. | |
if: github.event.pull_request.head.repo.full_name == github.repository | |
steps: | |
- name: Get current date | |
id: date | |
run: echo "date=$(date +'%Y-%m-%d' --utc)" >> $GITHUB_OUTPUT | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 17 | |
- name: Cache SonarCloud packages | |
uses: actions/cache@v2 | |
with: | |
path: ~/.sonar/cache | |
key: ${{ runner.os }}-sonar-${{ steps.date.outputs.date }} | |
- uses: actions/cache@v2 | |
id: mvn-cache | |
with: | |
path: ~/.m2/repository | |
key: ${{ runner.os }}-maven-unified-${{ steps.date.outputs.date }} | |
- name: Mvn install w/ coverage # Need this when the directory/pom structure changes | |
id: install | |
run: | | |
./mvnw \ | |
--batch-mode \ | |
--no-transfer-progress \ | |
--show-version \ | |
--threads 1.5C \ | |
--activate-profiles codecov \ | |
clean \ | |
install | |
- name: Build and analyze | |
id: sonar | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: | | |
./mvnw \ | |
--batch-mode \ | |
--no-transfer-progress \ | |
--activate-profiles codecov \ | |
--define sonar.projectKey=GoogleCloudPlatform_spring-cloud-gcp \ | |
--define sonar.host.url=https://sonarcloud.io \ | |
--define sonar.organization=googlecloudplatform \ | |
org.sonarsource.scanner.maven:sonar-maven-plugin:sonar |