11#! /bin/bash
2- echo " Cel-expr-python release build on MacOS"
3- echo " TODO(b/507567432): implement release build for MacOS."
2+ set -e
43
5- exit 0
4+ # If running locally (not on Kokoro), authenticate with gcloud.
5+ if [ -z " ${KOKORO_BUILD_ID} " ]; then
6+ if ! gcloud auth application-default print-access-token --quiet > /dev/null; then
7+ gcloud auth application-default login
8+ fi
9+ fi
10+
11+ pip install -U keyring keyrings.google-artifactregistry-auth twine cibuildwheel
12+
13+ echo " Installing CPython Mac Frameworks..."
14+ for pyver in " 3.11.9" " 3.12.4" " 3.13.0" " 3.14.3" ; do
15+ echo " Downloading and installing Python ${pyver} ..."
16+ curl -LO " https://www.python.org/ftp/python/${pyver} /python-${pyver} -macos11.pkg"
17+ sudo installer -pkg " python-${pyver} -macos11.pkg" -target /
18+ rm " python-${pyver} -macos11.pkg"
19+ done
20+
21+ REPO_DIR=$( mktemp -d)
22+ echo " Created temporary directory: ${REPO_DIR} "
23+
24+ # Ensure the temporary directory is removed on script exit
25+ trap ' echo "Cleaning up temporary directory: ${REPO_DIR}"; rm -rf "${REPO_DIR}"' EXIT
26+
27+ if [ " ${DRY_RUN} " = " true" ]; then
28+ echo " [DRY RUN] Using local Kokoro clone instead of cloning main."
29+ SRC_DIR=" $( cd " $( dirname " $0 " ) /../.." && pwd) "
30+ pushd " ${SRC_DIR} "
31+ # Get the latest tag or fallback
32+ VERSION=$( git tag --sort=-v:refname 2> /dev/null | head -n 1 || true)
33+ if [ -z " ${VERSION} " ]; then
34+ VERSION=" 0.1.2"
35+ fi
36+ popd
37+ else
38+ pushd " ${REPO_DIR} "
39+ git clone https://github.com/cel-expr/cel-python.git
40+ cd cel-python
41+ # Get the latest version tag
42+ VERSION=$( git tag --sort=-v:refname | head -n 1)
43+ SRC_DIR=" ${REPO_DIR} /cel-python"
44+ popd
45+ fi
46+
47+ # Strip initial "v" if present
48+ VERSION=${VERSION# v}
49+ echo " Building release for version: ${VERSION} "
50+
51+ TMP_DIR=$( mktemp -d)
52+ echo " Build directory: ${TMP_DIR} "
53+
54+ # Add trap cleanup for TMP_DIR as well
55+ trap ' echo "Cleaning up temporary directories: ${REPO_DIR} ${TMP_DIR}"; rm -rf "${REPO_DIR}" "${TMP_DIR}"' EXIT
56+
57+ pushd " ${TMP_DIR} "
58+
59+ cp -r " ${SRC_DIR} " /{* ,.* } . 2> /dev/null || true
60+ cp " ${SRC_DIR} " /release/* . 2> /dev/null || true
61+ rm -rf cel_expr_python/* _test.py
62+
63+ # Check if pyproject.toml exists before running sed
64+ if [ -f pyproject.toml ]; then
65+ sed -i " " " s/\$ VERSION/${VERSION} /g" pyproject.toml || sed -i " s/\$ VERSION/${VERSION} /g" pyproject.toml
66+ fi
67+
68+ echo " Running cibuildwheel: ${CIBWHEEL_BIN} "
69+ # Default CIBWHEEL_BIN if not set
70+ if [ -z " ${CIBWHEEL_BIN} " ]; then
71+ CIBWHEEL_BIN=" python3 -m cibuildwheel"
72+ fi
73+ ${CIBWHEEL_BIN} --platform macos --output-dir dist
74+
75+ if [ " ${DRY_RUN} " = " true" ]; then
76+ echo " [DRY RUN] Skipping upload to PyPI exit gate."
77+ else
78+ echo " Uploading to OSS Exit Gate for autopush to PyPI..."
79+ python3 -m twine upload --repository-url https://us-python.pkg.dev/oss-exit-gate-prod/cel-expr-python--pypi dist/*
80+ fi
81+
82+ popd
83+
84+ echo " cel-expr-python ${VERSION} built and uploaded for release by OSS Exit Gate."
0 commit comments