Skip to content

Commit cde5e54

Browse files
committed
ci: Extract repetitive code to a function
1 parent 5f6c5b0 commit cde5e54

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

ci/verify-build.sh

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ fi
3030

3131
# Run the tests for a specific target
3232
test_target() {
33-
target="${1}"
34-
no_dist="${2:-0}"
33+
target="$1"
34+
no_dist="$2"
3535

3636
RUSTFLAGS="${RUSTFLAGS:-}"
3737

@@ -265,7 +265,13 @@ case "$rust" in
265265
*) supports_wasi_pn=0 ;;
266266
esac
267267

268-
for target in $targets; do
268+
some_tests_run=0
269+
270+
# Apply the `FILTER` variable, do OS-specific tasks, and run a target
271+
filter_and_run() {
272+
target="$1"
273+
no_dist="${2:-0}"
274+
269275
if echo "$target" | grep -q "$filter"; then
270276
if [ "$os" = "windows" ]; then
271277
TARGET="$target" ./ci/install-rust.sh
@@ -278,27 +284,24 @@ for target in $targets; do
278284

279285
# `wasm32-wasip2` only exists in recent versions of Rust
280286
if [ "$target" = "wasm32-wasip2" ] && [ "$supports_wasi_pn" = "0" ]; then
281-
continue
287+
return
282288
fi
283289

284-
test_target "$target"
285-
test_run=1
290+
test_target "$target" "$no_dist"
291+
some_tests_run=1
286292
fi
293+
}
294+
295+
for target in $targets; do
296+
filter_and_run "$target"
287297
done
288298

289299
for target in ${no_dist_targets:-}; do
290-
if echo "$target" | grep -q "$filter"; then
291-
if [ "$os" = "windows" ]; then
292-
TARGET="$target" ./ci/install-rust.sh
293-
fi
294-
295-
test_target "$target" 1
296-
test_run=1
297-
fi
300+
filter_and_run "$target" 1
298301
done
299302

300303
# Make sure we didn't accidentally filter everything
301-
if [ "${test_run:-}" != 1 ]; then
304+
if [ "$some_tests_run" != 1 ]; then
302305
echo "No tests were run"
303306
exit 1
304307
fi

0 commit comments

Comments
 (0)