forked from junit-team/junit5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make JAR builds reproducible (junit-team#2217)
This change uses Gradle's reproducible archives feature to consistently build the output JARs. Additionally, the build now supports `SOURCE_DATE_EPOCH` to allow overriding of `buildTimeAndDate` as this introduces non-determinism into the build. Timestamps in special-case JARs are now rewritten to make them reproducible using the same fixed-time constant as is being used when `isPreserveFileTimestamps` is set to false. Moreover, a GitHub Actions workflow is added that checks whether build is still reproducible on CI.
- Loading branch information
Showing
8 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Reproducible build | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- 'releases/*' | ||
pull_request: | ||
branches: | ||
- '*' | ||
|
||
jobs: | ||
check_build_reproducibility: | ||
name: 'Check build reproducibility' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: 'Set up JDK 11' | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 11 | ||
- name: Build and compare checksums | ||
shell: bash | ||
run: | | ||
./src/checkBuildReproducibility.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,5 @@ gradle-app.setting | |
*.graphml | ||
coverage.db* | ||
.metadata | ||
|
||
checksums* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import java.util.Calendar | ||
import java.util.GregorianCalendar | ||
import java.util.jar.JarEntry | ||
import java.util.jar.JarFile | ||
import java.util.jar.JarOutputStream | ||
import org.gradle.api.internal.file.archive.ZipCopyAction | ||
|
||
// This registers a `doLast` action to rewrite the timestamps of the project's output JAR | ||
afterEvaluate { | ||
val jarTask = (tasks.findByName("shadowJar") ?: tasks["jar"]) as Jar | ||
|
||
jarTask.doLast { | ||
|
||
val newFile = createTempFile("rewrite-timestamp") | ||
val originalOutput = jarTask.archiveFile.get().getAsFile() | ||
|
||
newFile.outputStream().use { os -> | ||
|
||
val newJarStream = JarOutputStream(os) | ||
val oldJar = JarFile(originalOutput) | ||
|
||
oldJar.entries() | ||
.toList() | ||
.distinctBy { it.name } | ||
.sortedBy { it.name } | ||
.forEach { entry -> | ||
val jarEntry = JarEntry(entry.name) | ||
|
||
// Use the same constant as the fixed timestamps in normal copy actions | ||
jarEntry.time = ZipCopyAction.CONSTANT_TIME_FOR_ZIP_ENTRIES | ||
|
||
newJarStream.putNextEntry(jarEntry) | ||
|
||
oldJar.getInputStream(entry).copyTo(newJarStream) | ||
} | ||
|
||
newJarStream.finish() | ||
} | ||
|
||
newFile.renameTo(originalOutput) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash -e | ||
|
||
rm -rf checksums* | ||
|
||
export SOURCE_DATE_EPOCH=$(date +%s) | ||
|
||
function calculate_checksums() { | ||
OUTPUT=$1 | ||
|
||
./gradlew --no-build-cache clean assemble --parallel | ||
|
||
find . -name '*.jar' \ | ||
| grep '/build/libs/' \ | ||
| grep --invert-match 'javadoc' \ | ||
| sort \ | ||
| xargs sha256sum > ${OUTPUT} | ||
} | ||
|
||
|
||
calculate_checksums checksums-1.txt | ||
calculate_checksums checksums-2.txt | ||
|
||
diff checksums-1.txt checksums-2.txt |