Skip to content

Commit 2d1b58a

Browse files
authored
[MNT] release workflow (#672)
Adds a release workflow to PyPI, with tests gating the release.
1 parent 8d81166 commit 2d1b58a

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

.github/workflows/release.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: PyPI Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
check_tag:
9+
name: Check tag
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v5
14+
15+
- uses: actions/setup-python@v6
16+
with:
17+
python-version: '3.11'
18+
19+
- shell: bash
20+
run: |
21+
TAG="${{ github.event.release.tag_name }}"
22+
GH_TAG_NAME="${TAG#v}"
23+
PY_VERSION=$(python - <<'PY'
24+
import pathlib, tomllib
25+
data = tomllib.loads(pathlib.Path("pyproject.toml").read_text(encoding="utf-8"))
26+
print(data.get("project").get("version"))
27+
PY
28+
)
29+
if [ "${GH_TAG_NAME}" != "${PY_VERSION}" ]; then
30+
echo "::error::Tag (${GH_TAG_NAME}) does not match pyproject.toml version (${PY_VERSION})."
31+
exit 2
32+
fi
33+
34+
build_wheels:
35+
name: Build wheels
36+
runs-on: ubuntu-latest
37+
38+
steps:
39+
- uses: actions/checkout@v5
40+
41+
- uses: actions/setup-python@v6
42+
with:
43+
python-version: '3.11'
44+
45+
- name: Build wheel
46+
run: |
47+
python -m pip install build
48+
python -m build --wheel --sdist --outdir wheelhouse
49+
50+
- name: Store wheels
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: wheels
54+
path: wheelhouse/*
55+
56+
pytest-nosoftdeps:
57+
name: no-softdeps
58+
runs-on: ${{ matrix.os }}
59+
needs: [build_wheels]
60+
strategy:
61+
fail-fast: false
62+
matrix:
63+
os: [ubuntu-latest, macos-latest, windows-latest]
64+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
65+
66+
steps:
67+
- uses: actions/checkout@v5
68+
69+
- name: Set up Python ${{ matrix.python-version }}
70+
uses: actions/setup-python@v6
71+
with:
72+
python-version: ${{ matrix.python-version }}
73+
74+
- name: Setup macOS
75+
if: runner.os == 'macOS'
76+
run: |
77+
brew install libomp # https://github.com/pytorch/pytorch/issues/20030
78+
79+
- name: Get full Python version
80+
id: full-python-version
81+
shell: bash
82+
run: echo version=$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))") >> $GITHUB_OUTPUT
83+
84+
- name: Install dependencies
85+
shell: bash
86+
run: |
87+
pip install ".[dev]"
88+
89+
- name: Show dependencies
90+
run: python -m pip list
91+
92+
- name: Run pytest
93+
shell: bash
94+
run: python -m pytest tests
95+
96+
upload_wheels:
97+
name: Upload wheels to PyPI
98+
runs-on: ubuntu-latest
99+
needs: [pytest-nosoftdeps]
100+
101+
permissions:
102+
id-token: write
103+
104+
steps:
105+
- uses: actions/download-artifact@v5
106+
with:
107+
name: wheels
108+
path: wheelhouse
109+
110+
- name: Publish package to PyPI
111+
uses: pypa/gh-action-pypi-publish@release/v1
112+
with:
113+
packages-dir: wheelhouse/

0 commit comments

Comments
 (0)