diff --git a/justfile b/justfile new file mode 100644 index 0000000..6d3f3d8 --- /dev/null +++ b/justfile @@ -0,0 +1,18 @@ +export RUST_BACKTRACE := "1" +alias s:= setup +alias h:= set-hooks +alias c:= clean + +@setup: + # rustup install nightly + rustup component add clippy-preview + pip install pre-commit + just h + cargo build + +@clean: + rm -rf pkg target dist + +@set-hooks: + pre-commit + bash ./scripts/pre-push \ No newline at end of file diff --git a/scripts/pre-push b/scripts/pre-push new file mode 100644 index 0000000..35cff7d --- /dev/null +++ b/scripts/pre-push @@ -0,0 +1,42 @@ +#!/bin/bash + +GREEN="\e[1;32m" +RED="\e[31m" +CYAN="\e[36m" +ENDCOLOR="\e[0m" + +read -p "Would you like to run tests & clippy before you push remotely ? (y/n): " choice +if [ "$choice" != "y" ]; then + echo -e "${CYAN}pre-push hook will not be installed ${ENDCOLOR}" + exit 0 +else + cat <> .git/hooks/pre-push +#!/bin/bash +set -e + +echo "Running tests.." + +cargo test + +if [ \$? -ne 0 ]; then + echo -e "${RED}hook failed, push aborted! ${ENDCOLOR}" + exit 1 +fi + +echo "Running Clippy.." +cargo clippy -- -D warnings -A incomplete_features -W clippy::dbg_macro -W clippy::print_stdout + +if [ \$? -ne 0 ]; then + + echo -e "${RED}pre-push checks failed! ${ENDCOLOR}" + + exit 1 +else + echo -e "${GREEN}pre-push checks went successful!${ENDCOLOR}" +fi +exit 0 + +EOF + chmod +x .git/hooks/pre-push + printf "${GREEN}pre-push hook installed!${ENDCOLOR}" +fi