-
Notifications
You must be signed in to change notification settings - Fork 9
377 lines (328 loc) · 11.8 KB
/
ci.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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
name: "Continuous Integration"
on:
push:
branches:
- "**"
release:
types:
- published
jobs:
test:
name: "Test"
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
runs-on: "${{ matrix.os }}"
steps:
# Check out the code
- uses: "actions/checkout@v4"
# We need node for some integration tests
- uses: "actions/setup-node@v4"
# Install python
- name: "Set up python"
uses: "actions/setup-python@v5"
with:
python-version: "${{ matrix.python-version }}"
- name: "Get Python Path"
id: get-py-path
shell: bash
run: |
echo "path=$(which python)" >> $GITHUB_OUTPUT
# Set the current month and year (used for cache key)
- name: "Get Date"
id: get-date
# Outputs e.g. "202007"
# tbh I have yet to find the docs where this output format is
# defined, but I copied this from the official cache action's README.
run: |
echo "date=$(/bin/date -u '+%Y%m')" >> $GITHUB_OUTPUT
shell: bash
# Generate the lockfile
- name: "Generate Cargo Lockfile"
run: "cargo generate-lockfile"
# Cache build dependencies
- name: "Cache Build Fragments"
id: "cache-build-fragments"
uses: "actions/cache@v4"
with:
path: |
~/.cargo/registry
~/.cargo/git
target
# Use the OS, the python version, and the hashed cargo lockfile as the
# cache key. The Python version shouldn't be necessary, but I have
# seen some weird failures in Windows CI where it gets the built
# python targets confused. The Python version is included at the
# end so it can be partially matched by cache keys in contexts
# where we're not iterating over python envs.
key: ${{ runner.os }}-${{ contains(runner.os, 'windows') && 'test-' || '' }}cargo-${{ hashFiles('**/Cargo.lock') }}-${{ matrix.python-version }}
# Cache `cargo install` built binaries
- name: "Cache Built Binaries"
id: "cache-binaries"
uses: "actions/cache@v4"
with:
path: "~/.cargo/bin"
# In theory, this should rebuild binaries once a month
key: "${{ runner.os }}-cargo-binaries-${{steps.get-date.outputs.date}}"
- name: Install wasm-pack
uses: jetli/[email protected]
with:
version: "v0.12.1"
- name: "Run Tests"
if: "${{ !contains(runner.os, 'windows') }}"
shell: bash
run: "cargo test --all-features"
- name: "Run Tests (Windows)"
if: "${{ contains(runner.os, 'windows') }}"
shell: bash
# Python behaves weirdly with setup.py develop in Windows,
# when it comes to loading DLLs, so on that platform we build and
# install the wheel and run the tests with that.
# Running `cargo test --features=wasm` runs all the regular lib
# tests plus the WASM integration tests, while excluding the
# python integration tests
run: |
cargo test --features=wasm
make develop-py-wheel
ls dist/*.whl
pip install dist/*.whl
echo "Running Tests"
python tests/test_py.py
env:
WINDOWS: "${{ contains(runner.os, 'windows') }}"
PYTHON: ${{ steps.get-py-path.outputs.path }}
build:
name: "Build Libs, WASM, and Python sdist"
needs: "test"
runs-on: ubuntu-latest
steps:
# Check out the code
- uses: "actions/checkout@v4"
# Install python
- name: "Set up python"
uses: "actions/setup-python@v5"
with:
python-version: "3.12"
- name: "Get Python Path"
id: get-py-path
shell: bash
run: |
echo "path=$(which python)" >> $GITHUB_OUTPUT
# Set the current month and year (used for cache key)
- name: "Get Date"
id: get-date
# Outputs e.g. "202007"
# tbh I have yet to find the docs where this output format is
# defined, but I copied this from the official cache action's README.
run: |
echo "date=$(/bin/date -u '+%Y%m')" >> $GITHUB_OUTPUT
shell: bash
# Generate the lockfile
- name: "Generate Cargo Lockfile"
run: "cargo generate-lockfile"
# Cache build dependencies
- name: "Cache Build Fragments"
id: "cache-build-fragments"
uses: "actions/cache@v4"
with:
path: |
~/.cargo/registry
~/.cargo/git
target
# This should partial match the caches generated for the tests,
# which include a python version at the end.
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
# Cache `cargo install` built binaries
- name: "Cache Built Binaries"
id: "cache-binaries"
uses: "actions/cache@v4"
with:
path: "~/.cargo/bin"
# In theory, this should rebuild binaries once a month
key: "${{ runner.os }}-cargo-binaries-${{steps.get-date.outputs.date}}"
- name: Install wasm-pack
uses: jetli/[email protected]
with:
version: "v0.12.1"
- name: "Build Rust/C Libraries"
run: "make build"
- name: "Check Rust target content"
run: ls target/release
- uses: "actions/upload-artifact@v3"
name: "Upload Rust/C Libraries"
with:
path: target/release/libjsonlogic_rs.*
name: libs
- name: "Build Python Source Dist"
run: "make build-py-sdist"
env:
WINDOWS: "${{ contains(runner.os, 'windows') }}"
PYTHON: ${{ steps.get-py-path.outputs.path }}
- uses: "actions/upload-artifact@v3"
name: "Upload Python sdist"
with:
path: dist/*.tar.gz
name: py-sdist
- name: "Build WASM Node Package"
run: "make build-wasm"
- uses: "actions/upload-artifact@v3"
name: "Upload node package"
with:
path: js/
name: wasm-pkg
build-wheels:
name: >
Build Wheel
(${{ matrix.platform.os }}, ${{ matrix.platform.name }}, ${{ matrix.py }})
# needs: test
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: false
matrix:
platform:
- { os: ubuntu-latest, name: manylinux }
- { os: ubuntu-latest, name: musllinux }
- { os: macos-latest, name: macosx }
py:
- cp39
- cp310
- cp311
- cp312
- cp313
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Build wheels
uses: pypa/[email protected]
env:
# configure cibuildwheel to build native archs ('auto'), and some
# emulated ones
CIBW_ARCHS_LINUX: x86_64 aarch64
# cross-compiling wheels for discrete architectures not working OOTB
# see: https://github.com/PyO3/setuptools-rust/issues/206
CIBW_ARCHS_MACOS: x86_64 universal2 arm64
CIBW_ARCHS_WINDOWS: AMD64
CIBW_BEFORE_ALL_LINUX: >
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y
CIBW_BEFORE_ALL_MACOS: |
rustup target add aarch64-apple-darwin
rustup target add x86_64-apple-darwin
CIBW_ENVIRONMENT_LINUX: PATH=/root/.cargo/bin:$PATH
CIBW_ENVIRONMENT_MACOS: MACOSX_DEPLOYMENT_TARGET=10.12
CIBW_BUILD: ${{ matrix.py }}-${{ matrix.platform.name }}_*
CIBW_TEST_COMMAND: python {project}/tests/test_py.py
- uses: actions/upload-artifact@v3
with:
name: py-wheels
path: ./wheelhouse/*.whl
distribute:
name: "Distribute Cargo, WASM, and Python Sdist Packages"
needs: ["build", "build-wheels"]
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
steps:
# Check out the code
- uses: "actions/checkout@v4"
# Install python
- name: "Set up python"
uses: "actions/setup-python@v5"
with:
python-version: "3.12"
# Generate the lockfile
- name: "Generate Cargo Lockfile"
run: "cargo generate-lockfile"
- name: "Get Current Version"
id: get-version
shell: bash
run: |
echo "version=$(cargo pkgid | tr '#' '\n' | tail -n 1 | tr ':' ' ' | awk '{print $2}')" >> $GITHUB_OUTPUT
- name: "(DEBUG) log current version"
shell: bash
run: |
echo "${{ steps.get-version.outputs.version }}"
- name: "Check if new Cargo version"
id: cargo-version
shell: bash
run: |
echo "new=$(./scripts/newCargoVersion.sh)" >> $GITHUB_OUTPUT
- name: "Check if new NPM version"
id: npm-version
shell: bash
run: |
echo "new=$(./scripts/newNpmVersion.sh)" >> $GITHUB_OUTPUT
# Note we don't check for a new python version b/c there are so
# many python artifacts that it is impractical. Instead we just
# upload with a `--skip-existing` flag, so if it's already there
# it wont' be an error.
- name: "(DEBUG) new versions"
shell: bash
run: |
echo "Cargo: ${{ steps.cargo-version.outputs.new }}"
echo "NPM: ${{ steps.npm-version.outputs.new }}"
- name: "Persist new cargo state for subsequent jobs"
shell: bash
run: |
echo "${{ steps.cargo-version.outputs.new }}" > tmp-new-cargo-ver
- uses: "actions/upload-artifact@v3"
with:
path: "tmp-new-cargo-ver"
name: "new-cargo"
- name: "Cargo Publish"
if: "${{ steps.cargo-version.outputs.new == 'true' }}"
run: |
cargo publish --token "$CARGO_TOKEN"
env:
CARGO_TOKEN: "${{ secrets.CARGO_TOKEN }}"
- name: "Pull WASM Artifact"
uses: "actions/download-artifact@v1"
if: "${{ steps.npm-version.outputs.new == 'true' }}"
with:
name: wasm-pkg
path: dist-wasm
- name: "Publish NPM Package"
shell: bash
if: "${{ steps.npm-version.outputs.new == 'true' }}"
run: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
npm publish dist-wasm/ --access public
env:
NPM_TOKEN: "${{ secrets.NPM_TOKEN }}"
- name: "Pull Python Sdist Artifact"
if: "${{ steps.cargo-version.outputs.new == 'true' }}"
uses: "actions/download-artifact@v1"
with:
name: py-sdist
path: dist-py
- name: "Publish Python Sdist"
if: "${{ steps.cargo-version.outputs.new == 'true' }}"
shell: bash
run: |
pip install twine
twine upload --skip-existing dist-py/*
env:
TWINE_USERNAME: "__token__"
TWINE_PASSWORD: "${{ secrets.PYPI_TOKEN }}"
distribute-py-wheels:
name: "Distribute Python Wheels"
needs: ["distribute"]
runs-on: ubuntu-latest
# upload to PyPI on every tag starting with 'v'
# if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
# alternatively, to publish when a GitHub Release is created, use the following rule:
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/download-artifact@v3
with:
name: py-wheels
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
skip_existing: true
# To test: repository_url: https://test.pypi.org/legacy/