Skip to content

Instantly share code, notes, and snippets.

@matt-bailey
Last active January 19, 2018 01:37
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 matt-bailey/bfdaaa290954e1a23f2f to your computer and use it in GitHub Desktop.
Save matt-bailey/bfdaaa290954e1a23f2f to your computer and use it in GitHub Desktop.
Example front-end workflow post-merge Git Hook
#/usr/bin/env bash
# git hook to run a command after `git merge` or `git pull`
# Check for changed files
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
# `npm install` and `npm prune` if the `package.json` file gets changed
echo "--- Updating Node packages..."
check_run package.json "(cd theme; npm install && npm prune)"
echo -e "\xE2\x9C\x93 Node packages updated"
# `bower install` and `bower prune` if the `bower.json` file gets changed
echo "--- Updating Bower components..."
check_run bower.json "(cd themes; bower install --allow-root && bower prune --allow-root)"
echo -e "\xE2\x9C\x93 Bower components updated"
# Run the build process `grunt`
echo "--- Running the build process..."
(cd theme; grunt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment