From 2cbf06259bfc3913b03fc1a2892bacdd9d84825a Mon Sep 17 00:00:00 2001 From: alonsopf89 Date: Wed, 11 Nov 2026 21:30:39 +0000 Subject: [PATCH 1/3] ci(release): migrate PyPI publishing to OSS Exit Gate --- .github/workflows/pypi-publish.yml | 66 ++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/pypi-publish.yml diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml new file mode 100644 index 0000000..2a578c0 --- /dev/null +++ b/.github/workflows/pypi-publish.yml @@ -0,0 +1,66 @@ +name: Publish Python Package (OSS Exit Gate) + +on: + release: + types: [published] + workflow_dispatch: + +permissions: + contents: read + +jobs: + publish-pypi: + name: Build and stage duet to OSS Exit Gate (PyPI) + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false + - name: Set up Python + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 + with: + python-version: '3.11' + - name: Build distribution packages + run: | + python -m pip install --upgrade pip build twine + python -m build + - 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 stale releases from staging repo + run: | + packages=$(gcloud artifacts packages list \ + --project="oss-exit-gate-prod" \ + --location="us" \ + --repository="duet--pypi" \ + --format="value(name)" 2>/dev/null) + echo "${packages}" | xargs -r -I {} sh -c ' + package_name=$(basename "{}") + echo "Deleting package: $package_name..." + gcloud artifacts packages delete "{}" \ + --project="oss-exit-gate-prod" \ + --location="us" \ + --repository="duet--pypi" \ + --quiet + ' + - name: Stage distributions to OSS Exit Gate and upload manifest + env: + RUN_ID: ${{ github.run_id }} + RUN_ATTEMPT: ${{ github.run_attempt }} + run: | + python -m pip install --upgrade twine + python -m twine upload \ + --repository-url "https://us-python.pkg.dev/oss-exit-gate-prod/duet--pypi/" \ + -u oauth2accesstoken \ + -p "$(gcloud auth print-access-token)" \ + dist/* + echo '{"publish_all": true}' > manifest.json + gcloud storage cp manifest.json \ + "gs://oss-exit-gate-prod-projects-bucket/duet/pypi/manifests/manifest-${RUN_ID}-${RUN_ATTEMPT}.json" From 9348530e089e27950176f605f397d0ba7cfba5d6 Mon Sep 17 00:00:00 2001 From: Fernando Alonso Date: Wed, 18 Nov 2026 20:46:41 +0000 Subject: [PATCH 2/3] fix(ci): replace package-wide staging delete with guarded version-scoped cleanup --- .github/workflows/pypi-publish.yml | 45 ++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml index 2a578c0..213f3be 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -34,22 +34,37 @@ jobs: 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 stale releases from staging repo + - name: Clean up failed staging attempt for this exact version (if any) run: | - packages=$(gcloud artifacts packages list \ - --project="oss-exit-gate-prod" \ - --location="us" \ - --repository="duet--pypi" \ - --format="value(name)" 2>/dev/null) - echo "${packages}" | xargs -r -I {} sh -c ' - package_name=$(basename "{}") - echo "Deleting package: $package_name..." - gcloud artifacts packages delete "{}" \ - --project="oss-exit-gate-prod" \ - --location="us" \ - --repository="duet--pypi" \ - --quiet - ' + python3 - <<'PY' + import email, glob, re, subprocess, tarfile, zipfile + seen = set() + for f in sorted(glob.glob("dist/**/*.whl", recursive=True) + glob.glob("dist/**/*.tar.gz", recursive=True)): + try: + if f.endswith(".whl"): + with zipfile.ZipFile(f) as zf: + meta = [n for n in zf.namelist() if n.endswith(".dist-info/METADATA")][0] + msg = email.message_from_bytes(zf.read(meta)) + else: + with tarfile.open(f) as tf: + info = [m for m in tf.getmembers() if m.name.endswith("/PKG-INFO") or m.name == "PKG-INFO"][0] + msg = email.message_from_bytes(tf.extractfile(info).read()) + pkg = re.sub(r"[-_.]+", "-", msg["Name"].strip()).lower() + ver = msg["Version"].strip() + except Exception: + continue + if (pkg, ver) in seen: + continue + seen.add((pkg, ver)) + if subprocess.run([ + "gcloud", "artifacts", "versions", "describe", ver, + f"--package={pkg}", "--project=oss-exit-gate-prod", "--location=us", "--repository=duet--pypi" + ], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0: + subprocess.run([ + "gcloud", "artifacts", "versions", "delete", ver, + f"--package={pkg}", "--project=oss-exit-gate-prod", "--location=us", "--repository=duet--pypi", "--quiet" + ], check=False) + PY - name: Stage distributions to OSS Exit Gate and upload manifest env: RUN_ID: ${{ github.run_id }} From 43ec1d0b59e93128c2812ddcfdce9b8bb43ade49 Mon Sep 17 00:00:00 2001 From: alonsopf89 Date: Thu, 19 Nov 2026 20:22:27 +0000 Subject: [PATCH 3/3] chore: upgrade google-github-actions/auth and setup-gcloud to v3 --- .github/workflows/pypi-publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml index 213f3be..e4369c9 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -29,11 +29,11 @@ jobs: python -m pip install --upgrade pip build twine python -m build - name: Authenticate to Google Cloud (OSS Exit Gate) - uses: google-github-actions/auth@c200f3691d83b41bf9bbd8638997a462592937ed # v2.1.13 + uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3.0.0 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 + uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db # v3.0.1 - name: Clean up failed staging attempt for this exact version (if any) run: | python3 - <<'PY'