Skip to content

Instantly share code, notes, and snippets.

@jamlfy
Last active August 21, 2018 15:31
Show Gist options
  • Save jamlfy/25602854f4947cb3cdbc18c331c82d31 to your computer and use it in GitHub Desktop.
Save jamlfy/25602854f4947cb3cdbc18c331c82d31 to your computer and use it in GitHub Desktop.
Auto Build in git
#/usr/bin/env bash
# MIT © Alejo Next
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
##
# check_run()
# check if a file has changed, if so, evaluate given command
# args:
# $1 - fileNameRegex - file name regex to check
# $2 - command - command to execute
check_run() {
fileNameRegex="$1"
command="$2"
if echo "$changed_files" | grep --quiet "$fileNameRegex"; then
echo " * changes detected in $fileNameRegex"
echo " * executing '$command'"
eval "$command";
fi
}
check_run package.json "yarn install"
# Run build
yarn build:test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment