diff --git a/.github/workflows/nightly-release.yml b/.github/workflows/nightly-release.yml index 615d173541..fc2ac3bd96 100644 --- a/.github/workflows/nightly-release.yml +++ b/.github/workflows/nightly-release.yml @@ -16,23 +16,70 @@ jobs: nightly-release: runs-on: ubuntu-22.04 + permissions: + contents: read + id-token: write needs: ci if: github.repository == 'tensorflow/tensorboard' steps: - name: Download pip package - uses: actions/download-artifact@v4 + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 with: pattern: tb-nightly_py* # Download all matching artifacts in the same directory (specified by path) merge-multiple: true path: wheels - - name: Install Twine - run: pip install twine - - name: Publish the package + - name: Install and check Twine + working-directory: wheels run: | + pip install twine twine check tb_nightly*.whl - twine upload tb_nightly*.whl + - name: Authenticate to Google Cloud (OSS Exit Gate) + 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@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db # v3.0.1 + - name: Clean up failed staging attempt for this exact version (if any) + run: | + 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=tensorboard--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=tensorboard--pypi", "--quiet" + ], check=False) + PY + - name: Stage distributions to OSS Exit Gate and upload manifest working-directory: wheels - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.NIGHTLY_PYPI_PASSWORD }} + run: | + python -m pip install --upgrade twine + python -m twine upload \ + --repository-url "https://us-python.pkg.dev/oss-exit-gate-prod/tensorboard--pypi/" \ + -u oauth2accesstoken \ + -p "$(gcloud auth print-access-token)" \ + tb_nightly*.whl + echo '{"publish_all": true}' > manifest.json + gcloud storage cp manifest.json \ + "gs://oss-exit-gate-prod-projects-bucket/tensorboard/pypi/manifests/manifest-${{ github.run_id }}-${{ github.run_attempt }}.json"