|
1 | 1 | #!/bin/bash |
| 2 | +# Copyright 2026 Google LLC |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
2 | 16 | set -e |
3 | 17 |
|
| 18 | +# Avoid virtualenv/pip trying to download/upgrade tools from PyPI on host |
| 19 | +export VIRTUALENV_NO_DOWNLOAD=1 |
| 20 | +export PIP_DISABLE_PIP_VERSION_CHECK=1 |
| 21 | + |
| 22 | +# Pass these environment variables to the cibuildwheel Docker container |
| 23 | +export CIBW_ENVIRONMENT="VIRTUALENV_NO_DOWNLOAD=1 PIP_DISABLE_PIP_VERSION_CHECK=1" |
| 24 | +export CIBW_DEPENDENCY_VERSIONS="latest" |
| 25 | + |
4 | 26 | # If running locally (not on Kokoro), authenticate with gcloud. |
5 | 27 | if [ -z "${KOKORO_BUILD_ID}" ]; then |
6 | 28 | if ! gcloud auth application-default print-access-token --quiet > /dev/null; then |
7 | 29 | gcloud auth application-default login |
8 | 30 | fi |
9 | 31 | fi |
10 | 32 |
|
11 | | -pip install -U keyring keyrings.google-artifactregistry-auth twine cibuildwheel |
| 33 | +# We use --no-cache-dir to force pip to download packages fresh and bypass the local |
| 34 | +# cache. In Kokoro/RBE sandboxed environments, writing to the default cache directory |
| 35 | +# (~/.cache/pip) can encounter permission/sandbox restrictions or lead to stale |
| 36 | +# dependency resolution. Disabling the cache ensures a reliable, reproducible install. |
| 37 | +pip install --no-cache-dir -U keyring keyrings.google-artifactregistry-auth twine cibuildwheel |
| 38 | + |
| 39 | +REPO_DIR="" |
| 40 | +TMP_DIR="" |
| 41 | +cleanup() { |
| 42 | + echo "Cleaning up temporary directories..." |
| 43 | + [ -n "${REPO_DIR}" ] && rm -rf "${REPO_DIR}" |
| 44 | + [ -n "${TMP_DIR}" ] && rm -rf "${TMP_DIR}" |
| 45 | +} |
| 46 | +trap cleanup EXIT |
12 | 47 |
|
13 | 48 | REPO_DIR=$(mktemp -d) |
14 | 49 | echo "Created temporary directory: ${REPO_DIR}" |
15 | 50 |
|
16 | | -# Ensure the temporary directory is removed on script exit |
17 | | -trap 'echo "Cleaning up temporary directory: ${REPO_DIR}"; rm -rf "${REPO_DIR}"' EXIT |
18 | | - |
19 | 51 | if [ "${DRY_RUN}" = "true" ]; then |
20 | 52 | echo "[DRY RUN] Using local Kokoro clone instead of cloning main." |
21 | 53 | SRC_DIR="$(cd "$(dirname "$0")/../.." && pwd)" |
@@ -43,25 +75,30 @@ echo "Building release for version: ${VERSION}" |
43 | 75 | TMP_DIR=$(mktemp -d) |
44 | 76 | echo "Build directory: ${TMP_DIR}" |
45 | 77 |
|
46 | | -# Add trap cleanup for TMP_DIR as well |
47 | | -trap 'echo "Cleaning up temporary directories: ${REPO_DIR} ${TMP_DIR}"; rm -rf "${REPO_DIR}" "${TMP_DIR}"' EXIT |
48 | | - |
49 | 78 | pushd "${TMP_DIR}" |
50 | 79 |
|
51 | 80 | cp -r "${SRC_DIR}"/{*,.*} . 2>/dev/null || true |
52 | 81 | cp -r "${SRC_DIR}"/release/* . 2>/dev/null || true |
53 | 82 | rm -rf cel_expr_python/*_test.py |
54 | 83 |
|
| 84 | +echo "Downloading bazelisk on host..." |
| 85 | +curl -LO https://github.com/bazelbuild/bazelisk/releases/download/v1.19.0/bazelisk-linux-amd64 |
| 86 | +chmod +x bazelisk-linux-amd64 |
| 87 | + |
55 | 88 | # Check if pyproject.toml exists before running sed |
56 | 89 | if [ -f pyproject.toml ]; then |
57 | 90 | sed -i "" "s/\$VERSION/${VERSION}/g" pyproject.toml || sed -i "s/\$VERSION/${VERSION}/g" pyproject.toml |
58 | 91 | fi |
59 | 92 |
|
60 | | -echo "Running cibuildwheel: ${CIBWHEEL_BIN}" |
| 93 | +export CIBW_CONTAINER_ENGINE_EXTRA_ARGS="--network=host" |
| 94 | + |
| 95 | +echo "Running cibuildwheel..." |
61 | 96 | # Default CIBWHEEL_BIN if not set |
62 | 97 | if [ -z "${CIBWHEEL_BIN}" ]; then |
63 | 98 | CIBWHEEL_BIN="python3 -m cibuildwheel" |
64 | 99 | fi |
| 100 | + |
| 101 | +# Run cibuildwheel synchronously. Output goes directly to the console in real-time. |
65 | 102 | ${CIBWHEEL_BIN} --platform linux --output-dir dist |
66 | 103 |
|
67 | 104 | if [ "${DRY_RUN}" = "true" ]; then |
|
0 commit comments