Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ BUILD_DATE_STAMP="202001010000.00"
function reproducible_tar_gzip() {
local dir=$1
local tar_cmd=tar
local gzip_cmd=gzip

# MacOS has a version of BSD tar which doesn't support setting the --mtime
# flag. We need gnu-tar, or gtar for short to be installed for this script to
Expand All @@ -38,12 +39,27 @@ function reproducible_tar_gzip() {
tar_cmd=gtar
fi

# On MacOS, the default BSD gzip produces a different output than the GNU
# gzip on Linux. To ensure reproducible builds, we need to use GNU gzip.
gzip_version=$(gzip --version 2>&1 || true)
if [[ ! "$gzip_version" =~ "GNU" ]]; then
if ! command -v "ggzip" >/dev/null 2>&1; then
echo "GNU gzip is required but cannot be found!"
echo "On MacOS please run 'brew install gzip' to install ggzip."
exit 1
fi

# We have ggzip installed, use that instead.
gzip_cmd=ggzip
fi

# Pin down the timestamp time zone.
export TZ=UTC

find "${dir}" -print0 | LC_ALL=C sort -r -z | $tar_cmd \
"--mtime=${BUILD_DATE}" --no-recursion --null --mode=u+rw,go+r-w,a+X \
--owner=0 --group=0 --numeric-owner -c -T - | gzip -9n > "${dir}.tar.gz"
--owner=0 --group=0 --numeric-owner -c -T - | $gzip_cmd \
-9n > "${dir}.tar.gz"

rm -r "${dir}"
}
Expand Down
Loading