Skip to content

Commit 9b6d907

Browse files
committed
Add CI and release workflows for building and publishing Python packages
1 parent 0ae1401 commit 9b6d907

3 files changed

Lines changed: 271 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
check:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Install Rust toolchain
18+
uses: actions-rust-lang/setup-rust-toolchain@v1
19+
with:
20+
cache-workspaces: rust
21+
22+
- name: Install uv
23+
uses: astral-sh/setup-uv@v5
24+
25+
- name: Build
26+
run: uv sync --group dev
27+
28+
- name: Lint (ruff)
29+
run: uvx ruff check .
30+
31+
- name: Format (ruff)
32+
run: uvx ruff format --check .
33+
34+
- name: Type check (ty)
35+
run: uv run ty check
36+
37+
- name: Tests (pytest)
38+
run: uv run pytest

.github/workflows/release-test.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Test Release
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
linux:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
target: [x86_64, aarch64]
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-python@v5
18+
with:
19+
python-version: 3.x
20+
- name: Build wheels
21+
uses: PyO3/maturin-action@v1
22+
with:
23+
target: ${{ matrix.target }}
24+
args: --release --out dist
25+
manylinux: auto
26+
- uses: actions/upload-artifact@v4
27+
with:
28+
name: wheels-linux-${{ matrix.target }}
29+
path: dist
30+
31+
windows:
32+
runs-on: windows-latest
33+
steps:
34+
- uses: actions/checkout@v4
35+
- uses: actions/setup-python@v5
36+
with:
37+
python-version: 3.x
38+
- name: Build wheels
39+
uses: PyO3/maturin-action@v1
40+
with:
41+
target: x64
42+
args: --release --out dist
43+
- uses: actions/upload-artifact@v4
44+
with:
45+
name: wheels-windows-x64
46+
path: dist
47+
48+
macos:
49+
runs-on: macos-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
- uses: actions/setup-python@v5
53+
with:
54+
python-version: 3.x
55+
- name: Build wheels
56+
uses: PyO3/maturin-action@v1
57+
with:
58+
target: aarch64
59+
args: --release --out dist
60+
- uses: actions/upload-artifact@v4
61+
with:
62+
name: wheels-macos-aarch64
63+
path: dist
64+
65+
sdist:
66+
runs-on: ubuntu-latest
67+
steps:
68+
- uses: actions/checkout@v4
69+
- name: Build sdist
70+
uses: PyO3/maturin-action@v1
71+
with:
72+
command: sdist
73+
args: --out dist
74+
- uses: actions/upload-artifact@v4
75+
with:
76+
name: wheels-sdist
77+
path: dist
78+
79+
publish:
80+
runs-on: ubuntu-latest
81+
needs: [linux, windows, macos, sdist]
82+
environment:
83+
name: testpypi
84+
url: https://test.pypi.org/p/cflib2
85+
permissions:
86+
id-token: write
87+
steps:
88+
- uses: actions/download-artifact@v4
89+
- name: Publish to TestPyPI
90+
uses: PyO3/maturin-action@v1
91+
with:
92+
command: upload
93+
args: --non-interactive --skip-existing --repository testpypi wheels-*/*

.github/workflows/release.yml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
draft:
7+
description: 'Create GitHub Release as draft'
8+
required: false
9+
type: boolean
10+
default: true
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
linux:
17+
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
target: [x86_64, aarch64]
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: actions/setup-python@v5
24+
with:
25+
python-version: 3.x
26+
- name: Build wheels
27+
uses: PyO3/maturin-action@v1
28+
with:
29+
target: ${{ matrix.target }}
30+
args: --release --out dist
31+
manylinux: auto
32+
- uses: actions/upload-artifact@v4
33+
with:
34+
name: wheels-linux-${{ matrix.target }}
35+
path: dist
36+
37+
windows:
38+
runs-on: windows-latest
39+
steps:
40+
- uses: actions/checkout@v4
41+
- uses: actions/setup-python@v5
42+
with:
43+
python-version: 3.x
44+
- name: Build wheels
45+
uses: PyO3/maturin-action@v1
46+
with:
47+
target: x64
48+
args: --release --out dist
49+
- uses: actions/upload-artifact@v4
50+
with:
51+
name: wheels-windows-x64
52+
path: dist
53+
54+
macos:
55+
runs-on: macos-latest
56+
steps:
57+
- uses: actions/checkout@v4
58+
- uses: actions/setup-python@v5
59+
with:
60+
python-version: 3.x
61+
- name: Build wheels
62+
uses: PyO3/maturin-action@v1
63+
with:
64+
target: aarch64
65+
args: --release --out dist
66+
- uses: actions/upload-artifact@v4
67+
with:
68+
name: wheels-macos-aarch64
69+
path: dist
70+
71+
sdist:
72+
runs-on: ubuntu-latest
73+
steps:
74+
- uses: actions/checkout@v4
75+
- name: Build sdist
76+
uses: PyO3/maturin-action@v1
77+
with:
78+
command: sdist
79+
args: --out dist
80+
- uses: actions/upload-artifact@v4
81+
with:
82+
name: wheels-sdist
83+
path: dist
84+
85+
publish-pypi:
86+
runs-on: ubuntu-latest
87+
needs: [linux, windows, macos, sdist]
88+
environment:
89+
name: pypi
90+
url: https://pypi.org/p/cflib2
91+
permissions:
92+
id-token: write
93+
steps:
94+
- uses: actions/checkout@v4
95+
with:
96+
fetch-depth: 0
97+
98+
- name: Verify commit is on main
99+
run: |
100+
git fetch origin main
101+
if ! git merge-base --is-ancestor HEAD origin/main; then
102+
echo "This workflow can only be run on a commit that is on the main branch."
103+
exit 1
104+
fi
105+
106+
- name: Check version consistency between git tag and Cargo.toml
107+
run: |
108+
TAG_VERSION=$(git describe --tags --exact-match HEAD)
109+
CARGO_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[0].version')
110+
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
111+
echo "Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
112+
exit 1
113+
fi
114+
115+
- uses: actions/download-artifact@v4
116+
117+
- name: Publish to PyPI
118+
uses: PyO3/maturin-action@v1
119+
with:
120+
command: upload
121+
args: --non-interactive --skip-existing wheels-*/*
122+
123+
github-release:
124+
runs-on: ubuntu-latest
125+
needs: publish-pypi
126+
permissions:
127+
contents: write
128+
steps:
129+
- uses: actions/checkout@v4
130+
with:
131+
fetch-depth: 0
132+
133+
- uses: actions/download-artifact@v4
134+
135+
- name: Create GitHub Release
136+
uses: softprops/action-gh-release@v2
137+
with:
138+
tag_name: ${{ github.ref_name }}
139+
draft: ${{ github.event.inputs.draft }}
140+
files: wheels-*/*

0 commit comments

Comments
 (0)