-
Notifications
You must be signed in to change notification settings - Fork 786
Expand file tree
/
Copy pathJustfile
More file actions
212 lines (185 loc) · 8.56 KB
/
Copy pathJustfile
File metadata and controls
212 lines (185 loc) · 8.56 KB
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
# FIXME: some of these tests don't work very well on MacOS at the moment. Should fix
# them at earliest convenience :)
platform_excludes := if os() == "macos" {
"--exclude runtime-params-estimator --exclude near-network --exclude estimator-warehouse"
} else if os() == "windows" {
"--exclude node-runtime --exclude runtime-params-estimator --exclude near-network --exclude estimator-warehouse --exclude integration-tests"
} else {
""
}
# TODO(spice): Make spice run part of nightly once it's close to being done.
# Releasing spice may take awhile and we should be able to test features without
# spice until it's close to being done.
spice_test_flags := "--features protocol_feature_spice,nightly,test_features"
nightly_test_flags := "--features nightly,test_features"
stable_test_flags := "--features test_features"
export RUST_BACKTRACE := env("RUST_BACKTRACE", "short")
export RUST_LOG := env("RUST_LOG", "info,test_loop=warn")
ci_hack_nextest_profile := if env("CI_HACKS", "0") == "1" { "--profile ci" } else { "" }
# all the tests, as close to CI as possible
test *FLAGS: (test-ci FLAGS) test-extra
# only the tests that are exactly the same as the ones in CI
test-ci *FLAGS: check-cargo-fmt \
check-import-blocks \
python-style-checks \
check-cargo-deny \
check-themis \
check-cargo-machete \
check-cargo-clippy \
check-non-default \
check-cargo-udeps \
(nextest "stable" FLAGS) \
(nextest "nightly" FLAGS) \
(nextest "spice" FLAGS) \
doctests
# order them with the fastest / most likely to fail checks first
# when changing this, remember to adjust the CI workflow in parallel, as CI runs each of these in a separate job
# tests that are as close to CI as possible, but not exactly the same code
test-extra: check-lychee
# all cargo tests,
# TYPE is one of "stable", "nightly"
nextest TYPE *FLAGS:
env RUSTFLAGS="-D warnings" \
cargo nextest run \
--locked \
--workspace \
--cargo-profile dev-release \
{{ ci_hack_nextest_profile }} \
{{ platform_excludes }} \
{{ if TYPE == "nightly" { nightly_test_flags } \
else if TYPE == "stable" { stable_test_flags } \
else if TYPE == "spice" { spice_test_flags } \
else { error("TYPE is neither 'spice, 'nightly' nor 'stable'") } }} \
{{ FLAGS }}
nextest-slow TYPE *FLAGS: (nextest TYPE "--ignore-default-filter -E 'default() + test(/^(.*::slow_test|slow_test)/)'" FLAGS)
nextest-all TYPE *FLAGS: (nextest TYPE "--ignore-default-filter -E 'all()'" FLAGS)
doctests:
cargo test --doc
# check various build configurations compile as anticipated
check-non-default:
# Ensure that near-vm-runner always builds without default features enabled
RUSTFLAGS="-D warnings" \
cargo check -p near-vm-runner --no-default-features
# check rust formatting
check-cargo-fmt:
cargo fmt -- --check
# check that use imports form a single block without blank line separators
check-import-blocks:
python3 scripts/check_import_blocks.py
# check clippy lints
check-cargo-clippy *FLAGS:
CARGO_TARGET_DIR="target/clippy" \
RUSTFLAGS="-D warnings" \
cargo clippy --all-features --all-targets --locked {{ FLAGS }}
# check cargo deny lints
check-cargo-deny:
cargo deny --all-features --locked check bans
# themis-based checks
check-themis:
env CARGO_TARGET_DIR="target/themis" cargo run --locked -p themis
# generate a codecov report for RULE
codecov RULE:
#!/usr/bin/env bash
set -euxo pipefail
# Note: macos seems to not support `source <()` as a way to set environment variables, but
# this variant seems to work on both linux and macos.
# TODO: remove the RUSTFLAGS hack, see also https://github.com/rust-lang/cargo/issues/13040
cargo llvm-cov show-env --export-prefix | grep -v RUSTFLAGS= > env
source ./env
export RUSTC_WORKSPACE_WRAPPER="{{ absolute_path("scripts/coverage-wrapper-rustc") }}"
{{ just_executable() }} {{ RULE }}
mkdir -p coverage/codecov
# If coverage profiling produced corrupted/empty .profraw (e.g. due to a segfault),
# `cargo llvm-cov report` can fail. Fall back to an empty JSON so CI proceeds.
cargo llvm-cov report --profile dev-release --codecov --output-path coverage/codecov/new.json || echo '{}' > coverage/codecov/new.json
# generate a codecov report for RULE, CI version
codecov-ci RULE:
{{ just_executable() }} codecov "{{ RULE }}"
# style checks from python scripts
python-style-checks:
python3 scripts/check_nightly.py
python3 scripts/check_pytests.py
./scripts/formatting --check
install-rustc-nightly:
rustup toolchain install nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
rustup component add rust-src --toolchain nightly
# verify there is no unused dependency specified in a Cargo.toml
check-cargo-udeps: install-rustc-nightly
env CARGO_TARGET_DIR={{justfile_directory()}}/target/udeps RUSTFLAGS='--cfg=udeps --cap-lints=allow' cargo +nightly udeps
check-cargo-machete:
cargo machete
# lychee-based url validity checks
check-lychee:
# This is not actually run in CI. GITHUB_TOKEN can still be set locally by people who want
# to reproduce CI behavior in a better way.
git ls-files | grep 'md$\|mkd$\|html\?$' | xargs lychee {{ if env("GITHUB_TOKEN", "") != "" { "" } else { "-a 429" } }}
@echo {{ if env("GITHUB_TOKEN", "") != "" { "" } \
else { "Note: 'Too Many Requests' errors are allowed here but not in CI, set GITHUB_TOKEN to check them" } }}
# check tools/protocol-schema-check/res/protocol_schema.toml
protocol_schema_env := "CARGO_TARGET_DIR=" + justfile_directory() + "/target/schema-check"
check-protocol-schema:
env {{protocol_schema_env}} cargo test -p protocol-schema-check --profile dev-artifacts
env {{protocol_schema_env}} cargo run -p protocol-schema-check --profile dev-artifacts
publishable := "cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.publish == null or (.publish | length > 0)) | .name'"
check-publishable-separately *OPTIONS:
#!/usr/bin/env bash
REPORT=""
FINAL_RESULT=0
for pkg in $({{ publishable }}); do
pkg_name=$(echo $pkg | tr -d '\n' | tr -d '\r') # remove trailing newline from package name
echo "Checking $pkg_name..."
# Skip the `cargo check -p near-vm-runner --all-features` check on windows, it's broken:
# See https://near.zulipchat.com/#narrow/channel/295302-general/topic/Crates.20windows.20support/near/509548123
# TODO - fix by removing the old broken crate
if [ "{{ os() }}" == "windows" ] && [ "$pkg_name" == "near-vm-runner" ] && [[ "{{ OPTIONS }}" == *"--all-features"* ]]; then
echo "Skipping"
REPORT="$REPORT\n$pkg_name: SKIPPED"
continue
fi
env RUSTFLAGS="-D warnings" \
cargo check -p $pkg_name --examples --tests {{ OPTIONS }}
res=$?
if [ $res -eq 0 ]; then
REPORT="$REPORT\n$pkg_name: OK"
else
REPORT="$REPORT\n$pkg_name: FAIL"
FINAL_RESULT=1
fi
done
echo -e $REPORT
exit $FINAL_RESULT
openapi-spec:
#!/usr/bin/env bash
cargo run -p near-jsonrpc-openapi-spec > chain/jsonrpc/openapi/openapi.json
git diff --exit-code
res=$?
if [ $res -ne 0 ]; then
echo "OpenAPI spec has changed, please ensure the code doesn't break Near JSON RPC clients and run 'cargo run -p near-jsonrpc-openapi-spec > chain/jsonrpc/openapi/openapi.json' to update it. Also update spec version accordingly in chain/jsonrpc/openapi/src/main.rs."
exit 1
fi
check-cspell:
# You will need the cspell npm package.
# For nixpkgs users that's `nodePackages.cspell`
git ls-files | cspell --no-progress --file-list stdin
# Derives COMPOSE_PROFILES from NUM_VALIDATORS; plain `docker compose up`
# users must sync it manually.
# Bring up the bug-bounty localnet (4 validators by default; edit tools/bounty-localnet/.env to change).
bounty-localnet:
#!/usr/bin/env bash
set -euo pipefail
cd tools/bounty-localnet
[ -f .env ] || cp .env.example .env
set -a
source .env
set +a
if (( NUM_VALIDATORS > 1 )); then
export COMPOSE_PROFILES="min${NUM_VALIDATORS}"
else
# empty export, not unset: shell env must win over the .env value
export COMPOSE_PROFILES=""
fi
docker compose up --build
# Tear down the bug-bounty localnet and wipe its generated state.
bounty-localnet-reset:
cd tools/bounty-localnet && ./reset.sh