@@ -2,15 +2,15 @@ name: CI
22
33on :
44 push :
5- branches :
6- - master
7- tags :
8- - v*
5+ branches : [master]
6+ tags : [v*]
97 pull_request :
10- branches :
11- - master
8+ branches : [master]
129
1310jobs :
11+ # ------------------------------------------------------------
12+ # C++ library build & test (fast sanity check)
13+ # ------------------------------------------------------------
1414 build-and-test-cpp :
1515 name : Build and test C++ library on ${{ matrix.os }}
1616 runs-on : ${{ matrix.os }}
@@ -20,139 +20,178 @@ jobs:
2020 os : [ubuntu-latest, macos-latest]
2121
2222 steps :
23- - uses : actions/checkout@v3
23+ - uses : actions/checkout@v4
2424 with :
2525 submodules : recursive
2626
27- - name : Install ICU libraries on macOS
28- if : startsWith(matrix .os, 'macos')
27+ - name : Install ICU ( macOS)
28+ if : runner .os == 'macOS'
2929 run : brew install icu4c
3030
31- - name : Build and install
32- if : startsWith(matrix .os, 'ubuntu')
31+ - name : Build & install (Linux)
32+ if : runner .os == 'Linux'
3333 run : |
3434 cmake -DBUILD_TESTS=ON -DCMAKE_INSTALL_PREFIX=$PWD/install .
35- make install
35+ make -j2 install
3636
37- - name : Build and install (macOS)
38- if : startsWith(matrix .os, 'macos')
37+ - name : Build & install (macOS)
38+ if : runner .os == 'macOS'
3939 run : |
4040 ICU_PREFIX=$(brew --prefix icu4c)
4141 cmake \
4242 -DBUILD_TESTS=ON \
4343 -DCMAKE_INSTALL_PREFIX=$PWD/install \
4444 -DICU_ROOT=$ICU_PREFIX \
4545 .
46- make install
46+ make -j2 install
4747
48-
49- - name : Test
50- run : |
51- test/onmt_tokenizer_test test/data
48+ - name : Run C++ tests
49+ run : test/onmt_tokenizer_test test/data
5250
5351
52+ # ------------------------------------------------------------
53+ # Python style checks
54+ # ------------------------------------------------------------
5455 check-python-style :
5556 runs-on : ubuntu-latest
5657
5758 steps :
58- - uses : actions/checkout@v3
59+ - uses : actions/checkout@v4
5960
60- - name : Set up Python
61- uses : actions/setup-python@v4
61+ - uses : actions/setup-python@v5
6262 with :
6363 python-version : " 3.11"
6464
65- - name : Install dependencies
65+ - name : Install linters
6666 run : |
67- python -m pip install black==22.* flake8==3.9.* isort==5.*
67+ pip install black==22.* flake8==3.9.* isort==5.*
6868
69- - name : Check code format with Black
69+ - name : Black
7070 working-directory : bindings/python
71- run : |
72- black --check .
71+ run : black --check .
7372
74- - name : Check imports order with isort
73+ - name : isort
7574 working-directory : bindings/python
76- run : |
77- isort --check-only .
75+ run : isort --check-only .
7876
79- - name : Check code style with Flake8
77+ - name : Flake8
8078 working-directory : bindings/python
81- if : ${{ always() }}
82- run : |
83- flake8 .
79+ run : flake8 .
8480
8581
86- build-and-test-python-wheels :
87- name : Build and test wheels on ${{ matrix.os }} for ${{ matrix.arch }}
82+ # ------------------------------------------------------------
83+ # Build Python wheels
84+ # ------------------------------------------------------------
85+ build-python-wheels :
86+ name : Wheels – ${{ matrix.os }} / ${{ matrix.arch }}
8887 runs-on : ${{ matrix.os }}
8988 strategy :
9089 fail-fast : false
9190 matrix :
92- os : [ubuntu-latest, macos-latest, windows-2019]
93- arch : [auto64]
9491 include :
95- - os : ubuntu-latest
96- arch : aarch64
97- - os : macos-latest
98- arch : arm64
92+ # Linux
93+ - os : ubuntu-latest
94+ arch : x86_64
95+ - os : ubuntu-latest
96+ arch : aarch64
97+
98+ # macOS
99+ # - os: macos-latest
100+ # arch: x86_64
101+ # - os: macos-latest
102+ # arch: arm64
103+
104+ # Windows
105+ - os : windows-2019
106+ arch : AMD64
99107
100108 steps :
101- - uses : actions/checkout@v3
109+ - uses : actions/checkout@v4
102110 with :
103111 submodules : recursive
104112
105- - uses : docker/setup-qemu-action@v2
106- if : ${{ matrix.arch == 'aarch64' }}
107- name : Set up QEMU
113+ - name : Enable QEMU (Linux ARM)
114+ if : matrix.arch == 'aarch64'
115+ uses : docker/setup-qemu-action@v3
108116
109117 - name : Build wheels
110118111119 with :
112120 package-dir : bindings/python
113121 output-dir : wheelhouse
114122 env :
115- CIBW_ENVIRONMENT_LINUX : TOKENIZER_ROOT=/project/build/install ICU_ROOT=/project/icu
116- CIBW_ENVIRONMENT_MACOS : TOKENIZER_ROOT=${GITHUB_WORKSPACE}/build/install
117- CIBW_ENVIRONMENT_WINDOWS : TOKENIZER_ROOT=${GITHUB_WORKSPACE}/build/install
118- CIBW_BEFORE_ALL_LINUX : bindings/python/tools/prepare_build_environment_linux.sh
119- CIBW_BEFORE_ALL_MACOS : bindings/python/tools/prepare_build_environment_macos.sh
120- CIBW_BEFORE_ALL_WINDOWS : bash bindings/python/tools/prepare_build_environment_windows.sh
123+ # ---- Build selection ----
124+ CIBW_BUILD : " cp310-* cp311-* cp312-* "
125+ CIBW_SKIP : " pp* *-musllinux_* "
126+ CIBW_ARCHS : ${{ matrix.arch }}
127+
128+ # ---- Dependencies ----
121129 CIBW_BEFORE_BUILD : pip install pybind11==2.10.1
130+
131+ # ---- Linux ----
132+ CIBW_BEFORE_ALL_LINUX : bindings/python/tools/prepare_build_environment_linux.sh
133+ CIBW_ENVIRONMENT_LINUX : |
134+ TOKENIZER_ROOT=/project/build/install
135+ ICU_ROOT=/project/icu
122136 CIBW_MANYLINUX_X86_64_IMAGE : manylinux2014
123137 CIBW_MANYLINUX_AARCH64_IMAGE : manylinux2014
124- CIBW_BUILD : " cp310-* cp311-* cp312-*"
138+
139+ # ---- macOS ----
140+ CIBW_BEFORE_ALL_MACOS : bindings/python/tools/prepare_build_environment_macos.sh
141+ CIBW_ENVIRONMENT_MACOS : |
142+ TOKENIZER_ROOT=${GITHUB_WORKSPACE}/build/install
143+ ICU_ROOT=${GITHUB_WORKSPACE}/icu
144+ DYLD_LIBRARY_PATH=${GITHUB_WORKSPACE}/icu/lib:${DYLD_LIBRARY_PATH}
145+ CIBW_REPAIR_WHEEL_COMMAND_MACOS : |
146+ set -e
147+ echo "=== Bundling ICU into wheel ==="
148+ delocate-wheel -v -w {dest_dir} {wheel}
149+
150+ REPAIRED_WHEEL=$(ls {dest_dir}/*.whl)
151+ echo "=== Inspecting repaired wheel ==="
152+ unzip -q "$REPAIRED_WHEEL" -d /tmp/wheel_check
153+ SO_FILE=$(find /tmp/wheel_check -name "_ext*.so" | head -n1)
154+ otool -L "$SO_FILE"
155+ rm -rf /tmp/wheel_check
156+ echo "=== Wheel ready: $REPAIRED_WHEEL ==="
157+
158+
159+
160+ # ---- Windows ----
161+ CIBW_BEFORE_ALL_WINDOWS : bash bindings/python/tools/prepare_build_environment_windows.sh
162+ CIBW_ENVIRONMENT_WINDOWS : TOKENIZER_ROOT=${GITHUB_WORKSPACE}/build/install
163+
164+ # ---- Tests ----
125165 CIBW_TEST_COMMAND : pytest {project}/bindings/python/test/test.py
126166 CIBW_TEST_REQUIRES : pytest
127- CIBW_ARCHS : ${{ matrix.arch }}
128- CIBW_SKIP : pp* *-musllinux_*
129- CIBW_TEST_SKIP : " *-macosx_arm64"
130- CIBW_REPAIR_WHEEL_COMMAND_MACOS : " "
131167
132- - name : Upload Python wheels
168+ - name : Upload wheels
133169 uses : actions/upload-artifact@v4
134170 with :
135171 name : python-wheels-${{ matrix.os }}-${{ matrix.arch }}
136172 path : wheelhouse
137173
138174
139- publish-python-wheels-on-pypi :
140- if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
141- needs : [build-and-test-cpp, build-and-test-python-wheels]
175+ # ------------------------------------------------------------
176+ # Publish to PyPI (API token, no Trusted Publishing)
177+ # ------------------------------------------------------------
178+ publish-python-wheels :
179+ if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
180+ needs : [build-and-test-cpp, build-python-wheels]
142181 runs-on : ubuntu-latest
143182
144183 steps :
145- - name : Download all wheels
184+ - name : Download wheels
146185 uses : actions/download-artifact@v4
147186 with :
148187 path : artifacts
149188
150189 - name : Collect wheels
151190 run : |
152- mkdir -p dist
191+ mkdir dist
153192 find artifacts -name "*.whl" -exec cp {} dist/ \;
154-
155- - name : Publish Python wheels to PyPI
193+
194+ - name : Publish to PyPI
156195 uses : pypa/gh-action-pypi-publish@release/v1
157196 with :
158197 packages-dir : dist
0 commit comments