Skip to content

Commit 597ed46

Browse files
committed
Prepare for initial release on PyPI
1 parent 77ba590 commit 597ed46

File tree

5 files changed

+111
-0
lines changed

5 files changed

+111
-0
lines changed

.github/workflows/pypi.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Publish Python distribution to PyPI and TestPyPI
2+
# Source:
3+
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
4+
on:
5+
push:
6+
branches:
7+
- main
8+
tags:
9+
- 'v*'
10+
jobs:
11+
build:
12+
name: Build distribution package
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.x"
20+
- name: Install pypa/build
21+
run: python3 -m pip install build --user
22+
- name: Build a binary wheel and a source tarball
23+
run: python3 -m build
24+
- name: Store the distribution packages
25+
uses: actions/upload-artifact@v4
26+
with:
27+
name: python-package-distributions
28+
path: dist/
29+
version-check:
30+
name: Check for version match in git tag and unmagic.__version__
31+
runs-on: ubuntu-latest
32+
if: startsWith(github.ref, 'refs/tags/v')
33+
steps:
34+
- uses: actions/checkout@v4
35+
- name: Set up Python
36+
uses: actions/setup-python@v5
37+
with:
38+
python-version: "3.x"
39+
- name: Install pytest-unmagic
40+
run: python3 -m pip install --user -e .
41+
- name: Check version
42+
run: python3 tests/version-check.py "${{ github.ref }}"
43+
pypi-publish:
44+
name: Upload release to PyPI
45+
needs: [build, version-check]
46+
runs-on: ubuntu-latest
47+
if: startsWith(github.ref, 'refs/tags/v')
48+
environment:
49+
name: pypi
50+
url: https://pypi.org/p/pytest-unmagic
51+
permissions:
52+
id-token: write
53+
steps:
54+
- name: Download all the dists
55+
uses: actions/download-artifact@v4
56+
with:
57+
name: python-package-distributions
58+
path: dist/
59+
- name: Publish package distributions to PyPI
60+
uses: pypa/gh-action-pypi-publish@release/v1
61+
pypi-test-publish:
62+
name: Upload release to test PyPI
63+
needs: [build]
64+
runs-on: ubuntu-latest
65+
environment:
66+
name: testpypi
67+
url: https://test.pypi.org/p/pytest-unmagic
68+
permissions:
69+
id-token: write
70+
steps:
71+
- name: Download all the dists
72+
uses: actions/download-artifact@v4
73+
with:
74+
name: python-package-distributions
75+
path: dist/
76+
- name: Publish package distributions to PyPI
77+
uses: pypa/gh-action-pypi-publish@release/v1
78+
with:
79+
repository-url: https://test.pypi.org/legacy/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
__pycache__
2+
/dist

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,14 @@ cd path/to/pytest-unmagic
193193
pip install -e .
194194
pytest
195195
```
196+
197+
198+
## Publishing a new verison to PyPI
199+
200+
Push a new tag to Github using the format vX.Y.Z where X.Y.Z matches the version
201+
in [`__init__.py`](src/unmagic/__init__.py).
202+
203+
A new version is published to https://test.pypi.org/p/pytest-unmagic on every
204+
push to the *main* branch.
205+
206+
Publishing is automated with [Github Actions](.github/workflows/pypi.yml).

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "pytest-unmagic"
33
authors = [{name = "Daniel Miller", email = "millerdev@gmail.com"}]
44
license = {file = "LICENSE"}
5+
readme = {file = "README.md", content-type = "text/markdown"}
56
dynamic = ["version", "description"]
67
requires-python = ">= 3.9"
78
classifiers = [
@@ -10,6 +11,10 @@ classifiers = [
1011
"License :: OSI Approved :: BSD License",
1112
"Programming Language :: Python :: 3",
1213
"Programming Language :: Python :: 3.9",
14+
"Programming Language :: Python :: 3.10",
15+
"Programming Language :: Python :: 3.11",
16+
"Programming Language :: Python :: 3.12",
17+
"Programming Language :: Python :: 3.13",
1318
"Topic :: Software Development :: Libraries",
1419
"Topic :: Software Development :: Testing",
1520
]

tests/version-check.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""Check for version match between github tag and __init__.py"""
2+
import sys
3+
import unmagic
4+
5+
6+
def check(ref):
7+
if not ref.startswith("refs/tags/v"):
8+
sys.exit(f"Unexpected ref: {ref}")
9+
version = ref.removeprefix("refs/tags/v")
10+
if version != unmagic.__version__:
11+
sys.exit(f"Version mismatch: {version} != {unmagic.__version__}")
12+
13+
14+
if __name__ == "__main__":
15+
check(sys.argv[-1])

0 commit comments

Comments
 (0)