-
Notifications
You must be signed in to change notification settings - Fork 4
95 lines (80 loc) · 2.68 KB
/
Copy pathpublish.yml
File metadata and controls
95 lines (80 loc) · 2.68 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
87
88
89
90
91
92
93
94
95
name: Publish Package
on:
push:
tags: ['v*'] # Triggers on any tag push
release:
types: [published] # Triggers when a GitHub release is published
workflow_dispatch: # Manual trigger
permissions:
contents: read
jobs:
publish:
name: Build and Publish to PyPI
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Install build tools
run: pip install --upgrade build setuptools wheel setuptools-scm twine
- name: Extract version
id: get_version
env:
EVENT_NAME: ${{ github.event_name }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
REF_NAME: ${{ github.ref_name }}
run: |
# Get clean version from the tag or release
if [[ "$EVENT_NAME" == "release" ]]; then
# For releases, get the version from the release tag
TAG_NAME="$RELEASE_TAG"
else
# For tags, get version from the tag
TAG_NAME="$REF_NAME"
fi
# Remove 'v' prefix
VERSION=$(echo $TAG_NAME | sed 's/^v//')
# Check if this is a stable version (no rc, alpha, beta, dev, etc.)
if [[ $TAG_NAME =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "IS_STABLE=true" >> $GITHUB_ENV
else
echo "IS_STABLE=false" >> $GITHUB_ENV
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Build package
run: |
# Force clean version
export SETUPTOOLS_SCM_PRETEND_VERSION=$VERSION
pip install build
python -m build
- name: Check dist
run: |
ls -alh
twine check dist/*
- name: Verify wheel contents
run: |
unzip -l dist/*.whl
# Always publish to TestPyPI for all tags and releases
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
skip-existing: true
verbose: true
#
- name: Publish to PyPI
# TODO: Enable '&& env.IS_STABLE == 'true' only publish to PyPI for stable GitHub releases (no RC/alpha/beta)
if: github.event_name == 'release' #&& env.IS_STABLE == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
verbose: true