Skip to content

Commit 10bbfec

Browse files
committed
HHH-18678 Use specific check tasks for CI build
1 parent ee2d8a3 commit 10bbfec

File tree

3 files changed

+95
-7
lines changed

3 files changed

+95
-7
lines changed

.github/workflows/contributor-build.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,67 @@ concurrency:
2929
cancel-in-progress: ${{ github.event_name == 'pull_request_target' || github.repository != 'hibernate/hibernate-orm' }}
3030

3131
jobs:
32+
# Pre-requisite step that only runs format checks
33+
format_checks:
34+
permissions:
35+
contents: read
36+
name: Java 17
37+
runs-on: ubuntu-latest
38+
strategy:
39+
fail-fast: false
40+
steps:
41+
- name: Check out commit already pushed to branch
42+
if: "! github.event.pull_request.number"
43+
uses: actions/checkout@v4
44+
with:
45+
persist-credentials: false
46+
- name: Check out PR head
47+
uses: actions/checkout@v4
48+
if: github.event.pull_request.number
49+
with:
50+
ref: "refs/pull/${{ github.event.pull_request.number }}/head"
51+
persist-credentials: false
52+
- name: Reclaim Disk Space
53+
run: .github/ci-prerequisites.sh
54+
- name: Set up Java 17
55+
uses: actions/setup-java@v4
56+
with:
57+
distribution: 'temurin'
58+
java-version: '17'
59+
- name: Get year/month for cache key
60+
id: get-date
61+
run: echo "yearmonth=$(/bin/date -u "+%Y-%m")" >> $GITHUB_OUTPUT
62+
shell: bash
63+
- name: Cache Maven local repository
64+
uses: actions/cache@v4
65+
id: cache-maven
66+
with:
67+
path: |
68+
~/.m2/repository
69+
~/.gradle/caches/
70+
~/.gradle/wrapper/
71+
# refresh cache every month to avoid unlimited growth
72+
key: maven-localrepo-${{ steps.get-date.outputs.yearmonth }}
73+
- name: Run format checks
74+
env:
75+
# Don't populate Develocity cache in pull requests as that's potentially dangerous
76+
POPULATE_REMOTE_GRADLE_CACHE: "${{ github.event_name == 'push' }}"
77+
# WARNING: exposes secrets, so must only be passed to a step that doesn't run unapproved code.
78+
DEVELOCITY_ACCESS_KEY: "${{ github.event_name == 'push' && secrets.GRADLE_ENTERPRISE_ACCESS_KEY || '' }}"
79+
run: |
80+
./gradlew formatChecks
81+
- name: Upload test reports (if Gradle failed)
82+
uses: actions/upload-artifact@v4
83+
if: failure()
84+
with:
85+
name: test-reports-java11-${{ matrix.rdbms }}
86+
path: |
87+
./**/target/reports/tests/
88+
- name: Omit produced artifacts from build cache
89+
run: ./ci/before-cache.sh
90+
# Actual build that executes tests
3291
build:
92+
needs: format_checks
3393
permissions:
3494
contents: read
3595
name: Java 17

ci/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ function logAndExec() {
8181
exec "${@}"
8282
}
8383

84-
logAndExec ./gradlew check ${goal} "${@}" -Plog-test-progress=true --stacktrace
84+
logAndExec ./gradlew ciCheck ${goal} "${@}" -Plog-test-progress=true --stacktrace

gradle/java-module.gradle

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ tasks.copyResourcesToIntelliJOutFolder.mustRunAfter processTestResources
447447
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
448448
// Report configs
449449

450-
task enforceRules {
450+
tasks.register('enforceRules') {
451451
doLast {
452452
def illegalImport = ~/^import (sun|java.awt|org.slf4j)/
453453
def missingNewline = ~/^\s*}\s*(else|catch|finally)/
@@ -477,23 +477,23 @@ task enforceRules {
477477
}
478478
if (!line.startsWith("//")) { //ignore commented-out code
479479
if (line =~ equals) {
480-
equalsMinusHashcode ++
480+
equalsMinusHashcode++
481481
}
482482
if (line =~ hashCode) {
483-
equalsMinusHashcode --
483+
equalsMinusHashcode--
484484
}
485485
}
486486
}
487-
if (equalsMinusHashcode>0) {
487+
if (equalsMinusHashcode > 0) {
488488
errors++
489489
logger.error("Equals with missing hash code in ${shortName}")
490490
}
491-
if (equalsMinusHashcode<0) {
491+
if (equalsMinusHashcode < 0) {
492492
errors++
493493
logger.error("Hash code with missing equals in ${shortName}")
494494
}
495495
}
496-
if ( errors>0 ) {
496+
if (errors > 0) {
497497
throw new GradleException("Code rules were violated ($errors problems)")
498498
}
499499
}
@@ -514,6 +514,34 @@ spotless {
514514

515515
tasks.spotlessApply.dependsOn enforceRules
516516

517+
tasks.register( "ciCheck" ) {
518+
group "verification"
519+
description "Checks for CI environments"
520+
dependsOn tasks.check
521+
522+
spotlessApply {
523+
enabled = false
524+
}
525+
spotlessJavaApply {
526+
enabled = false
527+
}
528+
}
529+
530+
tasks.register( "formatChecks" ) {
531+
group "verification"
532+
description "Code style and formatting checks"
533+
534+
dependsOn tasks.spotlessCheck
535+
dependsOn tasks.enforceRules
536+
dependsOn tasks.forbiddenApisMain
537+
538+
spotlessApply {
539+
enabled = false
540+
}
541+
spotlessJavaApply {
542+
enabled = false
543+
}
544+
}
517545

518546
class CompilerStubsArgumentProvider implements CommandLineArgumentProvider {
519547

0 commit comments

Comments
 (0)