Skip to content

Commit fbfcad6

Browse files
committed
HHH-18678 Specific task for CI build and separate step for format checks
1 parent d6e85b0 commit fbfcad6

File tree

3 files changed

+120
-3
lines changed

3 files changed

+120
-3
lines changed

.github/workflows/ci.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,97 @@ jobs:
226226
with:
227227
name: build-scan-data-${{ matrix.rdbms }}
228228
path: ~/.gradle/build-scan-data
229+
- name: Upload test reports (if Gradle failed)
230+
uses: actions/upload-artifact@v4
231+
if: failure()
232+
with:
233+
name: test-reports-java11-${{ matrix.rdbms }}
234+
path: |
235+
./**/target/reports/tests/
236+
- name: Omit produced artifacts from build cache
237+
run: ./ci/before-cache.sh
238+
239+
# Static code analysis check
240+
format_checks:
241+
permissions:
242+
contents: read
243+
name: Static code analysis
244+
runs-on: ubuntu-latest
245+
strategy:
246+
fail-fast: false
247+
steps:
248+
- uses: actions/checkout@v4
249+
with:
250+
persist-credentials: false
251+
- name: Reclaim disk space and sanitize user home
252+
run: .github/ci-prerequisites-atlas.sh
253+
- name: Set up Java 17
254+
uses: actions/setup-java@v4
255+
with:
256+
distribution: 'temurin'
257+
java-version: '17'
258+
259+
- name: Generate cache key
260+
id: cache-key
261+
run: |
262+
CURRENT_BRANCH="${{ github.repository != 'hibernate/hibernate-orm' && 'fork' || github.base_ref || github.ref_name }}"
263+
CURRENT_MONTH=$(/bin/date -u "+%Y-%m")
264+
CURRENT_DAY=$(/bin/date -u "+%d")
265+
ROOT_CACHE_KEY="buildtool-cache-atlas"
266+
echo "buildtool-monthly-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}" >> $GITHUB_OUTPUT
267+
echo "buildtool-monthly-branch-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}-${CURRENT_BRANCH}" >> $GITHUB_OUTPUT
268+
echo "buildtool-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}-${CURRENT_BRANCH}-${CURRENT_DAY}" >> $GITHUB_OUTPUT
269+
- name: Cache Maven/Gradle Dependency/Dist Caches
270+
id: cache-maven
271+
uses: actions/cache@v4
272+
# if it's not a pull request, we restore and save the cache
273+
if: github.event_name != 'pull_request'
274+
with:
275+
path: |
276+
~/.m2/repository/
277+
~/.m2/wrapper/
278+
~/.gradle/caches/modules-2
279+
~/.gradle/wrapper/
280+
# A new cache will be stored daily. After that first store of the day, cache save actions will fail because the cache is immutable but it's not a problem.
281+
# The whole cache is dropped monthly to prevent unlimited growth.
282+
# The cache is per branch but in case we don't find a branch for a given branch, we will get a cache from another branch.
283+
key: ${{ steps.cache-key.outputs.buildtool-cache-key }}
284+
restore-keys: |
285+
${{ steps.cache-key.outputs.buildtool-monthly-branch-cache-key }}-
286+
${{ steps.cache-key.outputs.buildtool-monthly-cache-key }}-
287+
- name: Restore Maven/Gradle Dependency/Dist Caches
288+
uses: actions/cache/restore@v4
289+
# if it a pull request, we restore the cache but we don't save it
290+
if: github.event_name == 'pull_request'
291+
with:
292+
path: |
293+
~/.m2/repository/
294+
~/.m2/wrapper/
295+
~/.gradle/caches/modules-2
296+
~/.gradle/wrapper/
297+
key: ${{ steps.cache-key.outputs.buildtool-cache-key }}
298+
restore-keys: |
299+
${{ steps.cache-key.outputs.buildtool-monthly-branch-cache-key }}-
300+
${{ steps.cache-key.outputs.buildtool-monthly-cache-key }}-
301+
302+
- name: Run build script
303+
run: ./gradlew formatChecks
304+
env:
305+
# For jobs running on 'push', publish build scan and cache immediately.
306+
# This won't work for pull requests, since they don't have access to secrets.
307+
POPULATE_REMOTE_GRADLE_CACHE: ${{ github.event_name == 'push' && github.repository == 'hibernate/hibernate-orm' && 'true' || 'false' }}
308+
DEVELOCITY_ACCESS_KEY: "${{ secrets.DEVELOCITY_ACCESS_KEY }}"
309+
310+
# For jobs running on 'pull_request', upload build scan data.
311+
# The actual publishing must be done in a separate job (see ci-report.yml).
312+
# We don't write to the remote cache as that would be unsafe.
313+
- name: Upload GitHub Actions artifact for the Develocity build scan
314+
uses: actions/upload-artifact@v4
315+
if: "${{ github.event_name == 'pull_request' && !cancelled() }}"
316+
with:
317+
name: build-scan-data-${{ matrix.rdbms }}
318+
path: ~/.gradle/build-scan-data
319+
229320
- name: Upload test reports (if Gradle failed)
230321
uses: actions/upload-artifact@v4
231322
if: failure()

ci/build.sh

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

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

gradle/java-module.gradle

Lines changed: 28 additions & 2 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)/
@@ -512,8 +512,34 @@ spotless {
512512
}
513513
}
514514

515-
tasks.spotlessApply.dependsOn enforceRules
515+
tasks.check.dependsOn enforceRules
516516

517+
tasks.register( "ciCheck" ) {
518+
// Task used by CI builds
519+
group "verification"
520+
description "Checks for CI environments"
521+
dependsOn tasks.check
522+
523+
// These are already enforced by the formatChecks task
524+
spotlessApply {
525+
enabled = false
526+
}
527+
spotlessJavaApply {
528+
enabled = false
529+
}
530+
enforceRules {
531+
enabled = false
532+
}
533+
}
534+
535+
tasks.register( "formatChecks" ) {
536+
// Only runs static code analysis, doesn't require compilation
537+
group "verification"
538+
description "Code style and formatting checks"
539+
540+
dependsOn tasks.spotlessCheck
541+
dependsOn tasks.enforceRules
542+
}
517543

518544
class CompilerStubsArgumentProvider implements CommandLineArgumentProvider {
519545

0 commit comments

Comments
 (0)