keep-a-changelog-new-release/.githooks/pre-commit

16 lines
808 B
Bash
Executable File

#!/usr/bin/env bash
# This commit hook checks whether we ran `yarn build` when committed TypeScript files.
# For GitHub actions to work, we need to check the compiled JavaScript into VCS.
#
# This script can yield false positives in cases where you only make stylistic changes to the TypeScript code that don't result in changes to the compiled JavaScript code.
# It is your responsibility as a developer to then commit the changes with `git commit --no-verify` and simply skip this commit hook.
TS_FILES=$(git diff --staged --name-only | grep '\.ts' | grep -cv '__tests__')
DIST_MODIFIED=$(git diff --staged --name-only | grep -c dist/index.js)
if [ "$TS_FILES" -gt 0 ] && [ "$DIST_MODIFIED" -eq 0 ] ; then
echo "You modified TypeScript files but apparently did not run 'yarn build'".
exit 1;
fi