Skip to content

Commit a3460d7

Browse files
committed
CI: add test pypi release
1 parent 644bf2c commit a3460d7

1 file changed

Lines changed: 148 additions & 0 deletions

File tree

.github/workflows/pypi-release.yml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
name: Build and Publish Python Wheels to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch: # Allow manual triggering
7+
8+
jobs:
9+
build-wheels:
10+
name: Build wheels on ${{ matrix.os }}
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, macos-latest]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
submodules: recursive
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: '3.11'
25+
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
python -m pip install cibuildwheel
30+
31+
- name: Sync Python version
32+
run: python scripts/sync_python_version.py
33+
34+
- name: Build main libCacheSim library
35+
run: |
36+
sudo apt-get update && sudo apt-get install -y cmake ninja-build libglib2.0-dev || true
37+
brew install cmake ninja glib || true
38+
rm -rf ./build
39+
cmake -G Ninja -B build
40+
ninja -C build
41+
42+
- name: Build wheels
43+
env:
44+
CIBW_SKIP: "*-musllinux* *-manylinux_i686"
45+
CIBW_ARCHS_LINUX: "x86_64"
46+
CIBW_ARCHS_MACOS: "x86_64 arm64"
47+
CIBW_BEFORE_ALL_LINUX: |
48+
yum install -y glib2-devel cmake ninja-build || \
49+
apt-get update && apt-get install -y libglib2.0-dev cmake ninja-build
50+
CIBW_BEFORE_ALL_MACOS: |
51+
brew install glib cmake ninja
52+
CIBW_TEST_COMMAND: "python -c 'import libcachesim; print(\"Import successful\")'"
53+
run: python -m cibuildwheel libCacheSim-python --output-dir wheelhouse
54+
55+
- name: Upload wheels as artifacts
56+
uses: actions/upload-artifact@v3
57+
with:
58+
name: wheels-${{ matrix.os }}
59+
path: wheelhouse/*.whl
60+
61+
build-sdist:
62+
name: Build source distribution
63+
runs-on: ubuntu-latest
64+
steps:
65+
- uses: actions/checkout@v4
66+
with:
67+
submodules: recursive
68+
69+
- name: Set up Python
70+
uses: actions/setup-python@v4
71+
with:
72+
python-version: '3.11'
73+
74+
- name: Install build dependencies
75+
run: |
76+
python -m pip install --upgrade pip
77+
python -m pip install build
78+
79+
- name: Sync Python version
80+
run: python scripts/sync_python_version.py
81+
82+
- name: Build source distribution
83+
run: python -m build --sdist libCacheSim-python --outdir dist/
84+
85+
- name: Upload sdist as artifact
86+
uses: actions/upload-artifact@v3
87+
with:
88+
name: sdist
89+
path: dist/*.tar.gz
90+
91+
publish-to-pypi:
92+
name: Publish to PyPI
93+
needs: [build-wheels, build-sdist]
94+
runs-on: ubuntu-latest
95+
if: github.event_name == 'release' && github.event.action == 'published'
96+
environment:
97+
name: pypi
98+
url: https://pypi.org/p/libcachesim
99+
permissions:
100+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
101+
102+
steps:
103+
- name: Download all artifacts
104+
uses: actions/download-artifact@v3
105+
with:
106+
path: dist/
107+
108+
- name: Flatten artifacts directory
109+
run: |
110+
mkdir -p final-dist
111+
find dist/ -name "*.whl" -exec cp {} final-dist/ \;
112+
find dist/ -name "*.tar.gz" -exec cp {} final-dist/ \;
113+
ls -la final-dist/
114+
115+
- name: Publish to PyPI
116+
uses: pypa/gh-action-pypi-publish@release/v1
117+
with:
118+
packages-dir: final-dist/
119+
skip-existing: true
120+
121+
publish-to-test-pypi:
122+
name: Publish to TestPyPI
123+
needs: [build-wheels, build-sdist]
124+
runs-on: ubuntu-latest
125+
if: github.event_name == 'workflow_dispatch'
126+
environment:
127+
name: testpypi
128+
url: https://test.pypi.org/p/libcachesim
129+
130+
steps:
131+
- name: Download all artifacts
132+
uses: actions/download-artifact@v3
133+
with:
134+
path: dist/
135+
136+
- name: Flatten artifacts directory
137+
run: |
138+
mkdir -p final-dist
139+
find dist/ -name "*.whl" -exec cp {} final-dist/ \;
140+
find dist/ -name "*.tar.gz" -exec cp {} final-dist/ \;
141+
ls -la final-dist/
142+
143+
- name: Publish to TestPyPI
144+
uses: pypa/gh-action-pypi-publish@release/v1
145+
with:
146+
repository-url: https://test.pypi.org/legacy/
147+
packages-dir: final-dist/
148+
skip-existing: true

0 commit comments

Comments
 (0)