CI: Check for required commands

Add a function to check for commands used by the `run_task` script. Move
the version printing to after the check. Also print the bash version in
use.
This commit is contained in:
Tobin C. Harding 2024-02-01 12:01:43 +11:00
parent 5c15ed5441
commit 01a66a7fa7
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 30 additions and 5 deletions

View File

@ -5,13 +5,18 @@ set -ex
# Make all cargo invocations verbose.
export CARGO_TERM_VERBOSE=true
cargo --version
rustc --version
main() {
crate="$1"
task="$2"
check_required_commands
cargo --version
rustc --version
/usr/bin/env bash --version
locale
env
cd "$crate"
# Building the fuzz crate is more-or-less just a sanity check.
@ -65,8 +70,7 @@ main() {
do_schemars
;;
*)
echo "Error: unknown task $task" >&2
exit 1
err "Error: unknown task $task"
;;
esac
}
@ -222,6 +226,27 @@ do_schemars() {
cargo test
}
# Check all the commands we use are present in the current environment.
check_required_commands() {
need_cmd cargo
need_cmd rustc
need_cmd jq
need_cmd cut
need_cmd grep
need_cmd wc
}
need_cmd() {
if ! command -v "$1" > /dev/null 2>&1
then err "need '$1' (command not found)"
fi
}
err() {
echo "$1" >&2
exit 1
}
#
# Main script
#