-
Notifications
You must be signed in to change notification settings - Fork 0
50 lines (42 loc) · 1.32 KB
/
publish.yml
File metadata and controls
50 lines (42 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
name: Publish to PyPI
on:
push:
tags:
- "v*"
workflow_dispatch:
permissions:
contents: read
id-token: write
jobs:
publish:
runs-on: ubuntu-latest
environment: release
env:
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Verify tag matches package version
if: startsWith(github.ref, 'refs/tags/v')
run: |
TAG_VERSION="${GITHUB_REF_NAME#v}"
PACKAGE_VERSION="$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")"
if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then
echo "Tag version ($TAG_VERSION) does not match package version ($PACKAGE_VERSION)."
exit 1
fi
- name: Build distributions
run: |
python -m pip install -U pip build
python -m build
- name: Publish to PyPI (API token)
if: env.PYPI_API_TOKEN != ''
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ env.PYPI_API_TOKEN }}
- name: Publish to PyPI (trusted publisher)
if: env.PYPI_API_TOKEN == ''
uses: pypa/gh-action-pypi-publish@release/v1