-
Notifications
You must be signed in to change notification settings - Fork 7
166 lines (153 loc) · 5.12 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
# Build wheels for many platforms, use cibuildwheel
# see: https://github.com/pypa/cibuildwheel
name: Build wheels
on:
push:
branches:
- main
paths:
- 'nlpo3-python/**'
- '!nlpo3-python/**.md'
- '!nlpo3-python/notebooks/**'
- '.github/workflows/build-python-wheels.yml'
pull_request:
branches:
- main
paths:
- 'nlpo3-python/**'
- '!nlpo3-python/**.md'
- '!nlpo3-python/notebooks/**'
- '.github/workflows/build-python-wheels.yml'
release:
types: [published]
# Manual run
workflow_dispatch: {}
jobs:
echo_github_env:
name: Echo env 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
# Not for forks
if: github.repository == 'pythainlp/nlpo3'
outputs:
build: ${{ steps.check_build_trigger.outputs.build }}
steps:
- name: Checkout source code
uses: actions/checkout@v4
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
# To trigger the build steps, add "[cd build]" to commit message
build_wheels:
name: Build ${{ matrix.os }}
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-version: ["3.13"]
env:
CIBW_BUILD: "" # blank, let cibuildwheel build all supported platforms
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install Python dependencies
run: python -m pip install --upgrade pip
- name: Setup Rust toolchain
if: startsWith(matrix.os, 'ubuntu-') == false
uses: actions-rust-lang/setup-rust-toolchain@v1
# For Linux, Rust will be installed inside a cibuildwheel container later
- name: Setup rustup target
if: startsWith(matrix.os, 'macos-')
run: rustup target add x86_64-apple-darwin
# For cross-compile x86 on GitHub arm64 runner
- name: Build Python wheels
uses: pypa/cibuildwheel@v2.21.3
with:
package-dir: nlpo3-python
output-dir: wheelhouse
env:
CIBW_BUILD_VERBOSITY: 1
# See CIBW_BUILD, CIBW_SKIP, CIBW_ARCHS and other build selectors at:
# https://cibuildwheel.readthedocs.io/en/stable/options/#build-skip
CIBW_SKIP: "*-musllinux_i686"
CIBW_ARCHS_MACOS: "x86_64 arm64"
CIBW_ENVIRONMENT_MACOS: |
MACOSX_DEPLOYMENT_TARGET=10.9
PATH="$HOME/.cargo/bin:$PATH"
CC=/usr/bin/clang
CXX=/usr/bin/clang++
CIBW_ARCHS_LINUX: "auto"
CIBW_ENVIRONMENT_LINUX: PATH="$HOME/.cargo/bin:$PATH"
CIBW_BEFORE_BUILD_LINUX: |
pip install --upgrade setuptools-rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
# It is needed to install Rust for Linux,
# because cibuildwheel on Linux runs inside a container
# and the container does not have Rust.
CIBW_ARCHS_WINDOWS: "AMD64 x86"
- name: Store artifacts
uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl
build_sdist:
name: Build 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@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
cache: "pip"
- name: Build source distribution
run: |
cd nlpo3-python
bash ../build_tools/github/build_source.sh
- name: Store artifacts
uses: actions/upload-artifact@v3
with:
path: nlpo3-python/dist/*.tar.gz
publish_pypi:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: [build_wheels, build_sdist]
# Publish when a GitHub Release is created:
if: github.event_name == 'release' && github.event.action == 'published'
# Alternatively, upload to PyPI on every tag starting with 'v':
#if: github.event_name == 'push' && startsWith(github.event.ref, 'v')
steps:
- name: Retrieve artifacts
uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- name: Publish package
uses: pypa/gh-action-pypi-publish@v1.12.2
with:
skip-existing: true
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}