main
yaml 106 lines 4.08 KB
Raw
1 # Cloud Build pipeline triggered on git tag push.
2 #
3 # Builds an sdist + wheel for google-colab-cli using `uv build`, then publishes
4 # both to the OSS Exit Gate Artifact Registry repository:
5 # https://us-python.pkg.dev/oss-exit-gate-prod/google-colab-cli--pypi
6 # and triggers an Exit Gate release by uploading a manifest to:
7 # gs://oss-exit-gate-prod-projects-bucket/google-colab-cli/pypi/manifests/
8 #
9 # OSS Exit Gate consumes the artifacts from AR and publishes them to PyPI under
10 # the google-colab-cli project. See go/oss-exit-gate-release-python.
11 #
12 # The build runs against the tagged commit (TAG_NAME is set by the trigger).
13 # Version is derived from the git tag by hatch-vcs, so the checkout must have
14 # tags available (Cloud Build's default GitHub checkout includes them).
15 #
16 # Trigger: GitHub push to refs/tags/v* on googlecolab/google-colab-cli (main).
17 substitutions:
18 _AR_LOCATION: us
19 _AR_REPOSITORY: google-colab-cli--pypi
20 _AR_PROJECT: oss-exit-gate-prod
21 _EG_PROJECT_NAME: google-colab-cli
22 _EG_REGISTRY: pypi
23 _EG_TRIGGER_BUCKET: oss-exit-gate-prod-projects-bucket
24
25 steps:
26 # 1. Ensure hatch-vcs sees the tag. Cloud Build's default GitHub checkout
27 # is shallow and may omit tag refs; unshallow + force-fetch tags so
28 # `git describe` returns the clean tag (e.g. v0.5.5 -> 0.5.5) rather
29 # than a dev-suffixed pseudo-version.
30 - id: show-version
31 name: gcr.io/cloud-builders/git
32 entrypoint: bash
33 args:
34 - -c
35 - |
36 set -e
37 git fetch --tags --force --unshallow 2>/dev/null || git fetch --tags --force
38 echo "TAG_NAME=${TAG_NAME}"
39 echo "git describe: $(git describe --tags --always)"
40
41 # 2. Build sdist + wheel into dist/ using uv.
42 # Use the non-slim bookworm variant: hatch-vcs derives the version
43 # by shelling out to `git describe`, which requires a git binary
44 # in the build container. The -slim variant omits git and breaks
45 # the build with a setuptools-scm "not a git repository" error.
46 - id: build
47 name: ghcr.io/astral-sh/uv:python3.13-bookworm
48 entrypoint: bash
49 args:
50 - -c
51 - |
52 set -e
53 uv build
54 ls -la dist/
55
56 # 3. Publish artifacts to the OSS Exit Gate AR repository via twine + the
57 # google-artifactregistry-auth keyring plugin (uses ADC from the
58 # Cloud Build service account, which is registered as a builder in
59 # the project's project.txtpb).
60 - id: publish-to-ar
61 name: python:3.13-slim
62 entrypoint: bash
63 args:
64 - -c
65 - |
66 set -e
67 pip install --quiet --root-user-action=ignore \
68 twine keyrings.google-artifactregistry-auth
69 twine upload \
70 --repository-url "https://${_AR_LOCATION}-python.pkg.dev/${_AR_PROJECT}/${_AR_REPOSITORY}/" \
71 --verbose \
72 dist/*
73
74 # 4. Trigger the OSS Exit Gate release by uploading a manifest file to the
75 # project's GCS trigger bucket. `publish_all: true` tells the Exit Gate to
76 # publish every artifact currently in our AR repo, which is correct here
77 # because the trigger fires on a single tag push and only the artifacts
78 # for that tag are in AR at this moment (Exit Gate auto-cleans on success).
79 #
80 # Note: this step runs in the same Cloud Build as the AR upload. This is
81 # fine for BCID L0 (no attestations). When/if we move to BCID L1+ this
82 # must be split into a separate build that fires after this one succeeds;
83 # see go/oss-exit-gate-faq#why-manifest.
84 - id: trigger-release
85 name: gcr.io/google.com/cloudsdktool/cloud-sdk:slim
86 entrypoint: bash
87 args:
88 - -c
89 - |
90 set -e
91 MANIFEST="${_EG_PROJECT_NAME}-${TAG_NAME}.json"
92 echo '{"publish_all": true}' > "$${MANIFEST}"
93 echo "Manifest contents:"
94 cat "$${MANIFEST}"
95 gcloud storage cp "$${MANIFEST}" \
96 "gs://${_EG_TRIGGER_BUCKET}/${_EG_PROJECT_NAME}/${_EG_REGISTRY}/manifests/$${MANIFEST}"
97
98 # Surface the built artifacts in the Cloud Build UI / logs.
99 artifacts:
100 objects:
101 location: gs://${PROJECT_ID}_cloudbuild/google-colab-cli/${TAG_NAME}
102 paths:
103 - dist/*
104
105 options:
106 logging: CLOUD_LOGGING_ONLY