Skip to content

Commit

Permalink
HSEARCH-5094 Enable Develocity build cache and build scans on CI
Browse files Browse the repository at this point in the history
Also, adapt CI to work with build cache:

* Add a clean for build steps: the build cache should take care of skipping duplicate executions
* Don't skip non-cacheable goals such as moditect or code injection
* Remove now unnecessary skipSurefireTests/ci-rebuild

Co-Authored-By: Yoann Rodière <yoann@hibernate.org>
  • Loading branch information
gsmet and yrodiere committed Mar 1, 2024
1 parent 807f74d commit 46d294d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 46 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,17 @@ jobs:
run: ./ci/docker-cleanup.sh
- name: Building code and running unit tests and basic checks
run: |
./mvnw $MAVEN_ARGS ${{ matrix.os.maven.args }} install \
./mvnw $MAVEN_ARGS ${{ matrix.os.maven.args }} clean install \
-Pjqassistant -Pdist -Pci-sources-check -DskipITs
env:
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
- name: Running integration tests in the default environment
run: |
./mvnw $MAVEN_ARGS ${{ matrix.os.maven.args }} verify \
-DskipSurefireTests -Pskip-checks -Pci-rebuild \
./mvnw $MAVEN_ARGS ${{ matrix.os.maven.args }} clean verify \
-Pskip-checks \
${{ github.event.pull_request.base.ref && format('-Dincremental -Dgib.referenceBranch=refs/remotes/origin/{0}', github.event.pull_request.base.ref) || '' }}
env:
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
- name: Docker cleanup
if: always()
run: ./ci/docker-cleanup.sh
Expand Down
41 changes: 33 additions & 8 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ import org.hibernate.jenkins.pipeline.helpers.alternative.AlternativeMultiMap
* Then you will also need to add SonarCloud credentials in Jenkins
* and reference them from the configuration file (see below).
*
* #### Develocity (optional)
*
* You will need to add Develocity credentials in Jenkins
* and reference them from the configuration file (see below).
*
* #### Gitter (optional)
*
* You need to enable the Jenkins integration in your Gitter room first:
Expand Down Expand Up @@ -126,6 +131,17 @@ import org.hibernate.jenkins.pipeline.helpers.alternative.AlternativeMultiMap
* # Expects username/password credentials where the username is the organization ID on sonarcloud.io
* # and the password is a sonarcloud.io access token with sufficient rights for that organization.
* credentials: ...
* develocity:
* credentials:
* # String containing the ID of Develocity credentials used on "main" (non-PR) builds. Optional.
* # Expects something valid for the GRADLE_ENTERPRISE_ACCESS_KEY environment variable.
* # See https://docs.gradle.com/enterprise/gradle-plugin/#via_environment_variable
* main: ...
* # String containing the ID of Develocity credentials used on PR builds. Optional.
* # Expects something valid for the GRADLE_ENTERPRISE_ACCESS_KEY environment variable.
* # See https://docs.gradle.com/enterprise/gradle-plugin/#via_environment_variable
* # WARNING: These credentials should not give write access to the build cache!
* pr: ...
* deployment:
* maven:
* # String containing the ID of a Maven settings file registered using the config-file-provider Jenkins plugin.
Expand Down Expand Up @@ -429,27 +445,23 @@ stage('Default build') {
// Jacoco will just not report coverage for these classes.
// In PRs, "relevant" modules are only those affected by changes.
// However:
// - Maven will normally not recompile anything as class files are still here.
// - We disable running unit tests (surefire) because we already ran them just above.
// - We have the Develocity local build cache to avoid re-compiling/re-running unit tests.
// - We disable a couple checks that were run above.
// - We activate a profile that fixes the second Maven execution
// by disabling a few misbehaving plugins whose output is already there anyway.
String itMavenArgs = """ \
${commonMavenArgs} \
-DskipSurefireTests \
-Pskip-checks \
-Pci-build \
-Pci-rebuild \
${incrementalBuild ? """ \
-Dincremental \
-Dgib.referenceBranch=refs/remotes/origin/${helper.scmSource.pullRequest.target.name} \
""" : '' } \
"""
pullContainerImages( itMavenArgs )
// Note "clean" is necessary here in order to store the result of the build in the remote build cache
sh """ \
mvn \
${itMavenArgs} \
verify \
clean verify \
"""

def sonarCredentialsId = helper.configuration.file?.sonar?.credentials
Expand Down Expand Up @@ -884,7 +896,19 @@ void withMavenWorkspace(Map args, Closure body) {
// to be performed by helper.withMavenWorkspace before we can call the script.
sh 'ci/docker-cleanup.sh'
try {
body()
def develocityCredentialsId = helper.scmSource.pullRequest ?
helper.configuration.file?.develocity?.credentials?.pr : helper.configuration.file?.develocity?.credentials?.main
if (develocityCredentialsId) {
withCredentials([string(credentialsId: develocityCredentialsId,
variable: 'GRADLE_ENTERPRISE_ACCESS_KEY')]) {
withGradle { // withDevelocity, actually: https://plugins.jenkins.io/gradle/#plugin-content-capturing-build-scans-from-jenkins-pipeline
body()
}
}
}
else {
body()
}
}
finally {
sh 'ci/docker-cleanup.sh'
Expand Down Expand Up @@ -945,6 +969,7 @@ void mavenNonDefaultBuild(BuildEnvironment buildEnv, String args, List<String> a
// of the same test in different environments in reports
def testSuffix = buildEnv.tag.replaceAll('[^a-zA-Z0-9_\\-+]+', '_')

// Note "clean" is necessary here in order to store the result of the build in the remote build cache
sh """ \
mvn clean install -Pci-build -Dsurefire.environment=$testSuffix \
${toTestJdkArg(buildEnv)} \
Expand Down
7 changes: 6 additions & 1 deletion ci/dependency-update/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ def withMavenWorkspace(Closure body) {
withMaven(jdk: 'OpenJDK 17 Latest', maven: 'Apache Maven 3.9',
mavenLocalRepo: env.WORKSPACE_TMP + '/.m2repository',
options: [artifactsPublisher(disabled: true)]) {
body()
withCredentials([string(credentialsId: 'ge.hibernate.org-access-key',
variable: 'GRADLE_ENTERPRISE_ACCESS_KEY')]) {
withGradle { // withDevelocity, actually: https://plugins.jenkins.io/gradle/#plugin-content-capturing-build-scans-from-jenkins-pipeline
body()
}
}
}
}

Expand Down
34 changes: 0 additions & 34 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1693,40 +1693,6 @@
</properties>
</profile>

<!-- A profile for CI when we've already built the whole tree but for some reason need
to run Maven again, preferably without cleaning.
Useful for example when we do `mvn clean verify -DskipITs` then `mvn verify -Dincremental`;
the second execution needs this profile to fix a few things.
-->
<profile>
<id>ci-rebuild</id>
<properties>
<!-- Don't inject code again if we already did a full build (we only do this in the engine).
Necessary to avoid rebuilding JARs when executing Maven twice,
which has dramatic cascading effects as it leads to recompiling
sources for all depending projects. -->
<injection-plugin.phase>none</injection-plugin.phase>
<!-- Once we've already built the main modules, we don't need to run Moditect a second time,
and doing so will actually lead to errors because Moditect worries about overwriting
module-info.class files. -->
<moditect.skip>true</moditect.skip>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- This is to skip Surefire without skipping Failsafe -->
<skipTests>true</skipTests >
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>

<profile>
<id>IDEA</id>
<!--
Expand Down

0 comments on commit 46d294d

Please sign in to comment.