|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | +set -x # Echo commands for build transparency in Kokoro logs |
| 4 | + |
| 5 | +# ----------------------------------------------------------------------------- |
| 6 | +# 1. Workspace & Directory Resolution |
| 7 | +# ----------------------------------------------------------------------------- |
| 8 | +# Navigate to the root of the repository |
| 9 | +REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 10 | +cd "${REPO_DIR}" |
| 11 | + |
| 12 | +echo "=== Building and Releasing from: ${REPO_DIR} ===" |
| 13 | + |
| 14 | +# ----------------------------------------------------------------------------- |
| 15 | +# 2. Environment & Tooling Setup |
| 16 | +# ----------------------------------------------------------------------------- |
| 17 | +# Upgrade pip and install standard Python build and packaging tools |
| 18 | +python3 -m pip install --upgrade pip |
| 19 | +python3 -m pip install --upgrade \ |
| 20 | + build \ |
| 21 | + twine \ |
| 22 | + keyrings.google-artifactregistry-auth |
| 23 | + |
| 24 | +# ----------------------------------------------------------------------------- |
| 25 | +# 3. Clean and Build Distribution Packages |
| 26 | +# ----------------------------------------------------------------------------- |
| 27 | +echo "=== Cleaning previous build artifacts ===" |
| 28 | +rm -rf dist/ build/ *.egg-info |
| 29 | + |
| 30 | +echo "=== Building sdist and wheel ===" |
| 31 | +python3 -m build |
| 32 | + |
| 33 | +echo "=== Validating built packages with twine ===" |
| 34 | +twine --version |
| 35 | +twine check dist/* |
| 36 | + |
| 37 | +# ----------------------------------------------------------------------------- |
| 38 | +# 4. Upload to Internal Exit Gate Artifact Registry |
| 39 | +# ----------------------------------------------------------------------------- |
| 40 | +# keyrings.google-artifactregistry-auth automatically handles authentication |
| 41 | +# using the ambient Kokoro BYOSA Service Account. |
| 42 | +EXIT_GATE_REPO="https://us-python.pkg.dev/oss-exit-gate-prod/measurement-devrel--pypi" |
| 43 | + |
| 44 | +echo "=== Uploading packages to Exit Gate staging repository: ${EXIT_GATE_REPO} ===" |
| 45 | +twine upload --repository-url "${EXIT_GATE_REPO}" dist/* |
| 46 | + |
| 47 | +# ----------------------------------------------------------------------------- |
| 48 | +# 5. Trigger Exit Gate Release via GCS Manifest |
| 49 | +# ----------------------------------------------------------------------------- |
| 50 | +# If DRY_RUN is set to "true", stop here so you can verify the AR staging |
| 51 | +# without publishing to public PyPI. |
| 52 | +if [[ "${DRY_RUN:-false}" == "true" ]]; then |
| 53 | + echo "=== DRY_RUN is enabled. Skipping manifest upload to Exit Gate. ===" |
| 54 | + echo "Artifacts are staged in Artifact Registry." |
| 55 | + exit 0 |
| 56 | +fi |
| 57 | + |
| 58 | +echo "=== Creating targeted release manifest for google-ads-datamanager-util ===" |
| 59 | +cat <<EOF > manifest.json |
| 60 | +{ |
| 61 | + "publish_all": false, |
| 62 | + "publishing_groups": [ |
| 63 | + { |
| 64 | + "packages": [ |
| 65 | + { |
| 66 | + "name": "google-ads-datamanager-util" |
| 67 | + } |
| 68 | + ] |
| 69 | + } |
| 70 | + ] |
| 71 | +} |
| 72 | +EOF |
| 73 | + |
| 74 | +EXIT_GATE_BUCKET="gs://oss-exit-gate-prod-projects-bucket/measurement-devrel/pypi/manifests" |
| 75 | +MANIFEST_NAME="manifest-$(date +%Y%m%d%H%M%S).json" |
| 76 | + |
| 77 | +echo "=== Uploading manifest to ${EXIT_GATE_BUCKET}/${MANIFEST_NAME} ===" |
| 78 | +gcloud storage cp manifest.json "${EXIT_GATE_BUCKET}/${MANIFEST_NAME}" |
| 79 | + |
| 80 | +echo "=========================================================================" |
| 81 | +echo "Release successfully triggered! Exit Gate will now verify BCID and publish to PyPI." |
| 82 | +echo "=========================================================================" |
0 commit comments