Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added standard pre-commit script that runs formatting, clippy and tests. #17

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added standard pre-commit script that runs formatting, clippy and tests.
tfenne committed Oct 27, 2022
commit d80dc1451f8dfe767e9595c5472842367c2abce8
55 changes: 55 additions & 0 deletions precommit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

###############################################################################
# Script that should be run pre-commit after making any changes.
###############################################################################

set -e

failures=""

function banner() {
echo
echo "================================================================================"
echo $*
echo "================================================================================"
echo
}

#####################################################################
# Takes two parameters, a "name" and a "command".
# Runs the command and prints out whether it succeeded or failed, and
# also tracks a list of failed steps in $failures.
#####################################################################
function run() {
local name=$1
local cmd=$2

banner "Running $name"
set +e
$cmd
exit_code=$?
set -e

if [[ $exit_code == 0 ]]; then
echo Passed $name
else
echo Failed $name
if [ -z "$failures" ]; then
failures="$name"
else
failures="$failures, $name"
fi
fi
}

run "cargo fmt" "cargo fmt --all"
run "cargo clippy" "cargo clippy --all-features --locked -- -D warnings"
run "cargo test" "cargo test --locked --quiet"

if [ -z "$failures" ]; then
banner "Precommit Passed"
else
banner "Precommit Failed with failures in: $failures"
exit 1
fi