Skip to content

Instantly share code, notes, and snippets.

@benmatselby
Last active November 12, 2022 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benmatselby/0434e99471ea1bd071d9fff28e2a0231 to your computer and use it in GitHub Desktop.
Save benmatselby/0434e99471ea1bd071d9fff28e2a0231 to your computer and use it in GitHub Desktop.
Example pre-commit hook
#!/usr/bin/env bash
#
# Git pre-commit hook
#
# Colours https://misc.flogisoft.com/bash/tip_colors_and_formatting
reset=$'\e[0m'
red=$'\e[1;31m'
##
# The Makefile target runner
##
function runTarget {
target="${1}"
printf '\n🏃‍♀️ [EXEC] Running target: %s\n' "${target}"
if ! make "${target}"; then
printf '🔴 [FAIL] %s\n' "${target}"
exit 1
fi
printf '\n\n\n'
}
##
# General targets irrelevant of changes made.
# - Must be quick
# - Run for many areas of the codebase
##
TARGETS=(
lint
test
)
for target in "${TARGETS[@]}"; do runTarget "${target}"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment