This is an automated email from the ASF dual-hosted git repository.

jdaugherty pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 0c2c4f332776cca8ed5dce806ee43eca30043242
Author: James Daugherty <[email protected]>
AuthorDate: Thu Apr 24 12:08:01 2025 -0400

    add helper scripts to test reproducible builds
---
 etc/bin/generate-build-artifact-hashes.groovy      | 57 ++++++++++++++++++++++
 ...ducible-build.sh => test-reproducible-build.sh} | 12 ++---
 2 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/etc/bin/generate-build-artifact-hashes.groovy 
b/etc/bin/generate-build-artifact-hashes.groovy
new file mode 100755
index 0000000000..9b02b049bd
--- /dev/null
+++ b/etc/bin/generate-build-artifact-hashes.groovy
@@ -0,0 +1,57 @@
+#!/usr/bin/env groovy
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+import java.nio.file.*
+import java.security.MessageDigest
+
+// ---------------------------------------------------------------------------
+String sha256(Path file) {
+    MessageDigest md = MessageDigest.getInstance('SHA-256')
+    file.withInputStream { is ->
+        byte[] buf = new byte[8192]
+        for (int r = is.read(buf); r > 0; r = is.read(buf))
+            md.update(buf, 0, r)
+    }
+    md.digest().collect { String.format('%02x', it) }.join()
+}
+
+Path scriptDir = Paths.get(getClass()
+        .protectionDomain
+        .codeSource
+        .location
+        .toURI())
+        .toAbsolutePath()
+        .parent
+
+Path root = scriptDir.resolve('..').resolve('..').normalize()
+List<Path> artifacts = []
+Files.walk(root)
+        .filter {
+            Files.isRegularFile(it) &&
+                    it.toString().endsWith('.jar') &&
+                    
it.toString().contains("${File.separator}build${File.separator}libs${File.separator}")
+        }
+        .forEach { artifacts << it }
+
+artifacts.sort { a, b -> a.toString() <=> b.toString() }
+        .each { Path jar ->
+            String hash = sha256(jar)
+            String relative = root.relativize(jar).toString()
+            println "${hash} ${relative}"
+        }
\ No newline at end of file
diff --git a/etc/bin/reproducible-build.sh b/etc/bin/test-reproducible-build.sh
similarity index 82%
rename from etc/bin/reproducible-build.sh
rename to etc/bin/test-reproducible-build.sh
index 23e6ba3385..f15230a4aa 100755
--- a/etc/bin/reproducible-build.sh
+++ b/etc/bin/test-reproducible-build.sh
@@ -19,20 +19,20 @@
 #
 
 export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
-SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
 
+SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
 cd "$SCRIPT_DIR/../.."
 
 git clean -xdf
 ./gradlew build --rerun-tasks -PskipTests
-FIRST_BUILD=$(sha256sum build/libs/*)
+FIRST_BUILD=$("$SCRIPT_DIR/generate-build-artifact-hashes.groovy")
 
 git clean -xdf
 ./gradlew build --rerun-tasks -PskipTests
-SECOND_BUILD=$(sha256sum build/libs/*)
+SECOND_BUILD=$("$SCRIPT_DIR/generate-build-artifact-hashes.groovy")
 
-cd $SCRIPT_DIR
-echo $FIRST_BUILD > first.txt
-echo $SECOND_BUILD > second.txt
+cd -
+echo "$FIRST_BUILD" > first.txt
+echo "$SECOND_BUILD" > second.txt
 
 diff -u first.txt second.txt
\ No newline at end of file

Reply via email to