From 32a825c1cc8e367a932ffbaa0f7eb93ed82407c1 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Wed, 7 May 2025 14:38:15 +0900 Subject: [PATCH 1/7] GH-46336: [Release][Packaging] Add support for Reproducible Builds for source archive See https://reproducible-builds.org/ for Reproducible Builds. Automated Release Signing requires this: https://infra.apache.org/release-signing.html#automated-release-signing --- .github/workflows/release_candidate.yml | 50 ++++++++++++++++++--- dev/release/utils-create-release-tarball.sh | 27 ++++++++++- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release_candidate.yml b/.github/workflows/release_candidate.yml index 5e222be06aa8..5d3f1ac94917 100644 --- a/.github/workflows/release_candidate.yml +++ b/.github/workflows/release_candidate.yml @@ -19,17 +19,26 @@ name: Release on: push: + branches: + - '**' + - '!dependabot/**' tags: # Trigger workflow when a tag whose name matches the pattern # "apache-arrow-{MAJOR}.{MINOR}.{PATCH}-rc{RC_NUM}" is pushed. - "apache-arrow-[0-9]+.[0-9]+.[0-9]+-rc[0-9]+" + paths: + - ".github/workflows/release_candidate.sh" + - "dev/release/utils-create-release-tarball.sh" + - "dev/release/utils-generate-checksum.sh" + pull_request: + paths: + - ".github/workflows/release_candidate.sh" + - "dev/release/utils-create-release-tarball.sh" + - "dev/release/utils-generate-checksum.sh" permissions: contents: write -env: - GH_TOKEN: ${{ github.token }} - jobs: publish: name: Publish @@ -40,12 +49,27 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Install dependencies + run: | + sudo apt update + sudo apt install -y -V reprotest - name: Store Version and Release Candidate Number run: | - version_with_rc=${GITHUB_REF_NAME#apache-arrow-} - version=${version_with_rc%-rc*} - rc_num=${version_with_rc#${version}-rc} - echo "VERSION_WITH_RC=${version_with_rc}" >> ${GITHUB_ENV} + if [ "${GITHUB_REF_TYPE}" = "tag" ]; then + version_with_rc=${GITHUB_REF_NAME#apache-arrow-} + version=${version_with_rc%-rc*} + rc_num=${version_with_rc#${version}-rc} + else + version=$(grep '^set(ARROW_VERSION ' cpp/CMakeLists.txt | \ + grep -E -o '[0-9]+\.[0-9]+\.[0-9]+') + rc_num=0 + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag \ + -a \ + "apache-arrow-${version}-rc${rc_num}" \ + -m "Apache Arrow ${version} RC${rc_num}" + fi echo "VERSION=${version}" >> ${GITHUB_ENV} echo "RC_NUM=${rc_num}" >> ${GITHUB_ENV} - name: Create Release Candidate Title @@ -58,10 +82,22 @@ jobs: echo "RELEASE_CANDIDATE_NOTES=${release_notes}" >> ${GITHUB_ENV} - name: Create Release tarball run: | + sudo reprotest \ + "dev/release/utils-create-release-tarball.sh ${VERSION} ${RC_NUM}" \ + apache-arrow-${VERSION}.tar.gz dev/release/utils-create-release-tarball.sh ${VERSION} ${RC_NUM} echo "RELEASE_TARBALL=apache-arrow-${VERSION}.tar.gz" >> ${GITHUB_ENV} dev/release/utils-generate-checksum.sh "apache-arrow-${VERSION}.tar.gz" + - name: Upload Artifacts + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: release-candidate + path: ${{ env.RELEASE_TARBALL }}* - name: Create GitHub Release + if: | + github.ref_type == 'tag' + env: + GH_TOKEN: ${{ github.token }} run: | gh release create ${GITHUB_REF_NAME} \ --verify-tag \ diff --git a/dev/release/utils-create-release-tarball.sh b/dev/release/utils-create-release-tarball.sh index 389197676201..cba1fdadae5a 100755 --- a/dev/release/utils-create-release-tarball.sh +++ b/dev/release/utils-create-release-tarball.sh @@ -46,18 +46,41 @@ rm -rf ${root_folder} # Resolve symbolic and hard links rm -rf ${root_folder}.tmp mv ${root_folder} ${root_folder}.tmp -cp -R -L ${root_folder}.tmp ${root_folder} +cp -a -L ${root_folder}.tmp ${root_folder} rm -rf ${root_folder}.tmp # Create a dummy .git/ directory to download the source files from GitHub with Source Link in C#. +if stat --help > /dev/null 2>&1; then + # GNU stat + csharp_mtime=$(date --date="$(stat --format="%y" csharp)" +%Y%m%d%H%M.%S) +else + # BSD stat + csharp_mtime=$(stat -f %Sm -t %Y%m%d%H%M.%S csharp) +fi dummy_git=${root_folder}/csharp/dummy.git mkdir ${dummy_git} pushd ${dummy_git} echo ${release_hash} > HEAD echo "[remote \"origin\"] url = https://github.com/${GITHUB_REPOSITORY:-apache/arrow}.git" >> config mkdir objects refs +find . -exec touch -t "${csharp_mtime}" '{}' ';' popd +touch -t "${csharp_mtime}" ${root_folder}/csharp # Create new tarball from modified source directory -tar czf ${tarball} ${root_folder} +if type gtar > /dev/null 2>&1; then + gtar=gtar +else + gtar=tar +fi +${gtar} \ + --group=0 \ + --mode=a=rX,u+w \ + --numeric-owner \ + --owner=0 \ + --sort=name \ + -cf \ + - \ + ${root_folder} | \ + gzip --no-name > ${tarball} rm -rf ${root_folder} From baa67183448059337cef7b2aad3e7c6408cc841f Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Wed, 7 May 2025 17:15:04 +0900 Subject: [PATCH 2/7] Verify reproducible source archive --- dev/release/verify-release-candidate.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/dev/release/verify-release-candidate.sh b/dev/release/verify-release-candidate.sh index f95ea861abd1..59b9d3ba2d3e 100755 --- a/dev/release/verify-release-candidate.sh +++ b/dev/release/verify-release-candidate.sh @@ -74,6 +74,8 @@ esac SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)" ARROW_DIR="$(cd "${SOURCE_DIR}/../.." && pwd)" +: ${GITHUB_REPOSITORY:=apache/arrow} + show_header() { echo "" printf '=%.0s' $(seq ${#1}); printf '\n' @@ -176,7 +178,7 @@ test_binary() { ${PYTHON:-python3} $SOURCE_DIR/download_rc_binaries.py $VERSION $RC_NUMBER \ --dest=${download_dir} \ - --repository=${GITHUB_REPOSITORY:-apache/arrow} \ + --repository=${GITHUB_REPOSITORY} \ --tag="apache-arrow-$VERSION-rc$RC_NUMBER" verify_dir_artifact_signatures ${download_dir} @@ -787,6 +789,14 @@ ensure_source_directory() { if [ ! -d "${ARROW_SOURCE_DIR}" ]; then pushd $ARROW_TMPDIR fetch_archive ${dist_name} + git clone https://github.com/${GITHUB_REPOSITORY}.git arrow + pushd arrow + dev/release/utils-create-release-tarball.sh ${VERSION} ${RC_NUMBER} + if ! cmp ${dist_name}.tar.gz ../${dist_name}.tar.gz; then + echo "Source archive isn't reproducible" + return 1 + fi + popd tar xf ${dist_name}.tar.gz popd fi @@ -988,7 +998,7 @@ test_wheels() { --package_type python \ --regex=${filter_regex} \ --dest=${download_dir} \ - --repository=${GITHUB_REPOSITORY:-apache/arrow} \ + --repository=${GITHUB_REPOSITORY} \ --tag="apache-arrow-$VERSION-rc$RC_NUMBER" verify_dir_artifact_signatures ${download_dir} From 370364cb971d79321a0c83b33fcc4fa096e271c4 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Thu, 8 May 2025 18:52:06 +0900 Subject: [PATCH 3/7] Add more comments about Reproducible Builds --- dev/release/utils-create-release-tarball.sh | 26 +++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/dev/release/utils-create-release-tarball.sh b/dev/release/utils-create-release-tarball.sh index cba1fdadae5a..b66ef6e74085 100755 --- a/dev/release/utils-create-release-tarball.sh +++ b/dev/release/utils-create-release-tarball.sh @@ -18,6 +18,12 @@ # under the License. # +# This must generate reproducible source archive. For reproducible +# source archive, we must use the same timestamp, user, group and so +# on. +# +# See also https://reproducible-builds.org/ for Reproducible Builds. + SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SOURCE_TOP_DIR="$(cd "${SOURCE_DIR}/../../" && pwd)" @@ -49,9 +55,19 @@ mv ${root_folder} ${root_folder}.tmp cp -a -L ${root_folder}.tmp ${root_folder} rm -rf ${root_folder}.tmp -# Create a dummy .git/ directory to download the source files from GitHub with Source Link in C#. +# Create a dummy .git/ directory to download the source files from +# GitHub with Source Link in C#. See the followings for more Source +# Link support and why we need a dummy .git directory: +# * https://github.com/apache/arrow/issues/21580 +# * https://github.com/apache/arrow/pull/4488 +# +# We need to set constant timestamp for a dummy .git/ directory for +# Reproducible Builds. We use mtime of csharp/ for it. if stat --help > /dev/null 2>&1; then # GNU stat + # + # touch accepts YYYYMMDDhhmm.ss format but GNU stat doesn't support + # for outputting with the format. So we use date for it. csharp_mtime=$(date --date="$(stat --format="%y" csharp)" +%Y%m%d%H%M.%S) else # BSD stat @@ -67,7 +83,13 @@ find . -exec touch -t "${csharp_mtime}" '{}' ';' popd touch -t "${csharp_mtime}" ${root_folder}/csharp -# Create new tarball from modified source directory +# Create new tarball from modified source directory. +# +# We need GNU tar for Reproducible Builds. We want to use the same +# owner, group, mode, file order for Reproducible Builds. +# +# gzip --no-name is for omitting timestamp in .gz. It's also for +# Reproducible Builds. if type gtar > /dev/null 2>&1; then gtar=gtar else From f6f206ab84cc8a841452301f893208563254b3c6 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Thu, 15 May 2025 18:09:12 +0900 Subject: [PATCH 4/7] Add more comments --- dev/release/utils-create-release-tarball.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dev/release/utils-create-release-tarball.sh b/dev/release/utils-create-release-tarball.sh index b66ef6e74085..39776f495077 100755 --- a/dev/release/utils-create-release-tarball.sh +++ b/dev/release/utils-create-release-tarball.sh @@ -85,8 +85,12 @@ touch -t "${csharp_mtime}" ${root_folder}/csharp # Create new tarball from modified source directory. # +# We need to strip unreproducible information. See also: +# https://reproducible-builds.org/docs/stripping-unreproducible-information/ +# # We need GNU tar for Reproducible Builds. We want to use the same # owner, group, mode, file order for Reproducible Builds. +# See also: https://reproducible-builds.org/docs/archives/ # # gzip --no-name is for omitting timestamp in .gz. It's also for # Reproducible Builds. From f71132d0394e06ffd63003e60a91316b5e0b28a4 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Thu, 15 May 2025 18:09:21 +0900 Subject: [PATCH 5/7] Use SOURCE_DATE_EPOCH if possible --- dev/release/utils-create-release-tarball.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/dev/release/utils-create-release-tarball.sh b/dev/release/utils-create-release-tarball.sh index 39776f495077..c9b6754f386b 100755 --- a/dev/release/utils-create-release-tarball.sh +++ b/dev/release/utils-create-release-tarball.sh @@ -62,7 +62,9 @@ rm -rf ${root_folder}.tmp # * https://github.com/apache/arrow/pull/4488 # # We need to set constant timestamp for a dummy .git/ directory for -# Reproducible Builds. We use mtime of csharp/ for it. +# Reproducible Builds. We use mtime of csharp/ for it. If +# SOURCE_DATE_EPOCH is defined, this mtime is overwritten when tar +# file is created. if stat --help > /dev/null 2>&1; then # GNU stat # @@ -99,12 +101,19 @@ if type gtar > /dev/null 2>&1; then else gtar=tar fi -${gtar} \ +gtar_options=( --group=0 \ --mode=a=rX,u+w \ --numeric-owner \ --owner=0 \ --sort=name \ +) +if [ -n "${SOURCE_DATE_EPOCH:-}" ]; then + gtar_options+=(--mtime="$(date +%Y-%m-%dT%H:%M:%S --date=@${SOURCE_DATE_EPOCH})") +fi +set -x +${gtar} \ + "${gtar_options[@]}" \ -cf \ - \ ${root_folder} | \ From 49b0858cacd93ad3f22f239ce4eae8c80f160724 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Thu, 19 Jun 2025 10:47:44 +0900 Subject: [PATCH 6/7] Use automated signing key --- .github/workflows/release_candidate.yml | 12 +++++++++++- dev/release/02-source.sh | 26 +------------------------ 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/.github/workflows/release_candidate.yml b/.github/workflows/release_candidate.yml index 5d3f1ac94917..c5a49f5fce06 100644 --- a/.github/workflows/release_candidate.yml +++ b/.github/workflows/release_candidate.yml @@ -52,7 +52,7 @@ jobs: - name: Install dependencies run: | sudo apt update - sudo apt install -y -V reprotest + sudo apt install -y -V gpg reprotest - name: Store Version and Release Candidate Number run: | if [ "${GITHUB_REF_TYPE}" = "tag" ]; then @@ -81,12 +81,22 @@ jobs: release_notes="Release Candidate: ${VERSION} RC${RC_NUM}" echo "RELEASE_CANDIDATE_NOTES=${release_notes}" >> ${GITHUB_ENV} - name: Create Release tarball + env: + ARROW_GPG_KEY_UID: A2AC7132B5DA7C273A7A147665F4A8CA9769ECD7 + ARROW_GPG_SECRET_KEY: ${{ secrets.ARROW_GPG_SECRET_KEY }} run: | sudo reprotest \ "dev/release/utils-create-release-tarball.sh ${VERSION} ${RC_NUM}" \ apache-arrow-${VERSION}.tar.gz dev/release/utils-create-release-tarball.sh ${VERSION} ${RC_NUM} echo "RELEASE_TARBALL=apache-arrow-${VERSION}.tar.gz" >> ${GITHUB_ENV} + echo "${ARROW_GPG_SECRET_KEY}" | gpg --import + gpg \ + --armor \ + --detach-sign \ + --local-user "${ARROW_GPG_SECRET_KEY}" \ + --output "${RELEASE_TARBALL}.asc" \ + "${RELEASE_TARBALL}" dev/release/utils-generate-checksum.sh "apache-arrow-${VERSION}.tar.gz" - name: Upload Artifacts uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 diff --git a/dev/release/02-source.sh b/dev/release/02-source.sh index 57220e4c1253..ab4fa106084d 100755 --- a/dev/release/02-source.sh +++ b/dev/release/02-source.sh @@ -75,37 +75,14 @@ if [ ${SOURCE_RAT} -gt 0 ]; then fi if [ ${SOURCE_UPLOAD} -gt 0 ]; then - rm -rf signed-artifacts - mkdir -p signed-artifacts - - # sign the artifacts - for artifact in artifacts/*; do - case "${artifact}" in - *.sha256|*.sha512) - continue - ;; - esac - gpg \ - --armor \ - --detach-sig \ - --output signed-artifacts/$(basename ${artifact}).asc \ - ${artifact} - done - - # Upload signed tarballs to GitHub Release - gh release upload ${tag} \ - --repo "${GITHUB_REPOSITORY}" \ - signed-artifacts/* - # check out the arrow RC folder svn co --depth=empty https://dist.apache.org/repos/dist/dev/arrow tmp # add the release candidate for the tag mkdir -p tmp/${tag} - # copy the rc tarball into the tmp dir + # copy the release candidate tarball and related files into the tmp dir cp artifacts/${tarball}* tmp/${tag} - cp signed-artifacts/${tarball}.asc tmp/${tag} # commit to svn svn add tmp/${tag} @@ -113,7 +90,6 @@ if [ ${SOURCE_UPLOAD} -gt 0 ]; then # clean up rm -rf artifacts - rm -rf signed-artifacts rm -rf tmp echo "Success! The release candidate is available here:" From 0f9048d86f5cc5fcb71a014a19e4f8663849519e Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Thu, 19 Jun 2025 11:51:20 +0900 Subject: [PATCH 7/7] Check ARROW_GPG_SECRET_KEY --- .github/workflows/release_candidate.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release_candidate.yml b/.github/workflows/release_candidate.yml index c5a49f5fce06..9e44f4d2527d 100644 --- a/.github/workflows/release_candidate.yml +++ b/.github/workflows/release_candidate.yml @@ -90,14 +90,16 @@ jobs: apache-arrow-${VERSION}.tar.gz dev/release/utils-create-release-tarball.sh ${VERSION} ${RC_NUM} echo "RELEASE_TARBALL=apache-arrow-${VERSION}.tar.gz" >> ${GITHUB_ENV} - echo "${ARROW_GPG_SECRET_KEY}" | gpg --import - gpg \ - --armor \ - --detach-sign \ - --local-user "${ARROW_GPG_SECRET_KEY}" \ - --output "${RELEASE_TARBALL}.asc" \ - "${RELEASE_TARBALL}" dev/release/utils-generate-checksum.sh "apache-arrow-${VERSION}.tar.gz" + if [ -n "${ARROW_GPG_SECRET_KEY}" ]; then + echo "${ARROW_GPG_SECRET_KEY}" | gpg --import + gpg \ + --armor \ + --detach-sign \ + --local-user "${ARROW_GPG_SECRET_KEY}" \ + --output "${RELEASE_TARBALL}.asc" \ + "${RELEASE_TARBALL}" + fi - name: Upload Artifacts uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: