Skip to content

Commit 71fc3d3

Browse files
marko-bekhtaDavideD
authored andcommitted
[hibernate#1929] Enable reproducible archives
1 parent 8178bf8 commit 71fc3d3

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

ci/compare-build-results.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
3+
# This is a simple script to check if builds are reproducible. The steps are:
4+
# 1. Build Hibernate Reactive with `./gradlew --no-daemon clean publishToMavenLocal --no-build-cache -Dmaven.repo.local=some-path/out/build1`
5+
# 2. Build Hibernate Reactive with `./gradlew --no-daemon clean publishToMavenLocal --no-build-cache -Dmaven.repo.local=some-path/out/build2` second time pointing to a different local maven repository to publish
6+
# 3. Compare the build results with sh ./ci/compare-build-results.sh some-path/out/build1 some-path/out/build2
7+
# 4. The generated .buildcompare file will also contain the diffscope commands to see/compare the problematic build artifacts
8+
9+
outputDir1=$1
10+
outputDir2=$2
11+
outputDir1=${outputDir1%/}
12+
outputDir2=${outputDir2%/}
13+
14+
ok=()
15+
okFiles=()
16+
ko=()
17+
koFiles=()
18+
19+
for f in `find ${outputDir1} -type f | grep -v "javadoc.jar$" | grep -v "maven-metadata-local.xml$" | sort`
20+
do
21+
flocal=${f#$outputDir1}
22+
# echo "comparing ${flocal}"
23+
sha1=`shasum -a 512 $f | cut -f 1 -d ' '`
24+
sha2=`shasum -a 512 $outputDir2$flocal | cut -f 1 -d ' '`
25+
# echo "$sha1"
26+
# echo "$sha2"
27+
if [ "$sha1" = "$sha2" ]; then
28+
ok+=($flocal)
29+
okFiles+=(${flocal##*/})
30+
else
31+
ko+=($flocal)
32+
koFiles+=(${flocal##*/})
33+
fi
34+
done
35+
36+
# generate .buildcompare
37+
buildcompare=".buildcompare"
38+
echo "ok=${#ok[@]}" >> ${buildcompare}
39+
echo "ko=${#ko[@]}" >> ${buildcompare}
40+
echo "okFiles=\"${okFiles[@]}\"" >> ${buildcompare}
41+
echo "koFiles=\"${koFiles[@]}\"" >> ${buildcompare}
42+
echo "" >> ${buildcompare}
43+
echo "# see what caused the mismatch in the checksum by executing the following diffscope commands" >> ${buildcompare}
44+
for f in ${ko[@]}
45+
do
46+
echo "# diffoscope $outputDir1$f $outputDir2$f" >> ${buildcompare}
47+
done
48+
49+
if [ ${#ko[@]} -eq 0 ]; then
50+
exit 0
51+
else
52+
exit 1
53+
fi

ci/nightly/Jenkinsfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
6+
@Library('hibernate-jenkins-pipeline-helpers') _
7+
8+
pipeline {
9+
agent none
10+
triggers {
11+
cron '@midnight'
12+
}
13+
tools {
14+
jdk 'OpenJDK 17 Latest'
15+
}
16+
options {
17+
buildDiscarder logRotator(daysToKeepStr: '10', numToKeepStr: '3')
18+
disableConcurrentBuilds(abortPrevious: true)
19+
overrideIndexTriggers(false)
20+
}
21+
stages {
22+
stage('Build reproducibility check') {
23+
agent {
24+
label 'Worker&&Containers'
25+
}
26+
steps {
27+
timeout(time: 30, unit: 'MINUTES') {
28+
script {
29+
def tempDir = pwd(tmp: true)
30+
def repo1 = tempDir + '/repo1'
31+
def repo2 = tempDir + '/repo2'
32+
// build Hibernate Reactive two times without any cache and "publish" the resulting artifacts
33+
// to different maven repositories, so that we can compare them afterwards:
34+
sh "./gradlew --no-daemon clean publishToMavenLocal --no-build-cache -Dmaven.repo.local=${repo1}"
35+
sh "./gradlew --no-daemon clean publishToMavenLocal --no-build-cache -Dmaven.repo.local=${repo2}"
36+
37+
sh "sh ci/compare-build-results.sh ${repo1} ${repo2}"
38+
sh "cat .buildcompare"
39+
}
40+
}
41+
}
42+
}
43+
}
44+
post {
45+
always {
46+
notifyBuildResult maintainers: 'davide@hibernate.org'
47+
}
48+
}
49+
}

hibernate-reactive-core/build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ dependencies {
8181
testImplementation "org.testcontainers:oracle-xe:${testcontainersVersion}"
8282
}
8383

84+
// Reproducible Builds
85+
86+
// https://docs.gradle.org/current/userguide/working_with_files.html#sec:reproducible_archives
87+
// Configure archive tasks to produce reproducible archives:
88+
tasks.withType(AbstractArchiveTask).configureEach {
89+
preserveFileTimestamps = false
90+
reproducibleFileOrder = true
91+
}
92+
8493
// Print a summary of the results of the tests (number of failures, successes and skipped)
8594
def loggingSummary(db, result, desc) {
8695
if ( !desc.parent ) { // will match the outermost suite

0 commit comments

Comments
 (0)