-
Notifications
You must be signed in to change notification settings - Fork 5
140 lines (118 loc) · 3.94 KB
/
Copy pathpython-publish.yml
File metadata and controls
140 lines (118 loc) · 3.94 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
name: Upload Python Package
on:
release:
types: [ created ]
jobs:
setup:
runs-on: ubuntu-latest
outputs:
python-version: ${{ steps.extract.outputs.version }}
python-short: ${{ steps.extract.outputs.short }}
steps:
- uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Extract Python version info
id: extract
run: |
PYTHON_CODE=$(cat <<EOF
import tomllib
with open('pyproject.toml', 'rb') as f:
data = tomllib.load(f)
req = data['project']['requires-python'].replace('>=', '').strip()
print(f"version={req}")
print(f"short={req.replace('.', '')}")
EOF
)
python3 -c "$PYTHON_CODE" >> "$GITHUB_OUTPUT"
update_version:
needs: setup
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
new-sha: ${{ steps.get-sha.outputs.sha }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.release.target_commitish }}
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Set Release version
run: uv version ${{ github.event.release.tag_name }}
- name: Commit and push changes
id: get-sha
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add pyproject.toml
git commit -m "chore: bump version to ${{ github.event.release.tag_name }}"
git push
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
build_sdist:
needs: [ setup, update_version ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.update_version.outputs.new-sha }}
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: ${{ needs.setup.outputs.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Build sdist
run: uv build --sdist
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz
build_wheels:
needs: [ setup, update_version ]
name: Build wheels on ${{ matrix.os }} for Python ${{ needs.setup.outputs.python-version }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.update_version.outputs.new-sha }}
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: ${{ needs.setup.outputs.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Build wheels via cibuildwheel
uses: pypa/cibuildwheel@v3.4.1
env:
CIBW_BUILD_FRONTEND: "uv"
CIBW_BUILD: "cp${{ needs.setup.outputs.python-short }}-*"
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}-${{ needs.setup.outputs.python-version }}
path: ./wheelhouse/*.whl
publish:
name: Publish to PyPI
needs: [ build_wheels, build_sdist ]
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Download sdist and wheels
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1