#!/usr/bin/env bash set -euo pipefail mode="${1:-fast}" stable_toolchain="${2:-1.88.0}" nightly_toolchain="${3:-nightly}" nextest_version="${NEXTEST_VERSION:-0.9.114}" cargo_deny_version="${CARGO_DENY_VERSION:-0.19.8}" cargo_udeps_version="${CARGO_UDEPS_VERSION:-0.1.61}" git_cliff_version="${GIT_CLIFF_VERSION:-2.13.1}" cargo_semver_checks_version="${CARGO_SEMVER_CHECKS_VERSION:-0.44.0}" if [ -f "${HOME}/.cargo/env" ]; then # shellcheck disable=SC1091 source "${HOME}/.cargo/env" fi command -v cargo >/dev/null 2>&1 || { echo "cargo is required to install CI tools" >&2 exit 1 } export CARGO_BUILD_JOBS="${CARGO_BUILD_JOBS:-1}" install_nextest() { local cargo_home cargo_home="${CARGO_HOME:-${HOME}/.cargo}" if cargo nextest --version 2>/dev/null | grep -q " ${nextest_version}"; then return fi curl -LsSf "https://get.nexte.st/${nextest_version}/linux" \ | tar zxf - -C "${cargo_home}/bin" } install_with_binary_fallback() { local toolchain="$1" local crate="$2" shift 2 if command -v cargo-binstall >/dev/null 2>&1; then cargo binstall -y "${crate}" "$@" && return fi cargo +"${toolchain}" install --locked --force --jobs "${CARGO_BUILD_JOBS}" "${crate}" "$@" } tool_has_version() { local command_name="$1" local expected_version="$2" "${command_name}" --version 2>/dev/null | grep -q " ${expected_version}" } install_nextest if ! tool_has_version git-cliff "${git_cliff_version}"; then install_with_binary_fallback "${stable_toolchain}" git-cliff --version "${git_cliff_version}" fi if [ "${mode}" = "strict" ]; then if ! tool_has_version cargo-deny "${cargo_deny_version}"; then install_with_binary_fallback "${stable_toolchain}" cargo-deny --version "${cargo_deny_version}" fi if ! cargo +"${nightly_toolchain}" udeps --version 2>/dev/null | grep -q " ${cargo_udeps_version}"; then install_with_binary_fallback "${nightly_toolchain}" cargo-udeps --version "${cargo_udeps_version}" fi if ! tool_has_version cargo-semver-checks "${cargo_semver_checks_version}"; then install_with_binary_fallback "${stable_toolchain}" cargo-semver-checks --version "${cargo_semver_checks_version}" fi fi cargo nextest --version git-cliff --version if [ "${mode}" = "strict" ]; then cargo deny --version cargo +"${nightly_toolchain}" udeps --version cargo semver-checks --version fi