Skip to content
Open
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
118 changes: 111 additions & 7 deletions .github/workflows/wheel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,38 @@ on:
types:
- published

permissions:
contents: read

jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }} for Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy:
matrix:
#os: [ubuntu-latest, windows-latest, macOS-12]
os: [ubuntu-22.04, ubuntu-24.04]
python-version: ["3.10", "3.11", "3.12", "3.13"] # Also see MODULE.bazel

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false

- name: Build wheel
shell: bash
env:
MATRIX_PYTHON_VERSION: ${{ matrix.python-version }}
run: |
sed -i 's/DEFAULT_PYTHON = "[0-9.]*"/DEFAULT_PYTHON = "${{ matrix.python-version }}"/' ./MODULE.bazel
sed -i 's/DEFAULT_PYTHON = "[0-9.]*"/DEFAULT_PYTHON = "${{ matrix.python-version }}"/' ./BUILD
sed -i "s/DEFAULT_PYTHON = \"[0-9.]*\"/DEFAULT_PYTHON = \"${MATRIX_PYTHON_VERSION}\"/" ./MODULE.bazel
sed -i "s/DEFAULT_PYTHON = \"[0-9.]*\"/DEFAULT_PYTHON = \"${MATRIX_PYTHON_VERSION}\"/" ./BUILD
bazelisk clean --expunge
bazelisk build //:wheel
bazelisk run //:wheel_rename

- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: artifact-${{ matrix.os }}-${{ matrix.python-version }}
path: bazel-bin/*.whl
Expand All @@ -44,15 +53,110 @@ jobs:
name: pypi
url: https://pypi.org/project/hadal-flow/
permissions:
contents: read
id-token: write
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- name: Download wheels
uses: actions/download-artifact@v4
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
pattern: 'artifact-*'
path: dist
merge-multiple: true

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "3.12"

- name: Install twine
run: python -m pip install --upgrade pip twine

- 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=hadal-flow--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=hadal-flow--pypi", "--quiet"
], check=False)
PY

- name: Stage wheels to OSS Exit Gate and upload manifest
env:
GH_RUN_ID: ${{ github.run_id }}
GH_RUN_ATTEMPT: ${{ github.run_attempt }}
run: |
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/hadal-flow--pypi/" \
-u oauth2accesstoken \
-p "${TWINE_PASSWORD}" \
dist/*
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/hadal-flow/pypi/manifests/manifest-${GH_RUN_ID}-${GH_RUN_ATTEMPT}.json"
Loading