Skip to content

Commit

Permalink
#320 Add Sonar analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
ascheman committed Mar 28, 2024
1 parent 0c4db88 commit 2615492
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
40 changes: 34 additions & 6 deletions .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
name: Gradle Build and Test
name: Build and Test
on:
pull_request:
push:
workflow_dispatch:
env:
SONAR_ORGANIZATION: ${{ secrets.SONAR_ORGANIZATION || 'aim42' }}
SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY || 'aim42_htmlSanityCheck' }}
jobs:
gradle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
- name: Check out
uses: actions/checkout@v4

- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: temurin
# Always build with JDK 8 initially
java-version: 8
# SonarQube requires JDK 17 or higher
java-version: 17

- name: Cache JDK
uses: actions/cache@v4
with:
path: ~/.jdk
key: ${{ runner.os }}-jdk
restore-keys: ${{ runner.os }}-jdk

- name: Setup Gradle
uses: gradle/gradle-build-action@v3
with:
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }}


- name: Cache Gradle packages
uses: actions/cache@v4
with:
Expand Down Expand Up @@ -55,3 +67,19 @@ jobs:
uses: benc-uk/workflow-dispatch@v1
with:
workflow: test-java-os-mix.yml

- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Analyze with SonarCloud
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
BRANCH_NAME=${GITHUB_REF#refs/heads/}
./gradlew sonar -Psonar.branch.name=${BRANCH_NAME} --info --scan
5 changes: 4 additions & 1 deletion .github/workflows/test-java-os-mix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ jobs:
strategy:
matrix:
os-version: [ ubuntu-latest, macos-14, windows-latest ]
java-version: [ 11, 17, 21 ]
java-version: [ 8, 11, 17, 21 ]
exclude:
- os-version: macos-14
java-version: 8
runs-on: ${{ matrix.os-version }}
steps:
- name: Check out
Expand Down
14 changes: 14 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
id 'java'

alias(libs.plugins.gradle.versions)
alias(libs.plugins.sonar)
}

allprojects {
Expand Down Expand Up @@ -87,6 +88,9 @@ configure(subprojects) {
finalizedBy jacocoTestReport // report is always generated after tests run
}
jacocoTestReport {
reports {
xml.required = true
}
dependsOn check // tests are required to run before generating the report
}

Expand All @@ -95,6 +99,16 @@ configure(subprojects) {
// apply plugin: 'codenarc'
}

sonar {
properties {
property "sonar.projectKey", System.getenv("SONAR_PROJECT_KEY") ?: "aim42_htmlSanityCheck"
property "sonar.organization", System.getenv('SONAR_ORGANIZATION') ?: "aim42"
property "sonar.host.url", System.getenv('SONAR_URL') ?: "https://sonarcloud.io"
property "sonar.scm.provider", "git"
property "sonar.coverage.jacoco.xmlReportPaths", "**/build/reports/jacoco/test/jacocoTestReport.xml"
}
}

tasks.register("integrationTestOnly") {
group("Verification")
description("Run overall integration tests (no publish)")
Expand Down
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ slf4j-nop = "org.slf4j:slf4j-nop:2.0.11"
spock = "org.spockframework:spock-bom:2.3-groovy-3.0"

[plugins]
gradle-versions = { id= "com.github.ben-manes.versions", version = "0.50.0" }
gradle-versions = { id = "com.github.ben-manes.versions", version = "0.50.0" }
sonar = { id = "org.sonarqube", version = "5.0.0.4638" }

# Copyright Gerd Aschemann and aim42 contributors.
#
Expand Down

0 comments on commit 2615492

Please sign in to comment.