rust/entrypoint.sh
Paul Campbell f710a77230
All checks were successful
/ test (map[name:v1.81.0]) (push) Successful in 46s
/ test (map[name:nightly]) (push) Successful in 2m55s
/ test (map[name:stable]) (push) Successful in 4m54s
feat: only update toolchain if it is 'nightly'
2024-11-14 08:15:15 +00:00

50 lines
1 KiB
Bash
Executable file

#!/usr/bin/env bash
set -e
echo "INPUT_ARGS: ${INPUT_ARGS}"
# split input into an array
read -ra ARGS <<<"${INPUT_ARGS}"
# default toolchain
TOOLCHAIN="stable"
echo "Default toolchain: ${TOOLCHAIN}"
# if first parameter is 'nightly'...
if test "${ARGS[0]}" == "nightly"; then
TOOLCHAIN="nightly"
ARGS=("${ARGS[@]:1}")
echo ">>> Update nightly toolchain"
rustup update "${TOOLCHAIN}"
fi
if test "${ARGS[0]}" == "stable"; then
TOOLCHAIN="stable" # redundant as this is the default
ARGS=("${ARGS[@]:1}")
fi
if [[ "${ARGS[0]}" == v1* ]]; then
TOOLCHAIN="${ARGS[0]:1}"
ARGS=("${ARGS[@]:1}")
fi
echo "Selected toolchain: ${TOOLCHAIN}"
echo ">>> Install rustfmt and clippy"
rustup component add --toolchain "${TOOLCHAIN}" rustfmt clippy
if test "${ARGS[0]}" == "cargo";then
PRE_COMMAND="cargo +${TOOLCHAIN} "
else
PRE_COMMAND="${ARGS[0]}"
fi
ARGS=("${ARGS[@]:1}")
# ensure toolchain is up-to-date
# recombine remaining arguments
COMMAND=$(
IFS=" "
echo "${ARGS[*]}"
)
# execute command
echo ">>> ${PRE_COMMAND} ${COMMAND}"
${PRE_COMMAND} ${COMMAND}