From 215e71302f3bbc410a35c35d221ad5cb750dbe80 Mon Sep 17 00:00:00 2001 From: alonsopf89 Date: Wed, 11 Nov 2026 18:51:14 +0000 Subject: [PATCH 1/4] ci(release): migrate PyPI publishing to OSS Exit Gate --- .github/workflows/pypi-publish.yml | 49 +++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml index 5828639..3f613f3 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -7,10 +7,13 @@ on: jobs: deploy: runs-on: ubuntu-latest + permissions: + contents: read + id-token: write steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1 with: python-version: '3.x' - name: Install dependencies @@ -26,10 +29,42 @@ jobs: then echo "package ver. ($PACKAGE_VER) != release ver. ($RELEASE_VER)"; exit 1 fi - - name: Build and publish - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + - name: Build run: | python -m build - twine upload dist/* + - 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="dm-pix--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="dm-pix--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/dm-pix--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/dm-pix/pypi/manifests/manifest-${RUN_ID}-${RUN_ATTEMPT}.json" \ No newline at end of file From 802d2457e1a47f9cefa388770ec12121de77e9d1 Mon Sep 17 00:00:00 2001 From: Fernando Alonso Date: Wed, 18 Nov 2026 20:47:43 +0000 Subject: [PATCH 2/4] 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 3f613f3..0ce91ba 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -38,22 +38,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="dm-pix--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="dm-pix--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=dm-pix--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=dm-pix--pypi", "--quiet" + ], check=False) + PY - name: Stage distributions to OSS Exit Gate and upload manifest env: RUN_ID: ${{ github.run_id }} From 158b25facaf60fb3b8abc50bac59cc94958d8b0d Mon Sep 17 00:00:00 2001 From: alonsopf89 Date: Thu, 19 Nov 2026 20:21:57 +0000 Subject: [PATCH 3/4] 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 0ce91ba..e53c72a 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -33,11 +33,11 @@ jobs: run: | 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' From f48d2d4c73424313f381ef9bf694ba929fadd02a Mon Sep 17 00:00:00 2001 From: Fernando Alonso Date: Mon, 23 Nov 2026 17:39:12 +0000 Subject: [PATCH 4/4] ci(release): mask OAuth token and scope manifest to publish_all=false --- .github/workflows/pypi-publish.yml | 39 ++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml index e53c72a..8cb97ac 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -75,11 +75,46 @@ jobs: RUN_ATTEMPT: ${{ github.run_attempt }} run: | python -m pip install --upgrade twine + TWINE_PASSWORD="$(gcloud auth print-access-token)" + echo "::add-mask::${TWINE_PASSWORD}" python -m twine upload \ --repository-url "https://us-python.pkg.dev/oss-exit-gate-prod/dm-pix--pypi/" \ -u oauth2accesstoken \ - -p "$(gcloud auth print-access-token)" \ + -p "${TWINE_PASSWORD}" \ dist/* - echo '{"publish_all": true}' > manifest.json + python3 - dist/* <<'PY' + import email, json, re, sys, tarfile, zipfile + pairs = set() + for path in sys.argv[1:]: + if path.endswith(".whl"): + with zipfile.ZipFile(path) as zf: + for name in zf.namelist(): + if name.endswith(".dist-info/METADATA"): + msg = email.message_from_bytes(zf.read(name)) + pkg = re.sub(r"[-_.]+", "-", msg["Name"].strip()).lower() + pairs.add((pkg, msg["Version"].strip())) + break + elif path.endswith(".tar.gz"): + with tarfile.open(path, "r:gz") as tf: + for member in tf.getmembers(): + if member.name.endswith("/PKG-INFO") and member.name.count("/") == 1: + f = tf.extractfile(member) + if f is not None: + msg = email.message_from_bytes(f.read()) + pkg = re.sub(r"[-_.]+", "-", msg["Name"].strip()).lower() + pairs.add((pkg, msg["Version"].strip())) + break + if not pairs: + raise SystemExit("ERROR: No .whl/.tar.gz package metadata found for manifest.json") + manifest = { + "publish_all": False, + "publishing_groups": [{ + "packages": [{"name": pkg, "version": ver} for pkg, ver in sorted(pairs)] + }], + } + with open("manifest.json", "w", encoding="utf-8") as fh: + json.dump(manifest, fh, indent=2) + fh.write("\n") + PY gcloud storage cp manifest.json \ "gs://oss-exit-gate-prod-projects-bucket/dm-pix/pypi/manifests/manifest-${RUN_ID}-${RUN_ATTEMPT}.json" \ No newline at end of file