From 9cab55138eab0daf4fba2c422b5a7dd92b13ca09 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Tue, 4 Nov 2025 13:50:47 -0800 Subject: [PATCH 01/13] Improve the produce-package.sh script for wheel building - add -h, --help option to show usage information - add -c, --commit=COMMIT option for building from sources at COMMIT instead of at HEAD - respect SOURCE_DATE_EPOCH if available as environment variable. Otherwise get it from the commit time of the sources. - do not purge temporary files if script exits with an error --- dev_tools/packaging/produce-package.sh | 116 ++++++++++++++++++------- 1 file changed, 85 insertions(+), 31 deletions(-) diff --git a/dev_tools/packaging/produce-package.sh b/dev_tools/packaging/produce-package.sh index 42854523968..66c6d9b1a0a 100755 --- a/dev_tools/packaging/produce-package.sh +++ b/dev_tools/packaging/produce-package.sh @@ -14,62 +14,116 @@ # See the License for the specific language governing permissions and # limitations under the License. -################################################################################ -# Produces wheels that can be uploaded to the pypi package repository. -# -# First argument must be the output directory. Second argument is an optional -# version specifier. If not set, the version from `_version.py` is used. If set, -# it overwrites `_version.py`. -# -# Usage: -# dev_tools/packaging/produce-package.sh output_dir [version] -################################################################################ +set -o errexit +set -o nounset -set -e trap "{ echo -e '\033[31mFAILED\033[0m'; }" ERR -if [ -z "${1}" ]; then - echo -e "\033[31mNo output directory given.\033[0m" - exit 1 -fi -out_dir=$(realpath "${1}") +DOC="\ +usage: $0 [options] output_dir [version] + +Produces wheels that can be uploaded to the pypi package repository. + +First argument must be the output directory. Second argument is an optional +version specifier, which overwrites the version in _version.py files. +If not set, the version from _version.py is used as is. -SPECIFIED_VERSION="${2}" +Options: + + -c, --commit=COMMIT create wheels from sources at COMMIT instead of HEAD + -h, --help display this message and exit. +" + +out_dir="" +specified_version="" +commitish=HEAD + + +die() { + ( shift; echo -e "\033[31m${*}\033[0m" ) + exit "$1" +} # Helper to isolate dev_tools/modules.py from Python environment variables my_dev_tools_modules() { python3 -E dev_tools/modules.py "$@" } -# Get the working directory to the repo root. +# Process command-line arguments +while (( $# )); do + case "$1" in + -h|--help) + echo "$DOC" + exit 0 + ;; + -c?*) + commitish="${1#-c}" + ;; + --commit=?*) + commitish="${1#*=}" + ;; + -c|--commit) + shift + (( $# )) || die 2 "Option '-c,--commit' requires an argument." + commit="$1" + ;; + *) + if [[ -z "${out_dir}" ]]; then + out_dir=$(realpath "${1}") + elif [[ -z "${specified_version}" ]]; then + specified_version="${1}" + else + die 2 "Unrecognized argument '$1'." + fi + ;; + esac + shift +done + +if [[ -z "${out_dir}" ]]; then + die 2 "No output directory given." +fi + +# Change to the root of the Cirq git repository thisdir=$(dirname "${BASH_SOURCE[0]:?}") repo_dir=$(git -C "${thisdir}" rev-parse --show-toplevel) cd "${repo_dir}" -# Make a clean copy of HEAD, without files ignored by git (but potentially kept by setup.py). -if [ -n "$(git status --short)" ]; then +# Validate and resolve the commit value +commit=$(git rev-parse --verify --quiet "${commitish}^{commit}") || + die "$?" "Invalid commit identifier '${commitish}'" + +# Make a pristine temporary clone of the Cirq repository +if [[ -n "$(git status --short)" ]]; then echo -e "\033[31mWARNING: You have uncommitted changes. They won't be included in the package.\033[0m" fi + tmp_git_dir=$(mktemp -d "/tmp/produce-package-git.XXXXXXXXXXXXXXXX") -trap '{ rm -rf "${tmp_git_dir}"; }' EXIT echo "Creating pristine repository clone at ${tmp_git_dir}" -git clone --shared --quiet "${repo_dir}" "${tmp_git_dir}" +git clone --shared --quiet --no-checkout "${repo_dir}" "${tmp_git_dir}" cd "${tmp_git_dir}" -if [ -n "${SPECIFIED_VERSION}" ]; then - CURRENT_VERSION=$(my_dev_tools_modules print_version) - my_dev_tools_modules replace_version --old="${CURRENT_VERSION}" --new="${SPECIFIED_VERSION}" +git checkout --quiet "${commit}" + +if [[ -n "${specified_version}" ]]; then + current_version=$(my_dev_tools_modules print_version) + my_dev_tools_modules replace_version --old="${current_version}" --new="${specified_version}" fi # Python 3 wheel. echo "Producing python 3 package files." -CIRQ_MODULES=$(my_dev_tools_modules list --mode folder --include-parent) -date_epoch=$(git log -1 --pretty="%ct") +# Reuse SOURCE_DATE_EPOCH if specified in the caller environment +date_epoch=${SOURCE_DATE_EPOCH:-$(git log -1 --pretty="%ct")} +cirq_modules=$(my_dev_tools_modules list --mode folder --include-parent) -for m in $CIRQ_MODULES; do - echo "creating wheel for ${m}" - SOURCE_DATE_EPOCH="${date_epoch}" \ - python3 -m pip wheel --no-deps --wheel-dir="${out_dir}" "./${m}" +for m in ${cirq_modules}; do + echo "creating wheel for ${m}" + SOURCE_DATE_EPOCH="${date_epoch}" \ + python3 -m pip wheel --no-deps --wheel-dir="${out_dir}" "./${m}" done ls "${out_dir}" + +# Final clean up (all is well if we got here) +cd "${repo_dir}" +rm -rf "${tmp_git_dir}" From e49ef747ccb532cad0a88ee16766cbdec30440ff Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Tue, 4 Nov 2025 14:28:38 -0800 Subject: [PATCH 02/13] Skip dev release if it is identical to the last one --- .github/workflows/release-main.yml | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-main.yml b/.github/workflows/release-main.yml index 67dc36324a9..2392a4fa345 100644 --- a/.github/workflows/release-main.yml +++ b/.github/workflows/release-main.yml @@ -34,7 +34,24 @@ jobs: - name: Build and publish run: | CIRQ_PRE_RELEASE_VERSION=$(dev_tools/packaging/generate-dev-version-id.sh) - [[ "$CIRQ_PRE_RELEASE_VERSION" =~ .*dev.* ]] && echo "Deploying dev version '$CIRQ_PRE_RELEASE_VERSION'" || (echo "not dev version"; exit 1) + if [[ "${CIRQ_PRE_RELEASE_VERSION}" != *.dev* ]]; then + echo "Not a dev version" + exit 1 + fi + echo "Building wheels for the dev version '${CIRQ_PRE_RELEASE_VERSION}'" + THIS_DATE_EPOCH=$(git log -1 --pretty="%ct") out_dir="${PWD}/dist" - dev_tools/packaging/produce-package.sh ${out_dir} $CIRQ_PRE_RELEASE_VERSION + out_dir_last="${PWD}/dist-last" + dev_tools/packaging/produce-package.sh "${out_dir}" "${CIRQ_PRE_RELEASE_VERSION}" + # disregard errors from building wheels at the previous commit + SOURCE_DATE_EPOCH=${THIS_DATE_EPOCH} dev_tools/packaging/produce-package.sh \ + --commit="HEAD~1" "${out_dir_last}" "${CIRQ_PRE_RELEASE_VERSION}" || true + echo "Comparing wheels with the previous version" + if diff -q -r "${out_dir_last}" "${out_dir}"; then + echo "### Skipping identical release" >> ${GITHUB_STEP_SUMMARY} + echo "Cirq release wheels at '${CIRQ_PRE_RELEASE_VERSION}' (${GITHUB_SHA})" \ + "are identical to those at the previous commit." >> ${GITHUB_STEP_SUMMARY} + exit 0 + fi + echo "Deploying dev version '$CIRQ_PRE_RELEASE_VERSION'" twine upload "${out_dir}/*" From fa2ebd216d0b5bbcafb04d3e1b65cdee0217d44d Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Tue, 4 Nov 2025 14:38:17 -0800 Subject: [PATCH 03/13] REVERT ME - temporarily activate release-main in pull requests --- .github/workflows/release-main.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release-main.yml b/.github/workflows/release-main.yml index 2392a4fa345..46c6e8974ad 100644 --- a/.github/workflows/release-main.yml +++ b/.github/workflows/release-main.yml @@ -4,6 +4,10 @@ on: push: branches: - main + # FIXME - for PR testing only, remove before merge + pull_request: + branches: + - main # Declare default permissions as read only. permissions: read-all @@ -54,4 +58,4 @@ jobs: exit 0 fi echo "Deploying dev version '$CIRQ_PRE_RELEASE_VERSION'" - twine upload "${out_dir}/*" + echo "[would execute]" twine upload "${out_dir}/*" From a7a5c6b5ba2a4d88ac6ee759d8f59dfb9176b38c Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Tue, 4 Nov 2025 14:53:37 -0800 Subject: [PATCH 04/13] Fetch several commits on GHA so we can compare with ancestors --- .github/workflows/release-main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release-main.yml b/.github/workflows/release-main.yml index 46c6e8974ad..c7bcd2a3f18 100644 --- a/.github/workflows/release-main.yml +++ b/.github/workflows/release-main.yml @@ -21,6 +21,8 @@ jobs: NAME: dev-release steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + fetch-depth: 2 - uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0 with: python-version: '3.11' From 9f0e72e92faed2b05f09751802fc50eda0dc5625 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Tue, 4 Nov 2025 15:03:34 -0800 Subject: [PATCH 05/13] Improve workflow messaging Show if wheels are identical or not also in the workflow log and improve the workflow summary text. --- .github/workflows/release-main.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release-main.yml b/.github/workflows/release-main.yml index c7bcd2a3f18..9d803440358 100644 --- a/.github/workflows/release-main.yml +++ b/.github/workflows/release-main.yml @@ -54,9 +54,10 @@ jobs: --commit="HEAD~1" "${out_dir_last}" "${CIRQ_PRE_RELEASE_VERSION}" || true echo "Comparing wheels with the previous version" if diff -q -r "${out_dir_last}" "${out_dir}"; then - echo "### Skipping identical release" >> ${GITHUB_STEP_SUMMARY} - echo "Cirq release wheels at '${CIRQ_PRE_RELEASE_VERSION}' (${GITHUB_SHA})" \ - "are identical to those at the previous commit." >> ${GITHUB_STEP_SUMMARY} + echo "Wheels are identical - skipping the release" + echo "### Skipped identical release" >> ${GITHUB_STEP_SUMMARY} + echo "Cirq release wheels for ${CIRQ_PRE_RELEASE_VERSION} (${GITHUB_SHA:0:10})" \ + "are identical to wheels at the previous commit." >> ${GITHUB_STEP_SUMMARY} exit 0 fi echo "Deploying dev version '$CIRQ_PRE_RELEASE_VERSION'" From e2ac561041135b67c077307ed41e0cccf901564d Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Tue, 4 Nov 2025 15:06:08 -0800 Subject: [PATCH 06/13] Yet another message tweak --- .github/workflows/release-main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-main.yml b/.github/workflows/release-main.yml index 9d803440358..9548834f3f5 100644 --- a/.github/workflows/release-main.yml +++ b/.github/workflows/release-main.yml @@ -57,7 +57,7 @@ jobs: echo "Wheels are identical - skipping the release" echo "### Skipped identical release" >> ${GITHUB_STEP_SUMMARY} echo "Cirq release wheels for ${CIRQ_PRE_RELEASE_VERSION} (${GITHUB_SHA:0:10})" \ - "are identical to wheels at the previous commit." >> ${GITHUB_STEP_SUMMARY} + "are identical to their build at previous commit." >> ${GITHUB_STEP_SUMMARY} exit 0 fi echo "Deploying dev version '$CIRQ_PRE_RELEASE_VERSION'" From dc43d3300c743f114be6159e50dca81bc5c3b0a6 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Tue, 4 Nov 2025 15:14:39 -0800 Subject: [PATCH 07/13] Output wheel files outside of the cirq repository Avoid log warning about repository not being clean. --- .github/workflows/release-main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-main.yml b/.github/workflows/release-main.yml index 9548834f3f5..be56f66a0e3 100644 --- a/.github/workflows/release-main.yml +++ b/.github/workflows/release-main.yml @@ -46,8 +46,8 @@ jobs: fi echo "Building wheels for the dev version '${CIRQ_PRE_RELEASE_VERSION}'" THIS_DATE_EPOCH=$(git log -1 --pretty="%ct") - out_dir="${PWD}/dist" - out_dir_last="${PWD}/dist-last" + out_dir="${HOME}/cirq-dist" + out_dir_last="${HOME}/cirq-dist-last" dev_tools/packaging/produce-package.sh "${out_dir}" "${CIRQ_PRE_RELEASE_VERSION}" # disregard errors from building wheels at the previous commit SOURCE_DATE_EPOCH=${THIS_DATE_EPOCH} dev_tools/packaging/produce-package.sh \ From 57a2bdc1f9eb5964cf4bb610d79e1e20d90c74e4 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Tue, 4 Nov 2025 15:20:11 -0800 Subject: [PATCH 08/13] Another message tweak --- .github/workflows/release-main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-main.yml b/.github/workflows/release-main.yml index be56f66a0e3..31cb714db85 100644 --- a/.github/workflows/release-main.yml +++ b/.github/workflows/release-main.yml @@ -56,8 +56,8 @@ jobs: if diff -q -r "${out_dir_last}" "${out_dir}"; then echo "Wheels are identical - skipping the release" echo "### Skipped identical release" >> ${GITHUB_STEP_SUMMARY} - echo "Cirq release wheels for ${CIRQ_PRE_RELEASE_VERSION} (${GITHUB_SHA:0:10})" \ - "are identical to their build at previous commit." >> ${GITHUB_STEP_SUMMARY} + echo "Cirq wheels for ${CIRQ_PRE_RELEASE_VERSION} (${GITHUB_SHA})" \ + "are identical to their build at the previous commit." >> ${GITHUB_STEP_SUMMARY} exit 0 fi echo "Deploying dev version '$CIRQ_PRE_RELEASE_VERSION'" From 9b1fa61189ddf432ab6f8751a9fa9c1d86a61dbe Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Tue, 4 Nov 2025 15:22:01 -0800 Subject: [PATCH 09/13] REVERT ME - change Python file so release wheel changes as well --- cirq-core/cirq/_version.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cirq-core/cirq/_version.py b/cirq-core/cirq/_version.py index 7a1fb81f213..8a618dd357f 100644 --- a/cirq-core/cirq/_version.py +++ b/cirq-core/cirq/_version.py @@ -28,4 +28,5 @@ 'of Cirq (e.g. "python -m pip install cirq==1.5.0")' ) +# FIXME - temporary comment __version__ = "1.7.0.dev0" From 5dd5c5d9a34af473bcff5d0633315c7eb2ef8869 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Tue, 4 Nov 2025 15:26:27 -0800 Subject: [PATCH 10/13] Revert "REVERT ME - change Python file so release wheel changes as well" This reverts commit 9b1fa61189ddf432ab6f8751a9fa9c1d86a61dbe. --- cirq-core/cirq/_version.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cirq-core/cirq/_version.py b/cirq-core/cirq/_version.py index 8a618dd357f..7a1fb81f213 100644 --- a/cirq-core/cirq/_version.py +++ b/cirq-core/cirq/_version.py @@ -28,5 +28,4 @@ 'of Cirq (e.g. "python -m pip install cirq==1.5.0")' ) -# FIXME - temporary comment __version__ = "1.7.0.dev0" From 87487a03354d831d9195d1a42cc26b0f09ef2a8c Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Tue, 4 Nov 2025 15:26:38 -0800 Subject: [PATCH 11/13] Revert "REVERT ME - temporarily activate release-main in pull requests" This reverts commit fa2ebd216d0b5bbcafb04d3e1b65cdee0217d44d. --- .github/workflows/release-main.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/release-main.yml b/.github/workflows/release-main.yml index 31cb714db85..ec9a2106c0b 100644 --- a/.github/workflows/release-main.yml +++ b/.github/workflows/release-main.yml @@ -4,10 +4,6 @@ on: push: branches: - main - # FIXME - for PR testing only, remove before merge - pull_request: - branches: - - main # Declare default permissions as read only. permissions: read-all @@ -61,4 +57,4 @@ jobs: exit 0 fi echo "Deploying dev version '$CIRQ_PRE_RELEASE_VERSION'" - echo "[would execute]" twine upload "${out_dir}/*" + twine upload "${out_dir}/*" From 3cf278f0a93f96d34b115b12f1251e1abffdb10a Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Tue, 4 Nov 2025 15:42:19 -0800 Subject: [PATCH 12/13] Log message tweak --- .github/workflows/release-main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-main.yml b/.github/workflows/release-main.yml index ec9a2106c0b..2987e2e5c90 100644 --- a/.github/workflows/release-main.yml +++ b/.github/workflows/release-main.yml @@ -48,7 +48,7 @@ jobs: # disregard errors from building wheels at the previous commit SOURCE_DATE_EPOCH=${THIS_DATE_EPOCH} dev_tools/packaging/produce-package.sh \ --commit="HEAD~1" "${out_dir_last}" "${CIRQ_PRE_RELEASE_VERSION}" || true - echo "Comparing wheels with the previous version" + echo "Comparing wheels with the build at previous commit" if diff -q -r "${out_dir_last}" "${out_dir}"; then echo "Wheels are identical - skipping the release" echo "### Skipped identical release" >> ${GITHUB_STEP_SUMMARY} From 098bca4a7d3071e75d05536c51751417805146f6 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Wed, 5 Nov 2025 17:27:02 -0800 Subject: [PATCH 13/13] Fix Python capitalization in log message Co-authored-by: Michael Hucka --- dev_tools/packaging/produce-package.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev_tools/packaging/produce-package.sh b/dev_tools/packaging/produce-package.sh index 66c6d9b1a0a..6b2fde3fca8 100755 --- a/dev_tools/packaging/produce-package.sh +++ b/dev_tools/packaging/produce-package.sh @@ -110,7 +110,7 @@ if [[ -n "${specified_version}" ]]; then fi # Python 3 wheel. -echo "Producing python 3 package files." +echo "Producing Python 3 package files." # Reuse SOURCE_DATE_EPOCH if specified in the caller environment date_epoch=${SOURCE_DATE_EPOCH:-$(git log -1 --pretty="%ct")}