Skip to content

Configure SonarQube analysis in CI #8

Configure SonarQube analysis in CI

Configure SonarQube analysis in CI #8

Workflow file for this run

name: Build
on:
workflow_dispatch:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
jobs:
build:
name: Build and test
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
- name: Cache SonarQube packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Build and test
run: ./gradlew build
- name: SonarQube analysis
# Analysis is advisory: a failed or unconfigured scan must not fail the build.
continue-on-error: true
# SONAR_PROJECT_KEY is a repository variable holding the key SonarQube
# assigned when this repo was imported via the GitHub App.
if: ${{ vars.SONAR_PROJECT_KEY != '' }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
run: ./gradlew sonar --info -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }}