Skip to content

Instantly share code, notes, and snippets.

@Sonictherocketman
Created July 11, 2018 20:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sonictherocketman/b196995f768eda4411e0771e9c509237 to your computer and use it in GitHub Desktop.
Save Sonictherocketman/b196995f768eda4411e0771e9c509237 to your computer and use it in GitHub Desktop.
A pre-commit hook that performs checks based on what is being committed.
#! /bin/bash
# Before we allow a commit, let's first enable preflight.
# To disable this check, set NO_PREFLIGHT=1
# The commit will fail if the preflight checks do.
set -e;
should_check() {
APP=$1
FOUND="-1"
while read file; do
if [[ "$file" = *"$APP"* ]]; then
FOUND="0";
break
fi
done <<< $(git diff --cached --staged --name-only)
echo "$FOUND"
}
## Begin Main ##
if [ -z "$NO_PREFLIGHT" ]; then
cat << EOF
-----------------------------------------------------
Running preflight checks... (this could take a while)
You might want to go get a coffee or talk a walk. ☕️
-----------------------------------------------------
EOF
if [[ $(should_check "api") -eq 0 ]]; then
echo "[$(date)] Linting the API..."
python flake8
echo "[$(date)] Running the API tests..."
pytest
else
echo "[$(date)] Skipping API. Nothing was modified."
fi
if [[ $(should_check "client") -eq 0 ]]; then
echo "[$(date)] Linting the client..."
yarn run lint
echo "[$(date)] Running the client tests..."
yarn run test
else
echo "[$(date)] Skipping client. Nothing was modified."
fi
cat << EOF
-----------------------------------------------------
Done with preflight checks! 🎉🎉🎉
Committing...
-----------------------------------------------------
EOF
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment