#!/usr/bin/env bash set -ueo pipefail export RUSTFLAGS="--deny warnings" TEMP_DIR="$(mktemp -d)" MAIN_DIR="$(pwd)" cleanup() { rm -fr "$TEMP_DIR" } trap cleanup EXIT # Set up directory with only what's being committed, and go there. git archive HEAD | tar -x -C "$TEMP_DIR" git diff --cached --binary | (cd "$TEMP_DIR" && git apply) cd "$TEMP_DIR" # Regular fmt check. cargo fmt -- --check || { echo "Run: cargo fmt" >&2 exit 1 } # Test. export CARGO_TARGET_DIR="$MAIN_DIR/target/test.normal" cargo test || { echo "Tests fail without features" >&2 exit 1 } # Test with all features. export CARGO_TARGET_DIR="$MAIN_DIR/target/test.all" cargo test --all-features || { echo "Tests fail with features" >&2 exit 1 } # Build with nightly. # TODO: maybe add --all-targets export CARGO_TARGET_DIR="$MAIN_DIR/target/nightly" cargo +nightly 2>/dev/null > /dev/null && { cargo +nightly bench --no-run -F rtlsdr || { echo "Benchmark builds fail" >&2 exit 1 } cargo +nightly clippy -- -D warnings || { echo "Clippy fail" >&2 exit 1 } } || echo "Skipping nightly, because not installed" if [[ ${AI_REVIEW:-} = true ]]; then exec < /dev/tty CODEBOT=codebot if which "${CODEBOT}" > /dev/null; then echo "---------------- AI reviewer -------------------" git diff HEAD | "$CODEBOT" -s 'you are a code reviewer. Find any problems that this code change could cause, any mistakes, or other suggestions for improvements' echo "--------- Still want to go ahead? y/n ----------" read A if [[ ! $A = "y" ]]; then exit 1 fi fi fi