Created
November 13, 2017 12:38
-
-
Save crakaC/b0c4e476889fe3c2149db11b61459382 to your computer and use it in GitHub Desktop.
mastodonを好きなブランチでデプロイするやつ
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 -e | |
if [[ $# -lt 1 ]]; then | |
echo "usage: $0 <target_branch>" 1>&2 | |
exit 1; | |
fi | |
TARGET=$1 | |
if [[ $2 =~ hubot ]]; then | |
ECHO=/home/mastodon/scripts/bot_post.sh | |
else | |
ECHO=echo | |
fi | |
set_deployed_hash(){ | |
git rev-parse --short HEAD > .last_deployed | |
} | |
get_deployed_hash(){ | |
cat .last_deployed | |
} | |
cd ~/live | |
touch .last_deployed | |
git stash | |
git checkout master | |
git fetch origin -p | |
git branch -D $TARGET | |
git checkout -b $TARGET origin/$TARGET | |
last_deployed_hash=`get_deployed_hash` | |
changed_files=`git diff HEAD $last_deployed_hash --name-only` | |
if [[ -n `git stash list` ]]; then | |
git stash pop | |
fi | |
if [[ -z "$changed_files" ]]; then | |
echo "nothing to deploy:($current_hash)" 1>&2 | |
exit 1 | |
fi | |
export RAILS_ENV=production | |
export PATH="/home/mastodon/.rbenv/shims:$PATH" | |
if [[ $changed_files =~ Gemfile ]]; then | |
$ECHO "bundle install" | |
bundle install --deployment --without development test >/dev/null | |
fi | |
if [[ $changed_files =~ yarn.lock ]]; then | |
$ECHO "yarn install" | |
yarn install --pure-lockfile >/dev/null | |
fi | |
if [[ $changed_files =~ db/migrate ]]; then | |
$ECHO "db:migrate" | |
bundle exec rails db:migrate >/dev/null | |
fi | |
if [[ $changed_files =~ \.(js|s?css) ]]; then | |
$ECHO "assets:precompile" | |
bundle exec rails assets:precompile >/dev/null | |
bundle exec rails assets:clean >/dev/null | |
fi | |
sudo systemctl restart mastodon-*.service | |
set_deployed_hash | |
$ECHO <ぴちぴち\(\``get_deployed_hash`\`\) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment