Skip to content

Commit fd80fdc

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

File tree

3 files changed

+90
-7
lines changed

3 files changed

+90
-7
lines changed

.github/workflows/contributor-build.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,62 @@ 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: Get year/month for cache key
55+
id: get-date
56+
run: echo "yearmonth=$(/bin/date -u "+%Y-%m")" >> $GITHUB_OUTPUT
57+
shell: bash
58+
- name: Cache Maven local repository
59+
uses: actions/cache@v4
60+
id: cache-maven
61+
with:
62+
path: |
63+
~/.m2/repository
64+
~/.gradle/caches/
65+
~/.gradle/wrapper/
66+
# refresh cache every month to avoid unlimited growth
67+
key: maven-localrepo-${{ steps.get-date.outputs.yearmonth }}
68+
- name: Run format checks
69+
env:
70+
# Don't populate Develocity cache in pull requests as that's potentially dangerous
71+
POPULATE_REMOTE_GRADLE_CACHE: "${{ github.event_name == 'push' }}"
72+
# WARNING: exposes secrets, so must only be passed to a step that doesn't run unapproved code.
73+
DEVELOCITY_ACCESS_KEY: "${{ github.event_name == 'push' && secrets.GRADLE_ENTERPRISE_ACCESS_KEY || '' }}"
74+
run: |
75+
./gradlew formatChecks
76+
- name: Upload test reports (if Gradle failed)
77+
uses: actions/upload-artifact@v4
78+
if: failure()
79+
with:
80+
name: test-reports-java11-${{ matrix.rdbms }}
81+
path: |
82+
./**/target/reports/tests/
83+
- name: Omit produced artifacts from build cache
84+
run: ./ci/before-cache.sh
85+
# Actual build that executes tests
3286
build:
87+
needs: format_checks
3388
permissions:
3489
contents: read
3590
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)