-
Notifications
You must be signed in to change notification settings - Fork 2
346 lines (290 loc) · 9.73 KB
/
packaging.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# Copyright 2021-2023 Jetperch LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# GitHub actions
# See documentation: https://docs.github.com/en/actions
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
# CMake example: https://github.com/Mizux/cmake-cpp/blob/main/.github/workflows/amd64_windows.yml
name: Packaging
on: ['push', 'pull_request']
env:
PYTHON_VERSION: '3.11'
jobs:
build_native_win:
name: Build native on windows-latest
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
include:
- {shared: OFF, target: ALL_BUILD}
- {shared: ON, target: jsdrv}
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Build
run: |
cmake --version
cmake -S . -B cmake_build -G "Visual Studio 17 2022" -DCMAKE_CONFIGURATION_TYPES=Release -DCMAKE_VERBOSE_MAKEFILE=ON -DBUILD_SHARED_LIBS=${{matrix.shared}}
cmake --build cmake_build --config Release --target ${{matrix.target}}
- name: Run tests
if: matrix.shared == 'OFF'
run: cmake --build cmake_build --config Release --target RUN_TESTS
- name: Create artifacts directory
shell: bash
run: mkdir artifacts
- name: Save static
if: matrix.shared == 'OFF'
shell: bash
run: cp cmake_build/example/Release/jsdrv.exe artifacts/jsdrv.exe
- name: Save dynamic
if: matrix.shared == 'ON'
shell: pwsh
run: Compress-Archive -Path cmake_build/src/Release/jsdrv.* -Destination artifacts/jsdrv_dll.zip
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: windows-latest-${{ matrix.shared }}
path: artifacts/*
if-no-files-found: error
build_native_posix:
name: Build native on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest"]
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Install Ubuntu dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt update
sudo apt install -y libudev-dev
- name: Display CMake version
run: cmake --version
- name: Build static
run: |
cmake -S . -B cmake_build_static -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_VERBOSE_MAKEFILE=ON
cmake --build cmake_build_static
- name: Run tests
run: cmake --build cmake_build_static --target test
- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}
path: cmake_build_static/example/jsdrv
if-no-files-found: error
build_python_sdist:
name: Build python sdist
runs-on: ubuntu-latest
steps:
- name: Display info
run: |
echo "github.event_name=$GITHUB_EVENT_NAME"
echo "github.ref=$GITHUB_REF"
echo "github.ref_type=$GITHUB_REF_TYPE"
echo "runner.os=$RUNNER_OS"
echo "runner.arch=$RUNNER_ARCH"
- name: Install Ubuntu dependencies
run: |
sudo apt update
sudo apt install -y libudev-dev
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install python dependencies
run: |
python -VV
python -m pip install --upgrade pip
python -m pip install --upgrade wheel setuptools build
- name: Build sdist
run: python -m build --sdist
- name: Upload python source package
uses: actions/upload-artifact@v4
with:
name: python_sdist
path: dist/*.tar.gz
if-no-files-found: error
build_python_wheels:
name: Build os=${{ matrix.os }}, python=${{ matrix.python_version }}
needs:
- build_python_sdist
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
python_version: ["cp39", "cp310", "cp311", "cp312"]
steps:
- name: Download sdist
uses: actions/download-artifact@v4
with:
name: python_sdist
path: dist/
- name: Find sdist filename
shell: bash
id: find_sdist_filename
run: echo "filename=$(ls dist/*.tar.gz)" >> $GITHUB_OUTPUT
- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_ARCHS_MACOS: universal2
CIBW_ARCHS_WINDOWS: native
CIBW_ARCHS_LINUX: native
# skip PyPy: Cython only supports CPython
# skip musllinux: build takes too long with default os images.
CIBW_SKIP: 'pp* *musllinux*'
CIBW_BUILD: '${{ matrix.python_version }}-*'
CIBW_BEFORE_BUILD_LINUX: yum install -y libudev-devel
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_COMMAND: pytest --pyargs pyjoulescope_driver
CIBW_TEST_SKIP: "*-macosx_universal2:arm64" # cannot test arm64 on x86_64
with:
package-dir: ${{ steps.find_sdist_filename.outputs.filename }}
- name: Upload python wheels
uses: actions/upload-artifact@v4
with:
name: python_wheel-${{ matrix.os }}-${{ matrix.python_version }}
path: wheelhouse/*.whl
if-no-files-found: error
publish_python:
name: Publish python packages to PyPi
if: github.event_name == 'push' && startswith(github.ref, 'refs/tags/v')
needs:
- build_native_win
- build_native_posix
- build_python_wheels
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: Download python sdist artifacts
uses: actions/download-artifact@v4
with:
name: python_sdist
path: dist/
- name: Download python wheel artifacts
uses: actions/download-artifact@v4
with:
pattern: python_wheel-*
merge-multiple: true
path: dist/
- name: Download windows binary artifacts
uses: actions/download-artifact@v4
with:
pattern: windows-latest-*
merge-multiple: true
path: windows-latest
- name: Display artifacts
shell: bash
run: ls dist/*
- name: Publish packages to PyPi
uses: pypa/[email protected]
with:
print-hash: true
- name: Publish Release assets
uses: softprops/action-gh-release@v1
with:
files: |
dist/*
windows-latest/*
build_node_js:
name: build_node_js_${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Install Ubuntu dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt update
sudo apt install -y libudev-dev
- name: NPM
shell: bash
run: |
cd node_api
npm install --global prebuildify node-gyp node-gyp-build
npm update
prebuildify --napi --strip --target 20.12.2
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: node_js_native-${{ matrix.os }}
path: node_api/prebuilds/*
if-no-files-found: error
package_node_js:
name: Package node.js binding
needs:
- build_node_js
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Download node.js native build files
uses: actions/download-artifact@v4
with:
pattern: node_js_native-*
merge-multiple: true
path: node_api/prebuilds/
- name: Create package
shell: bash
run: |
mkdir package
cd node_api
npm pack --pack-destination ../package
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: node_js
path: package/*
if-no-files-found: error
publish_node_js:
name: Publish node.js package to registry.npmjs.org
if: github.event_name == 'push' && startswith(github.ref, 'refs/tags/v')
needs:
- package_node_js
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: Download node package
uses: actions/download-artifact@v4
with:
name: node_js
path: dist/
- name: Find package filename
shell: bash
id: find_package
run: echo "filename=$(ls ./dist/*.tgz)" >> $GITHUB_OUTPUT
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'
- name: Install NPM command line utility
run: npm install -g npm
- name: Publish to NPM
run: npm publish --provenance --access public ${{ steps.find_package.outputs.filename }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}