-
Notifications
You must be signed in to change notification settings - Fork 5
86 lines (66 loc) · 2.37 KB
/
publish.yml
File metadata and controls
86 lines (66 loc) · 2.37 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Publish to PyPI
on:
push:
tags:
- "v*" # Only run when a version tag is pushed
permissions:
contents: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies for build and publish
run: |
python -m pip install --upgrade pip
pip install build twine toml
- name: Extract version number from tag
id: get_version
run: echo "version=$(echo ${{ github.ref_name }} | sed 's/^v//')" >> $GITHUB_OUTPUT
- name: Verify all version numbers match
run: |
TAG_VERSION="${{ steps.get_version.outputs.version }}"
PYPROJECT_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
APP_VERSION=$(python -c """
import re
with open('app.py', 'r') as f:
content = f.read()
version_block = '\n'.join(
line for line in content.splitlines()
if re.match(r'^__\w+__\s*=', line)
)
version_namespace = {}
exec(version_block, version_namespace)
print(version_namespace['__version__'])
""")
echo "Tag version: $TAG_VERSION"
echo "pyproject.toml version: $PYPROJECT_VERSION"
echo "app.py version: $APP_VERSION"
if [ "$PYPROJECT_VERSION" != "$TAG_VERSION" ]; then
echo "Error: pyproject.toml version ($PYPROJECT_VERSION) does not match tag version ($TAG_VERSION)."
exit 1
fi
if [ "$APP_VERSION" != "$TAG_VERSION" ]; then
echo "Error: app.py version ($APP_VERSION) does not match tag version ($TAG_VERSION)."
exit 1
fi
echo "All versions match: $TAG_VERSION"
- name: Build package
run: python -m build
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload dist/* --verbose
- name: Create Github release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
generate_release_notes: true