-
Notifications
You must be signed in to change notification settings - Fork 57
266 lines (241 loc) · 8.84 KB
/
build-test.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
name: Build Mac, Linux, and Windows wheels
on:
push:
branches:
- main
- dev
tags:
- '**'
pull_request:
branches:
- '**'
permissions:
contents: read
id-token: write
jobs:
build_wheels:
name: Wheel on ${{ matrix.os }} py-${{ matrix.python }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python: [3.7]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: chia-network/actions/setup-python@main
name: Install Python ${{ matrix.python }}
with:
python-version: ${{ matrix.python }}
- name: Update pip
run: |
python -m pip install --upgrade pip
- name: Set up rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Install dependencies
run: |
python -m pip install maturin
- name: Build MacOs with maturin on Python ${{ matrix.python }}
if: startsWith(matrix.os, 'macos')
env:
MACOSX_DEPLOYMENT_TARGET: '10.14'
run: |
python -m venv venv
ln -s venv/bin/activate
. ./activate
maturin build -m wheel/Cargo.toml --sdist -i python --release --strip --features=openssl
- name: Build Linux in manylinux2014 with maturin on Python ${{ matrix.python }}
if: startsWith(matrix.os, 'ubuntu')
run: |
docker run --rm \
-v ${{ github.workspace }}:/ws --workdir=/ws \
quay.io/pypa/manylinux2014_x86_64 \
bash -exc '\
curl -L https://sh.rustup.rs > rustup-init.sh && \
sh rustup-init.sh -y && \
yum -y --disablerepo=epel install openssl-devel && \
source $HOME/.cargo/env && \
rustup target add x86_64-unknown-linux-musl && \
PY_VERSION=${{ matrix.python }}
PY_VERSION=${PY_VERSION/.} && \
echo "Python version with dot removed is $PY_VERSION" && \
if [ "$PY_VERSION" = "37" ]; \
then export SCND_VERSION="${PY_VERSION}m"; \
else export SCND_VERSION="$PY_VERSION"; fi && \
echo "Exporting path /opt/python/cp$PY_VERSION-cp$SCND_VERSION/bin" && \
export PATH=/opt/python/cp$PY_VERSION-cp$SCND_VERSION/bin/:$PATH && \
/opt/python/cp38-cp38/bin/python -m venv /venv && \
. /venv/bin/activate && \
pip install --upgrade pip && \
pip install maturin && \
CC=gcc maturin build -m wheel/Cargo.toml --release --strip --manylinux 2014 --features=openssl \
'
python -m venv venv
ln -s venv/bin/activate
- name: Build Windows with maturin on Python ${{ matrix.python }}
if: startsWith(matrix.os, 'windows')
run: |
python -m venv venv
. .\venv\Scripts\Activate.ps1
ln -s venv\Scripts\Activate.ps1 activate
maturin build -m wheel/Cargo.toml -i python --release --strip
# this will install into the venv
# it'd be better to use the wheel, but I can't figure out how to do that
# TODO: figure this out
# this does NOT work: pip install target/wheels/clvm_rs-*.whl
maturin develop --release -m wheel/Cargo.toml
# the line above also doesn't seem to work
- name: Install clvm_rs wheel
if: ${{ !startsWith(matrix.os, 'windows') }}
run: |
. ./activate
ls target/wheels/
# this mess puts the name of the `.whl` file into `$WHEEL_PATH`
# remove the dot, use the `glob` lib to grab the file from the directory
WHEEL_PATH=$(echo ${{ matrix.python }} | python -c 'DOTLESS=input().replace(".", ""); import glob; print(" ".join(glob.glob("target/wheels/clvm_rs-*-cp%s-abi3-*.whl" % DOTLESS)))' )
echo ${WHEEL_PATH}
pip install ${WHEEL_PATH}
- name: Install other wheels
run: |
. ./activate
python -m pip install pytest
python -m pip install blspy
- name: Run tests from wheel
run: |
. ./activate
cd wheel/python
pytest --import-mode append tests
# we use `append` because otherwise the `clvm_rs` source is added
# to `sys.path` and it uses that instead of the wheel (and so
# ignoring `clvm_rs.so`, which is pretty important)
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: wheels
path: ./target/wheels/
- name: publish (PyPi)
if: startsWith(github.event.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: target/wheels/
skip-existing: true
checks:
runs-on: ubuntu-20.04
name: Checks
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt, clippy
- name: Clippy
run: cargo clippy --all-targets --workspace -- -D warnings
- name: fmt
run: cargo fmt --all -- --files-with-diff --check
# leaving out Windows fuzzing for now though it seems supported
# https://llvm.org/docs/LibFuzzer.html#q-does-libfuzzer-support-windows
fuzz_targets:
name: Run fuzz targets
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest]
python: [3.7]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
components: rustfmt, clippy
- name: fmt
run: |
cd fuzz
cargo fmt -- --files-with-diff --check
- name: clippy
run: |
cd fuzz
cargo clippy
- name: cargo-fuzz
run: cargo +nightly install cargo-fuzz
# TODO: it would be nice to save and restore the corpus between runs
- name: build corpus
run: |
cd tools
cargo run --bin generate-fuzz-corpus
- name: build
run: cargo fuzz list | xargs -I "%" sh -c "cargo +nightly fuzz run % -- -max_total_time=30 || exit 255"
unit_tests:
name: Unit tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python: [3.7]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
- name: build
run: cargo build --workspace --exclude clvm_rs-fuzz
- name: cargo test (default)
run: cargo test && cargo test --release
- name: cargo test (counters)
run: cargo test --features=counters && cargo test --features=counters --release
- name: cargo test (pre-eval)
run: cargo test --features=pre-eval && cargo test --features=pre-eval --release
- name: cargo test (pre-eval and counters)
run: cargo test --features=pre-eval,counters && cargo test --features=pre-eval,counters --release
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Run for coverage
run: |
sudo apt-get update
sudo apt-get install lcov -y
rustup component add llvm-tools-preview
export CARGOFLAGS="-j $(nproc)"
cargo install grcov
export RUSTFLAGS="-Cinstrument-coverage"
export LLVM_PROFILE_FILE=$(pwd)/target/clvm_rs-%p-%m.profraw
export CARGO_TARGET_DIR=$(pwd)/target
export RUST_TEST_THREADS=$(nproc)
cargo test --release --workspace
python -m venv venv
source venv/bin/activate
pip install colorama maturin pytest pytest-cov
maturin develop --release -m wheel/Cargo.toml --features=openssl
(cd tests && python generate-programs.py && python run-programs.py) || true
pytest wheel/python/tests --cov=clvm_rs --cov-report lcov:py_cov.info --cov-branch
grcov . --binary-path target -s . --branch --ignore-not-existing --ignore='*/.cargo/*' --ignore='target/*' -o pre_rust_cov.info
python -c 'with open("pre_rust_cov.info") as f: lines = [l for l in f if not (l.startswith("DA:") and int(l.split(",")[1].strip()) >= 2**63)]; open("rust_cov.info", "w").writelines(lines)'
lcov --add-tracefile rust_cov.info -a py_cov.info -o lcov.info
- name: Upload to Coveralls
uses: coverallsapp/github-action@v2
if: always()
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
with:
path-to-lcov: './lcov.info'