Skip to content

Commit

Permalink
Prepare for initial release on PyPI
Browse files Browse the repository at this point in the history
  • Loading branch information
millerdev committed Oct 22, 2024
1 parent 77ba590 commit 08c16ab
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Publish Python distribution to PyPI and TestPyPI
# Source:
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
on:
push:
branches:
- main
tags:
- 'v*'
jobs:
build:
name: Build distribution package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
run: python3 -m pip install build --user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
version-check:
name: Check for version match in git tag and unmagic.__version__
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pytest-unmagic
run: python3 -m pip install --user -e .
- name: Check version
run: python3 tests/version-check.py "${{ github.ref }}"
pypi-publish:
name: Upload release to PyPI
needs: [build, version-check]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
environment:
name: pypi
url: https://pypi.org/p/pytest-unmagic
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
pypi-test-publish:
name: Upload release to test PyPI
needs: [build]
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/pytest-unmagic
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__pycache__
/dist
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,14 @@ cd path/to/pytest-unmagic
pip install -e .
pytest
```


## Publishing a new verison to PyPI

Push a new tag to Github using the format vX.Y.Z where X.Y.Z matches the version
in [__init__.py](src/unmagic/__init__.py).

A new version is published to https://test.pypi.org/p/pytest-unmagic on every
push to the *main* branch.

Publishing is automated with [Github Actions](.github/workflows/pypi.yml).
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "pytest-unmagic"
authors = [{name = "Daniel Miller", email = "[email protected]"}]
license = {file = "LICENSE"}
readme = {file = "README.md", content-type = "text/markdown"}
dynamic = ["version", "description"]
requires-python = ">= 3.9"
classifiers = [
Expand All @@ -10,6 +11,10 @@ classifiers = [
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Testing",
]
Expand Down
15 changes: 15 additions & 0 deletions tests/version-check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Check for version match between github tag and __init__.py"""
import sys
import unmagic


def check(ref):
if not ref.startswith("refs/tags/v"):
sys.exit(f"Unexpected ref: {ref}")
version = ref.removeprefix("refs/tags/v")
if version != unmagic.__version__:
sys.exit(f"Version mismatch: {version} != {unmagic.__version__}")


if __name__ == "__main__":
check(sys.argv[-1])

0 comments on commit 08c16ab

Please sign in to comment.