|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Fork from https://github.com/paradigmxyz/reth/blob/main/.github/assets/check_wasm.sh |
| 4 | + |
| 5 | +set +e # Disable immediate exit on error |
| 6 | + |
| 7 | +# Array of crates to compile |
| 8 | +crates=($(cargo metadata --format-version=1 --no-deps | jq -r '.packages[].name' | grep '^huff-neo' | sort)) |
| 9 | + |
| 10 | +# Array of crates to exclude |
| 11 | +# Used with the `contains` function. |
| 12 | +# shellcheck disable=SC2034 |
| 13 | +exclude_crates=( |
| 14 | + "huff-neo-test-runner" |
| 15 | +) |
| 16 | + |
| 17 | +# Array to hold the results |
| 18 | +results=() |
| 19 | +# Flag to track if any command fails |
| 20 | +any_failed=0 |
| 21 | + |
| 22 | +# Function to check if a value exists in an array |
| 23 | +contains() { |
| 24 | + local array="$1[@]" |
| 25 | + local seeking=$2 |
| 26 | + local in=1 |
| 27 | + for element in "${!array}"; do |
| 28 | + if [[ "$element" == "$seeking" ]]; then |
| 29 | + in=0 |
| 30 | + break |
| 31 | + fi |
| 32 | + done |
| 33 | + return $in |
| 34 | +} |
| 35 | + |
| 36 | +for crate in "${crates[@]}"; do |
| 37 | + if contains exclude_crates "$crate"; then |
| 38 | + results+=("3:⏭️:$crate") |
| 39 | + continue |
| 40 | + fi |
| 41 | + |
| 42 | +export RUSTFLAGS='--cfg getrandom_backend="wasm_js"' |
| 43 | +cmd="cargo +stable build -p $crate --target wasm32-unknown-unknown --no-default-features" |
| 44 | + |
| 45 | + if [ -n "$CI" ]; then |
| 46 | + echo "::group::$cmd" |
| 47 | + else |
| 48 | + printf "\n%s:\n %s\n" "$crate" "$cmd" |
| 49 | + fi |
| 50 | + |
| 51 | + set +e # Disable immediate exit on error |
| 52 | + # Run the command and capture the return code |
| 53 | + $cmd |
| 54 | + ret_code=$? |
| 55 | + set -e # Re-enable immediate exit on error |
| 56 | + |
| 57 | + # Store the result in the dictionary |
| 58 | + if [ $ret_code -eq 0 ]; then |
| 59 | + results+=("1:✅:$crate") |
| 60 | + else |
| 61 | + results+=("2:❌:$crate") |
| 62 | + any_failed=1 |
| 63 | + fi |
| 64 | + |
| 65 | + if [ -n "$CI" ]; then |
| 66 | + echo "::endgroup::" |
| 67 | + fi |
| 68 | +done |
| 69 | + |
| 70 | +# Sort the results by status and then by crate name |
| 71 | +IFS=$'\n' sorted_results=($(sort <<<"${results[*]}")) |
| 72 | +unset IFS |
| 73 | + |
| 74 | +# Print summary |
| 75 | +echo -e "\nSummary of build results:" |
| 76 | +for result in "${sorted_results[@]}"; do |
| 77 | + status="${result#*:}" |
| 78 | + status="${status%%:*}" |
| 79 | + crate="${result##*:}" |
| 80 | + echo "$status $crate" |
| 81 | +done |
| 82 | + |
| 83 | +# Exit with a non-zero status if any command fails |
| 84 | +exit $any_failed |
0 commit comments