-
Notifications
You must be signed in to change notification settings - Fork 7
281 lines (255 loc) · 8.76 KB
/
build-python-wheels.yml
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# Build wheels for many platforms
# see: https://github.com/pypa/cibuildwheel
name: Build Python wheels
on:
push:
branches:
- main
paths:
- 'nlpo3-python/**'
pull_request:
branches:
- main
paths:
- 'nlpo3-python/**'
release:
types: [published]
# Manual run
workflow_dispatch:
jobs:
echo_github_env:
name: Echo GitHub environment variables
runs-on: ubuntu-latest
steps:
- run: |
echo "github.event.action : ${{ github.event.action }}"
echo "github.event_name : ${{ github.event_name }}"
echo "github.ref : ${{ github.ref }}"
echo "github.event.ref : ${{ github.event.ref }}"
echo "github.event.ref_type : ${{ github.event.ref_type }}"
# Check whether to build the wheels and the source tarball
check_build_trigger:
name: Check build trigger
runs-on: ubuntu-latest
if: github.repository == 'pythainlp/nlpo3'
outputs:
build: ${{ steps.check_build_trigger.outputs.build }}
steps:
- name: Checkout source code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- id: check_build_trigger
name: Check build trigger
run: bash build_tools/github/check_build_trigger.sh
build_wheels:
name: Build Python wheel for ${{ matrix.python }}-${{ matrix.platform_id }}-${{ matrix.manylinux_image }}
runs-on: ${{ matrix.os }}
needs: check_build_trigger
if: needs.check_build_trigger.outputs.build
strategy:
# Ensure that a wheel builder finishes even if another fails
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python: [cp36, cp37, cp38, cp39, cp310, cp311, cp312] # pp37
bitness: [32, 64]
manylinux_image: [manylinux2014]
include:
- os: macos-latest
bitness: 64
platform_id: macosx_x86_64
- os: ubuntu-latest
bitness: 64
platform_id: manylinux_x86_64
- os: ubuntu-latest
bitness: 32
platform_id: manylinux_i686
- os: windows-latest
bitness: 64
platform_id: win_amd64
- os: windows-latest
bitness: 32
platform_id: win32
- os: macos-latest
pip-path: ~/Library/Caches/pip
- os: ubuntu-latest
pip-path: ~/.cache/pip
- os: windows-latest
pip-path: ~\AppData\Local\pip\Cache
exclude:
- os: macos-latest
bitness: 32
# - python: pp37
# bitness: 32
steps:
- name: Checkout source code
uses: actions/checkout@v2
- name: Setup Rust toolchain - non-win32
uses: actions-rs/toolchain@v1
with:
override: true
profile: minimal
toolchain: stable
if: ${{ !startsWith(matrix.os, 'windows') || matrix.bitness != '32' }}
- name: Setup Rust toolchain - win32
uses: actions-rs/toolchain@v1
with:
override: true
profile: minimal
toolchain: stable
target: i686-pc-windows-msvc
if: startsWith(matrix.os, 'windows') && matrix.bitness == '32'
- name: Setup Rust dependencies
uses: actions-rs/toolchain@v1
with:
override: true
profile: minimal
toolchain: stable
if: ${{ !startsWith(matrix.os, 'windows') && matrix.bitness != '32' }}
- name: Cache Rust files
uses: actions/cache@v2
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ matrix.os }}-${{ matrix.bitness }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ matrix.os }}-${{ matrix.bitness }}-cargo-
- name: Setup Python
uses: actions/setup-python@v3
# with:
# python-version: "3.8"
- name: Cache Python files
uses: actions/cache@v2
with:
path: ${{ matrix.pip-path }}
key: ${{ matrix.os }}-${{ matrix.bitness }}-pip-${{ matrix.python }}-${{ matrix.platform_id }}-${{ matrix.manylinux_image }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ matrix.os }}-${{ matrix.bitness }}-pip-${{ matrix.python }}-${{ matrix.platform_id }}-${{ matrix.manylinux_image }}-
- name: Update pip
run: |
python -m pip install -U pip
- name: Build Python wheels
uses: pypa/cibuildwheel@v2.11.2
with:
package-dir: nlpo3-python
output-dir: wheelhouse
env:
CIBW_BUILD_VERBOSITY: 1
# See build selector name at:
# https://cibuildwheel.readthedocs.io/en/stable/options/#build-skip
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.platform_id }}
CIBW_ENVIRONMENT_LINUX: PATH="$HOME/.cargo/bin:$PATH"
CIBW_ENVIRONMENT_MACOS: MACOSX_DEPLOYMENT_TARGET=10.13
PATH="$HOME/.cargo/bin:$PATH"
CC=/usr/bin/clang
CXX=/usr/bin/clang++
CIBW_MANYLINUX_I686_IMAGE: ${{ matrix.manylinux_image }}
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux_image }}
CIBW_MANYLINUX_PYPY_I686_IMAGE: ${{ matrix.manylinux_image }}
CIBW_MANYLINUX_PYPY_X86_64_IMAGE: ${{ matrix.manylinux_image }}
CIBW_BEFORE_BUILD_LINUX: >
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=stable --profile=minimal -y
CIBW_BEFORE_BUILD_WINDOWS: 'rustup default stable'
- name: Store artifacts
uses: actions/upload-artifact@v2
with:
path: ./wheelhouse/*.whl
build_sdist:
name: Build Python source distribution
runs-on: ubuntu-latest
needs: check_build_trigger
if: needs.check_build_trigger.outputs.build
steps:
- name: Checkout source code
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.8"
- name: Build source distribution
run: |
cd nlpo3-python
bash ../build_tools/github/build_source.sh
- name: Store artifacts
uses: actions/upload-artifact@v2
with:
path: nlpo3-python/dist/*.tar.gz
build_wheels_macos:
name: Build wheels on M1
runs-on: self-hosted
steps:
- uses: actions/checkout@v3
#- name: Setup Rust dependencies
# uses: ATiltedTree/setup-rust@v1
# with:
# rust-version: 1.65.0
- name: Test
run: cargo test
- name: Build wheels - py38
run: |
source ~/miniconda3/etc/profile.d/conda.sh
conda init zsh
cd nlpo3-python
conda activate python38
python -V
python -m pip install maturin
python -m pip list
python -m pip wheel . -w build
conda deactivate
cd ..
shell: zsh {0}
- name: Build wheels - py39
run: |
source ~/miniconda3/etc/profile.d/conda.sh
conda init zsh
cd nlpo3-python
conda activate python39
python -V
python -m pip install maturin
python -m pip list
python -m pip wheel . -w build
conda deactivate
cd ..
shell: zsh {0}
- name: Build wheels - py310
run: |
source ~/miniconda3/etc/profile.d/conda.sh
conda init zsh
cd nlpo3-python
conda activate python310
python -V
python -m pip install maturin
python -m pip list
python -m pip wheel . -w build
conda deactivate
cd ..
shell: zsh {0}
- name: Store artifacts
uses: actions/upload-artifact@v2
with:
path: ./nlpo3-python/build/*.whl
publish_pypi:
name: Publish Python package to PyPI
runs-on: ubuntu-latest
needs: [build_wheels, build_sdist, build_wheels_macos]
# upload to PyPI on every tag starting with 'v'
#if: github.event_name == 'push' && startsWith(github.event.ref, 'v')
# alternatively, to publish when a GitHub Release is created, use the following rule:
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- name: Retrieve artifacts
uses: actions/download-artifact@v2
with:
name: artifact
path: dist
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}