diff --git a/.github/workflows/gradle-build.yml b/.github/workflows/gradle-build.yml index 5f43761a..0bd41cc8 100644 --- a/.github/workflows/gradle-build.yml +++ b/.github/workflows/gradle-build.yml @@ -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: @@ -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 + diff --git a/.github/workflows/test-java-os-mix.yml b/.github/workflows/test-java-os-mix.yml index 5c2d4371..35c43e3b 100644 --- a/.github/workflows/test-java-os-mix.yml +++ b/.github/workflows/test-java-os-mix.yml @@ -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 diff --git a/build.gradle b/build.gradle index 75022b9d..419b02f0 100644 --- a/build.gradle +++ b/build.gradle @@ -11,6 +11,7 @@ plugins { id 'java' alias(libs.plugins.gradle.versions) + alias(libs.plugins.sonar) } allprojects { @@ -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 } @@ -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)") diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 16668ed4..29515765 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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. #