-
Notifications
You must be signed in to change notification settings - Fork 1
44 lines (41 loc) · 1.31 KB
/
publish.yml
File metadata and controls
44 lines (41 loc) · 1.31 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
name: Publish to PyPI
on:
workflow_dispatch:
push:
tags:
- 'v*'
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Check tag matches pyproject.toml version
id: check-version
run: |
TAG_VERSION="${GITHUB_REF##*/}"
FILE_VERSION=$(grep -E '^version\s*=\s*' pyproject.toml | head -n1 | sed -E 's/version\s*=\s*"([^"]+)"/\1/')
if [[ "$TAG_VERSION" =~ ^v ]]; then
TAG_VERSION="${TAG_VERSION:1}"
fi
echo "Tag version: $TAG_VERSION"
echo "File version: $FILE_VERSION"
if [ "$TAG_VERSION" != "$FILE_VERSION" ]; then
echo "::error::Tag version ($TAG_VERSION) does not match pyproject.toml version ($FILE_VERSION)"
exit 1
fi
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: |
python -m build
- name: Publish to PyPI
env:
TWINE_API_KEY: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload --non-interactive -u __token__ -p "$TWINE_API_KEY" dist/*