set -Eeuo pipefail
NULL_SHA=$(git hash-object --stdin </dev/null | sed 's/./0/g')
commits=()
while read -r _ local_sha _ _; do
if [[ "$local_sha" != "$NULL_SHA" ]] && [[ " ${commits[*]-} " != *" $local_sha "* ]]; then
commits+=("$local_sha")
fi
done
GIT_ROOT=$(git rev-parse --show-toplevel)
export CARGO_TARGET_DIR="${GIT_ROOT}/target"
source "${GIT_ROOT}/scripts/lib-changed-paths.sh"
WORKDIR=$(mktemp -d)
trap 'rm -rf "$WORKDIR"' EXIT SIGHUP SIGINT SIGQUIT SIGTERM
for commit in ${commits[@]+"${commits[@]}"}; do
if git rev-parse --verify -q origin/main >/dev/null && ! affects_rust origin/main "$commit"; then
echo "Skipping clippy/nextest on $commit: no path affecting a Rust build/test outcome"
continue
fi
tree="$WORKDIR/$commit"
mkdir -p "$tree"
git archive "$commit" | tar -x -C "$tree"
echo "Running cargo clippy on $commit"
(cd "$tree"; cargo clippy --workspace --features internal-testing --all-targets -- --deny warnings)
echo "Running cargo nextest on $commit"
(cd "$tree"; cargo nextest run --workspace --features internal-testing --retries 4 --flaky-result fail)
done