From cde5e549e1b4684a851e0693efd87bc6b07add64 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sat, 7 Dec 2024 00:09:36 -0500 Subject: [PATCH 1/2] ci: Extract repetitive code to a function --- ci/verify-build.sh | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/ci/verify-build.sh b/ci/verify-build.sh index cba652accaeb..a433f047095d 100755 --- a/ci/verify-build.sh +++ b/ci/verify-build.sh @@ -30,8 +30,8 @@ fi # Run the tests for a specific target test_target() { - target="${1}" - no_dist="${2:-0}" + target="$1" + no_dist="$2" RUSTFLAGS="${RUSTFLAGS:-}" @@ -265,7 +265,13 @@ case "$rust" in *) supports_wasi_pn=0 ;; esac -for target in $targets; do +some_tests_run=0 + +# Apply the `FILTER` variable, do OS-specific tasks, and run a target +filter_and_run() { + target="$1" + no_dist="${2:-0}" + if echo "$target" | grep -q "$filter"; then if [ "$os" = "windows" ]; then TARGET="$target" ./ci/install-rust.sh @@ -278,27 +284,24 @@ for target in $targets; do # `wasm32-wasip2` only exists in recent versions of Rust if [ "$target" = "wasm32-wasip2" ] && [ "$supports_wasi_pn" = "0" ]; then - continue + return fi - test_target "$target" - test_run=1 + test_target "$target" "$no_dist" + some_tests_run=1 fi +} + +for target in $targets; do + filter_and_run "$target" done for target in ${no_dist_targets:-}; do - if echo "$target" | grep -q "$filter"; then - if [ "$os" = "windows" ]; then - TARGET="$target" ./ci/install-rust.sh - fi - - test_target "$target" 1 - test_run=1 - fi + filter_and_run "$target" 1 done # Make sure we didn't accidentally filter everything -if [ "${test_run:-}" != 1 ]; then +if [ "$some_tests_run" != 1 ]; then echo "No tests were run" exit 1 fi From 5b471ae47f0e762c0687c8c72e5b62b4f001cfef Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Dec 2024 23:59:01 -0500 Subject: [PATCH 2/2] ci: Use workflow commands to group output by target --- ci/verify-build.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ci/verify-build.sh b/ci/verify-build.sh index a433f047095d..cc407d7569b7 100755 --- a/ci/verify-build.sh +++ b/ci/verify-build.sh @@ -28,6 +28,12 @@ if [ "$TOOLCHAIN" = "nightly" ] ; then rustup component add rust-src fi +# Print GHA workflow commands +echo_if_ci() { + # Discard stderr so the "set -x" trace doesn't show up + { [ -n "${CI:-}" ] && echo "$1"; } 2> /dev/null +} + # Run the tests for a specific target test_target() { target="$1" @@ -293,11 +299,15 @@ filter_and_run() { } for target in $targets; do + echo_if_ci "::group::Target: $target" filter_and_run "$target" + echo_if_ci "::endgroup::" done for target in ${no_dist_targets:-}; do + echo_if_ci "::group::Target: $target" filter_and_run "$target" 1 + echo_if_ci "::endgroup::" done # Make sure we didn't accidentally filter everything