Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 99 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ jobs:
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: releases
path: bazel-bin/**/*.whl
path: bazel-bin/android_env/*.whl
if-no-files-found: error

publish:
needs: build
Expand All @@ -53,5 +54,100 @@ jobs:
name: releases
path: dist

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # release/v1
- name: Set up Python
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: "3.11"

- name: Authenticate to Google Cloud (OSS Exit Gate)
uses: google-github-actions/auth@c200f3691d83b41bf9bbd8638997a462592937ed # v2.1.13
with:
workload_identity_provider: 'projects/305452601764/locations/global/workloadIdentityPools/builders/providers/github'

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@e427ad8a34f8676edf47cf7d7925499adf3eb74f # v2.2.1

- name: Clean up failed staging attempt for this exact version (if any)
id: exit_gate_cleanup
run: |
set -euo pipefail
PKG_VER=$(python3 - <<'PY'
import email, glob, tarfile, zipfile
files = sorted(
glob.glob("dist/**/*.whl", recursive=True)
+ glob.glob("dist/**/*.tar.gz", recursive=True)
)
assert files, "No built distributions found under dist/"
f = files[0]
if f.endswith(".whl"):
with zipfile.ZipFile(f) as zf:
meta = [n for n in zf.namelist() if n.endswith(".dist-info/METADATA")][0]
raw = zf.read(meta).decode()
else:
with tarfile.open(f) as tf:
pkg_info = [m for m in tf.getmembers() if m.name.endswith("/PKG-INFO")][0]
raw = tf.extractfile(pkg_info).read().decode()
print(email.message_from_string(raw)["Version"].strip())
PY
)
echo "pkg_ver=${PKG_VER}" >> "$GITHUB_OUTPUT"
set +e
gcloud artifacts versions describe "${PKG_VER}" \
--package="android-env" \
--project="oss-exit-gate-prod" \
--location="us" \
--repository="android-env--pypi" >/dev/null 2>describe.err
DESC_RC=$?
set -e
if [ "$DESC_RC" -eq 0 ]; then
echo "Deleting incomplete staged version ${PKG_VER} before retry..."
gcloud artifacts versions delete "${PKG_VER}" \
--package="android-env" \
--project="oss-exit-gate-prod" \
--location="us" \
--repository="android-env--pypi" \
--quiet
elif grep -Eqi "NOT_FOUND|not.found|404" describe.err; then
echo "Version ${PKG_VER} not present in staging repository — proceeding with fresh upload"
else
cat describe.err >&2
exit "$DESC_RC"
fi

- name: Stage distributions to OSS Exit Gate and upload manifest
env:
PKG_VER: ${{ steps.exit_gate_cleanup.outputs.pkg_ver }}
RUN_ID: ${{ github.run_id }}
RUN_ATTEMPT: ${{ github.run_attempt }}
run: |
set -euo pipefail
shopt -s globstar nullglob
DIST_FILES=(dist/**/*.whl dist/**/*.tar.gz)
if [ "${#DIST_FILES[@]}" -eq 0 ]; then
echo "No distribution files found under dist/" >&2
exit 1
fi
python3 -m pip install --upgrade twine
TWINE_PASSWORD="$(gcloud auth print-access-token)"
python3 -m twine upload \
--repository-url "https://us-python.pkg.dev/oss-exit-gate-prod/android-env--pypi/" \
-u oauth2accesstoken \
-p "${TWINE_PASSWORD}" \
"${DIST_FILES[@]}"
cat <<EOF > manifest.json
{
"publish_all": false,
"publishing_groups": [
{
"packages": [
{
"name": "android-env",
"version": "${PKG_VER}"
}
]
}
]
}
EOF
gcloud storage cp manifest.json \
"gs://oss-exit-gate-prod-projects-bucket/android-env/pypi/manifests/manifest-${PKG_VER}-${RUN_ID}-${RUN_ATTEMPT}.json"
Loading