Skip to content

Instantly share code, notes, and snippets.

@unRob
Created July 21, 2014 07:05
Show Gist options
  • Save unRob/fe15e82513ea4dcbffa3 to your computer and use it in GitHub Desktop.
Save unRob/fe15e82513ea4dcbffa3 to your computer and use it in GitHub Desktop.
Rails post-pull
#!/usr/bin/env bash
# Checa si cambiaron (Gemfile|.e?rb|css|js) y reinicia/compila/instala madres
# guárdame como .git/hooks/post-merge
HOOKDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
GITDIR="$(dirname $HOOKDIR)"
REPODIR="$(dirname $GITDIR)"
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
# changed_files="$(git diff-tree -r --name-only --no-commit-id HEAD HEAD^)"
runif() {
#esto si jala con las variables exportadas, al parecer
changed "$1" && eval "$2"
}
changed() {
echo "$changed_files" | egrep --quiet "$1"
}
export BUNDLE_GEMFILE=/data/domains/favc/Gemfile
export RAILS_ENV=production
restart=false
if changed "Gemfile"; then
restart=true
echo "Installing dependencies"
bundle install --deployment
fi
if changed "\.(s?css|js|coffee)$"; then
echo "Compiling assets"
restart=true
bundle exec rake assets:precompile
fi
if changed ".e?rb" || restart; then
echo "Restarting app"
touch $REPODIR/tmp/restart.txt
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment