Last active
December 14, 2015 19:29
-
-
Save uri/a1ea4511da44bad452e6 to your computer and use it in GitHub Desktop.
A post-commit hook that will check for changed assets and ask if they should be compiled.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ASSET_FILES="$(git diff-index --name-only HEAD~ | egrep '.+\.(?:js|css|jpg|jpeg|png|gif)' | grep -v 'public/')" | |
if [[ ! -z $ASSET_FILES ]] ; then | |
echo 'You have changed the following assets that need to be compiled:' | |
echo $ASSET_FILES | |
# Allows us to read user input below, assigns stdin to keyboard | |
exec < /dev/tty | |
read -p "Are you sure? " -r | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]] ; then | |
echo "Starting compilation..." | |
RAILS_ENVIRONMENT=production bundle exec rake assets:precompile | |
RAILS_ENVIRONMENT=production bundle exec rake assets:clean | |
git add -A | |
git commit --no-verify -m "Precompiled assets [ci skip]" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install
WARNING: This will overwrite your exist post-commit if you had one.
Go into a project that is using git.
curl https://gist.githubusercontent.com/uri/a1ea4511da44bad452e6/raw/99e356726626496f6f71805f65f88fcedaea0898/post-commit > .git/hooks/post-commit chmod +x .git/hooks/post-commit
Uninstall