Skip to content

Commit f468d92

Browse files
mbelladesebersole
authored andcommitted
HHH-18678 Specific task for CI build and separate step for format checks
1 parent a1dab80 commit f468d92

File tree

3 files changed

+124
-9
lines changed

3 files changed

+124
-9
lines changed

.github/workflows/ci.yml

Lines changed: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
branches:
99
- 'main'
1010

11-
permissions: {} # none
11+
permissions: { } # none
1212

1313
# See https://github.com/hibernate/hibernate-orm/pull/4615 for a description of the behavior we're getting.
1414
concurrency:
@@ -41,10 +41,10 @@ jobs:
4141
- rdbms: db2
4242
- rdbms: mssql
4343
- rdbms: sybase
44-
# Running with CockroachDB requires at least 2-4 vCPUs, which we don't have on GH Actions runners
45-
# - rdbms: cockroachdb
46-
# Running with HANA requires at least 8GB memory just for the database, which we don't have on GH Actions runners
47-
# - rdbms: hana
44+
# Running with CockroachDB requires at least 2-4 vCPUs, which we don't have on GH Actions runners
45+
# - rdbms: cockroachdb
46+
# Running with HANA requires at least 8GB memory just for the database, which we don't have on GH Actions runners
47+
# - rdbms: hana
4848
steps:
4949
- uses: actions/checkout@v4
5050
with:
@@ -141,7 +141,7 @@ jobs:
141141
contents: read
142142
name: GraalVM 21 - ${{matrix.rdbms}}
143143
# runs-on: ubuntu-latest
144-
runs-on: [self-hosted, Linux, X64, OCI]
144+
runs-on: [ self-hosted, Linux, X64, OCI ]
145145
strategy:
146146
fail-fast: false
147147
matrix:
@@ -233,5 +233,94 @@ jobs:
233233
name: test-reports-java11-${{ matrix.rdbms }}
234234
path: |
235235
./**/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+
steps:
246+
- uses: actions/checkout@v4
247+
with:
248+
persist-credentials: false
249+
- name: Reclaim disk space and sanitize user home
250+
run: .github/ci-prerequisites-atlas.sh
251+
- name: Set up Java 17
252+
uses: actions/setup-java@v4
253+
with:
254+
distribution: 'temurin'
255+
java-version: '17'
256+
257+
- name: Generate cache key
258+
id: cache-key
259+
run: |
260+
CURRENT_BRANCH="${{ github.repository != 'hibernate/hibernate-orm' && 'fork' || github.base_ref || github.ref_name }}"
261+
CURRENT_MONTH=$(/bin/date -u "+%Y-%m")
262+
CURRENT_DAY=$(/bin/date -u "+%d")
263+
ROOT_CACHE_KEY="buildtool-cache-atlas"
264+
echo "buildtool-monthly-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}" >> $GITHUB_OUTPUT
265+
echo "buildtool-monthly-branch-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}-${CURRENT_BRANCH}" >> $GITHUB_OUTPUT
266+
echo "buildtool-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}-${CURRENT_BRANCH}-${CURRENT_DAY}" >> $GITHUB_OUTPUT
267+
- name: Cache Maven/Gradle Dependency/Dist Caches
268+
id: cache-maven
269+
uses: actions/cache@v4
270+
# if it's not a pull request, we restore and save the cache
271+
if: github.event_name != 'pull_request'
272+
with:
273+
path: |
274+
~/.m2/repository/
275+
~/.m2/wrapper/
276+
~/.gradle/caches/modules-2
277+
~/.gradle/wrapper/
278+
# 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.
279+
# The whole cache is dropped monthly to prevent unlimited growth.
280+
# 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.
281+
key: ${{ steps.cache-key.outputs.buildtool-cache-key }}
282+
restore-keys: |
283+
${{ steps.cache-key.outputs.buildtool-monthly-branch-cache-key }}-
284+
${{ steps.cache-key.outputs.buildtool-monthly-cache-key }}-
285+
- name: Restore Maven/Gradle Dependency/Dist Caches
286+
uses: actions/cache/restore@v4
287+
# if it a pull request, we restore the cache but we don't save it
288+
if: github.event_name == 'pull_request'
289+
with:
290+
path: |
291+
~/.m2/repository/
292+
~/.m2/wrapper/
293+
~/.gradle/caches/modules-2
294+
~/.gradle/wrapper/
295+
key: ${{ steps.cache-key.outputs.buildtool-cache-key }}
296+
restore-keys: |
297+
${{ steps.cache-key.outputs.buildtool-monthly-branch-cache-key }}-
298+
${{ steps.cache-key.outputs.buildtool-monthly-cache-key }}-
299+
300+
- name: Run build script
301+
run: ./gradlew formatChecks
302+
env:
303+
# For jobs running on 'push', publish build scan and cache immediately.
304+
# This won't work for pull requests, since they don't have access to secrets.
305+
POPULATE_REMOTE_GRADLE_CACHE: ${{ github.event_name == 'push' && github.repository == 'hibernate/hibernate-orm' && 'true' || 'false' }}
306+
DEVELOCITY_ACCESS_KEY: "${{ secrets.DEVELOCITY_ACCESS_KEY }}"
307+
308+
# For jobs running on 'pull_request', upload build scan data.
309+
# The actual publishing must be done in a separate job (see ci-report.yml).
310+
# We don't write to the remote cache as that would be unsafe.
311+
- name: Upload GitHub Actions artifact for the Develocity build scan
312+
uses: actions/upload-artifact@v4
313+
if: "${{ github.event_name == 'pull_request' && !cancelled() }}"
314+
with:
315+
name: build-scan-data-sca
316+
path: ~/.gradle/build-scan-data
317+
318+
- name: Upload test reports (if Gradle failed)
319+
uses: actions/upload-artifact@v4
320+
if: failure()
321+
with:
322+
name: test-reports-java11-sca
323+
path: |
324+
./**/target/reports/tests/
236325
- name: Omit produced artifacts from build cache
237326
run: ./ci/before-cache.sh

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)