diff --git a/.github/workflows/contributor-build.yml b/.github/workflows/contributor-build.yml index b293b047d07f..84f37b491bae 100644 --- a/.github/workflows/contributor-build.yml +++ b/.github/workflows/contributor-build.yml @@ -29,7 +29,67 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request_target' || github.repository != 'hibernate/hibernate-orm' }} jobs: + # Pre-requisite step that only runs format checks + format_checks: + permissions: + contents: read + name: Java 17 + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: Check out commit already pushed to branch + if: "! github.event.pull_request.number" + uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Check out PR head + uses: actions/checkout@v4 + if: github.event.pull_request.number + with: + ref: "refs/pull/${{ github.event.pull_request.number }}/head" + persist-credentials: false + - name: Reclaim Disk Space + run: .github/ci-prerequisites.sh + - name: Set up Java 17 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + - name: Get year/month for cache key + id: get-date + run: echo "yearmonth=$(/bin/date -u "+%Y-%m")" >> $GITHUB_OUTPUT + shell: bash + - name: Cache Maven local repository + uses: actions/cache@v4 + id: cache-maven + with: + path: | + ~/.m2/repository + ~/.gradle/caches/ + ~/.gradle/wrapper/ + # refresh cache every month to avoid unlimited growth + key: maven-localrepo-${{ steps.get-date.outputs.yearmonth }} + - name: Run format checks + env: + # Don't populate Develocity cache in pull requests as that's potentially dangerous + POPULATE_REMOTE_GRADLE_CACHE: "${{ github.event_name == 'push' }}" + # WARNING: exposes secrets, so must only be passed to a step that doesn't run unapproved code. + DEVELOCITY_ACCESS_KEY: "${{ github.event_name == 'push' && secrets.GRADLE_ENTERPRISE_ACCESS_KEY || '' }}" + run: | + ./gradlew formatChecks + - name: Upload test reports (if Gradle failed) + uses: actions/upload-artifact@v4 + if: failure() + with: + name: test-reports-java11-${{ matrix.rdbms }} + path: | + ./**/target/reports/tests/ + - name: Omit produced artifacts from build cache + run: ./ci/before-cache.sh + # Actual build that executes tests build: + needs: format_checks permissions: contents: read name: Java 17 diff --git a/ci/build.sh b/ci/build.sh index e1ae09d2f865..2e54c3a7604f 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -81,4 +81,4 @@ function logAndExec() { exec "${@}" } -logAndExec ./gradlew check ${goal} "${@}" -Plog-test-progress=true --stacktrace +logAndExec ./gradlew ciCheck ${goal} "${@}" -Plog-test-progress=true --stacktrace diff --git a/gradle/java-module.gradle b/gradle/java-module.gradle index 3cb648efaf17..9acd0a479901 100644 --- a/gradle/java-module.gradle +++ b/gradle/java-module.gradle @@ -447,7 +447,7 @@ tasks.copyResourcesToIntelliJOutFolder.mustRunAfter processTestResources // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Report configs -task enforceRules { +tasks.register('enforceRules') { doLast { def illegalImport = ~/^import (sun|java.awt|org.slf4j)/ def missingNewline = ~/^\s*}\s*(else|catch|finally)/ @@ -477,23 +477,23 @@ task enforceRules { } if (!line.startsWith("//")) { //ignore commented-out code if (line =~ equals) { - equalsMinusHashcode ++ + equalsMinusHashcode++ } if (line =~ hashCode) { - equalsMinusHashcode -- + equalsMinusHashcode-- } } } - if (equalsMinusHashcode>0) { + if (equalsMinusHashcode > 0) { errors++ logger.error("Equals with missing hash code in ${shortName}") } - if (equalsMinusHashcode<0) { + if (equalsMinusHashcode < 0) { errors++ logger.error("Hash code with missing equals in ${shortName}") } } - if ( errors>0 ) { + if (errors > 0) { throw new GradleException("Code rules were violated ($errors problems)") } } @@ -514,6 +514,26 @@ spotless { tasks.spotlessApply.dependsOn enforceRules +tasks.register( "ciCheck" ) { + group "verification" + description "Checks for CI environments" + dependsOn tasks.check + + spotlessApply { + enabled = false + } + spotlessJavaApply { + enabled = false + } +} + +tasks.register( "formatChecks" ) { + group "verification" + description "Code style and formatting checks" + + dependsOn tasks.spotlessCheck + dependsOn tasks.enforceRules +} class CompilerStubsArgumentProvider implements CommandLineArgumentProvider {