|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -eux
|
|
|
|
|
|
|
|
if test "$#" -gt 1; then
|
|
|
|
echo >&2 "Usage: $0 [branch]"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check that worktree is clean
|
|
|
|
if test -n "$(git status --porcelain)"; then
|
|
|
|
echo >&2 "FATAL: Tree not clean, refusing to deploy"
|
|
|
|
echo "Hint: This is current \`git status\`:"
|
|
|
|
git status
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test "$#" -eq 1; then
|
|
|
|
branch="$1"
|
|
|
|
else
|
|
|
|
branch=master
|
|
|
|
fi
|
|
|
|
|
|
|
|
# TODO: When deployment is new enough, use the top command.
|
|
|
|
#currentbranch="$(git branch --show-current)"
|
|
|
|
currentbranch="$(git rev-parse --abbrev-ref HEAD)"
|
|
|
|
|
|
|
|
# If we are not on target branch, switch and run again
|
|
|
|
if test "$currentbranch" '!=' "$branch"; then
|
|
|
|
exec /bin/sh -eu -c "git checkout $branch && git pull && exec $0 $branch"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Deploying branch $branch"
|
|
|
|
|
|
|
|
### Deploying starts here ###
|
|
|
|
|
|
|
|
git pull
|
|
|
|
. venv/bin/activate
|
|
|
|
pip install -U pip setuptools
|
|
|
|
pip install -r requirements.txt
|
|
|
|
./manage.py migrate
|
|
|
|
./manage.py collectstatic --no-input
|
|
|
|
systemctl --user restart wish.service
|
|
|
|
# TODO: Self-checks? i.e. ./manage.py --check and ./manage.py test?
|
|
|
|
echo # Just a blank line
|
|
|
|
echo '=== Deploy successful ==='
|