|
52 | 52 | run: | |
53 | 53 | cli_wheel="$(echo dist/tangle_cli-*.whl)" |
54 | 54 | uv run --isolated --no-project --find-links dist --with "${cli_wheel}[native]" tangle-cli version |
| 55 | + - name: Determine packages to publish |
| 56 | + id: publish-plan |
| 57 | + run: | |
| 58 | + python - <<'PY' |
| 59 | + import json |
| 60 | + import os |
| 61 | + import urllib.error |
| 62 | + import urllib.request |
| 63 | + from pathlib import Path |
| 64 | + import tomllib |
| 65 | +
|
| 66 | + packages = [ |
| 67 | + ("tangle-cli", "pyproject.toml", "dist/tangle_cli-*", "publish_cli"), |
| 68 | + ("tangle-api", "packages/tangle-api/pyproject.toml", "dist/tangle_api-*", "publish_api"), |
| 69 | + ] |
| 70 | +
|
| 71 | + def version_exists(package: str, version: str) -> bool: |
| 72 | + url = f"https://pypi.org/pypi/{package}/json" |
| 73 | + try: |
| 74 | + with urllib.request.urlopen(url, timeout=20) as response: |
| 75 | + data = json.load(response) |
| 76 | + except urllib.error.HTTPError as error: |
| 77 | + if error.code == 404: |
| 78 | + return False |
| 79 | + raise |
| 80 | + return version in data.get("releases", {}) |
| 81 | +
|
| 82 | + github_output = Path(os.environ["GITHUB_OUTPUT"]) |
| 83 | + with github_output.open("a") as output: |
| 84 | + for package, pyproject_path, dist_glob, output_name in packages: |
| 85 | + version = tomllib.loads(Path(pyproject_path).read_text())["project"]["version"] |
| 86 | + exists = version_exists(package, version) |
| 87 | + should_publish = not exists |
| 88 | + print( |
| 89 | + f"{package} {version}: " |
| 90 | + f"{'publish ' + dist_glob if should_publish else 'skip; version already exists on PyPI'}" |
| 91 | + ) |
| 92 | + print(f"{output_name}={'true' if should_publish else 'false'}", file=output) |
| 93 | + PY |
55 | 94 | - name: Publish tangle-cli |
56 | | - run: uv publish --check-url https://pypi.org/simple/ dist/tangle_cli-* |
| 95 | + if: steps.publish-plan.outputs.publish_cli == 'true' |
| 96 | + run: uv publish dist/tangle_cli-* |
| 97 | + - name: Publish tangle-api |
| 98 | + if: steps.publish-plan.outputs.publish_api == 'true' |
| 99 | + run: uv publish dist/tangle_api-* |
0 commit comments