-
-
Notifications
You must be signed in to change notification settings - Fork 0
55 lines (45 loc) · 1.47 KB
/
python-publish.yml
File metadata and controls
55 lines (45 loc) · 1.47 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
# This workflow will upload a Python Package to PyPI when a release is created
name: Upload Python Package
on:
release:
types: [published]
permissions:
contents: read
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Set version from tag
run: |
# Extract tag name without 'v' prefix if present
VERSION=${GITHUB_REF#refs/tags/}
VERSION=${VERSION#v}
# Update version in setup.py, pyproject.toml or __init__.py
if [ -f "setup.py" ]; then
sed -i "s/version=['\"][^'\"]*['\"]/version='${VERSION}'/g" setup.py
fi
if [ -f "pyproject.toml" ]; then
sed -i "s/version = \"[^\"]*\"/version = \"${VERSION}\"/g" pyproject.toml
fi
if [ -f "__init__.py" ]; then
sed -i "s/__version__ = ['\"][^'\"]*['\"]/__version__ = '${VERSION}'/g" __init__.py
fi
- name: Build package
run: python -m build
- name: Check package
run: twine check dist/*
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
verify-metadata: true