Skip to content

Commit 523df21

Browse files
committed
Enable PyPI trusted publishing
1 parent d4b4f35 commit 523df21

2 files changed

Lines changed: 74 additions & 1 deletion

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Publish Python SDK
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "**"
9+
- ".github/workflows/publish-python.yml"
10+
workflow_dispatch: {}
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
id-token: write
18+
defaults:
19+
run:
20+
working-directory: .
21+
steps:
22+
- name: Check out repo
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: "3.11"
29+
30+
- name: Install build tools
31+
run: |
32+
python -m pip install --upgrade pip
33+
python -m pip install build
34+
35+
- name: Decide whether to publish
36+
id: should_publish
37+
run: |
38+
python - <<'PY'
39+
import json
40+
import os
41+
import urllib.request
42+
import tomllib
43+
from pathlib import Path
44+
45+
data = tomllib.loads(Path("pyproject.toml").read_text())
46+
name = data["project"]["name"]
47+
version = data["project"]["version"]
48+
49+
url = f"https://pypi.org/pypi/{name}/json"
50+
try:
51+
with urllib.request.urlopen(url, timeout=10) as resp:
52+
payload = json.loads(resp.read().decode("utf-8"))
53+
published = version in payload.get("releases", {})
54+
except Exception:
55+
published = False
56+
57+
output = os.environ.get("GITHUB_OUTPUT")
58+
if output:
59+
with open(output, "a", encoding="utf-8") as handle:
60+
handle.write(f"publish={'false' if published else 'true'}\n")
61+
PY
62+
63+
- name: Build
64+
if: ${{ steps.should_publish.outputs.publish == 'true' }}
65+
run: python -m build
66+
67+
- name: Publish to PyPI
68+
if: ${{ steps.should_publish.outputs.publish == 'true' }}
69+
uses: pypa/gh-action-pypi-publish@release/v1

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "diffio"
7-
version = "0.1.0"
7+
version = "0.1.1"
88
description = "Python SDK for the Diffio API."
99
readme = "README.md"
1010
requires-python = ">=3.8"
@@ -34,6 +34,10 @@ dev = [
3434
"twine>=5.0",
3535
]
3636

37+
[project.urls]
38+
Homepage = "https://diffio.ai"
39+
Repository = "https://github.com/Diffio-AI/diffio-python"
40+
3741
[tool.setuptools]
3842
package-dir = { "" = "src" }
3943

0 commit comments

Comments
 (0)