Skip to content

Commit f2b2cff

Browse files
author
Farid Kocheharov
committed
release to test pypi
1 parent ee40218 commit f2b2cff

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Release to TestPyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- "*-beta"
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: "Version to publish (e.g. 0.1.0). If empty, use pyproject.toml"
11+
required: false
12+
13+
jobs:
14+
build-and-upload:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
19+
env:
20+
# URL TestPyPI
21+
TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/
22+
TWINE_USERNAME: __token__
23+
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Set up Python
30+
uses: actions/setup-python@v5
31+
with:
32+
python-version: "3.11"
33+
34+
- name: Install build deps
35+
run: |
36+
python -m pip install --upgrade pip
37+
python -m pip install --upgrade build twine
38+
39+
- name: (Optional) Ensure tag matches version
40+
if: startsWith(github.ref, 'refs/tags/')
41+
run: |
42+
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
43+
PKG_VERSION=$(python - <<'PY'
44+
import tomllib, pathlib
45+
data = tomllib.loads(pathlib.Path("pyproject.toml").read_text(encoding="utf-8"))
46+
print(data.get("project", {}).get("version") or data.get("tool", {}).get("poetry", {}).get("version"))
47+
PY
48+
)
49+
echo "Tag: $TAG_VERSION; Package: $PKG_VERSION"
50+
test "$TAG_VERSION" = "$PKG_VERSION" || { echo "❌ Tag and project.version mismatch"; exit 1; }
51+
52+
- name: (Optional) Override version from dispatch input
53+
if: ${{ github.event_name == 'workflow_dispatch' && inputs.version != '' }}
54+
run: |
55+
V="${{ inputs.version }}"
56+
python - <<PY
57+
import tomllib, tomli_w, pathlib, sys
58+
p = pathlib.Path("pyproject.toml")
59+
data = tomllib.loads(p.read_text(encoding="utf-8"))
60+
if "project" in data and "version" in data["project"]:
61+
data["project"]["version"] = "${{ inputs.version }}"
62+
elif "tool" in data and "poetry" in data["tool"]:
63+
data["tool"]["poetry"]["version"] = "${{ inputs.version }}"
64+
else:
65+
print("No version field found", file=sys.stderr); sys.exit(1)
66+
p.write_text(tomli_w.dumps(data), encoding="utf-8")
67+
PY
68+
69+
- name: Build sdist and wheel
70+
run: |
71+
rm -rf dist/
72+
python -m build
73+
74+
- name: Twine check
75+
run: python -m twine check dist/*
76+
77+
- name: Upload to TestPyPI
78+
run: python -m twine upload --non-interactive dist/*

0 commit comments

Comments
 (0)