philomena/post-receive

49 lines
1.4 KiB
Text
Raw Permalink Normal View History

#!/usr/bin/env bash
# Set up environment
source ~/bin/philomena-env
read oldrev newrev ref
echo "Updating $oldrev -> $newrev ($ref)"
# Clear variable set to '.' so git commands don't complain
unset GIT_DIR
2019-12-07 19:04:44 +01:00
cd ~/philomena
2019-12-07 19:04:04 +01:00
die() {
echo "$*" 1>&2
exit 1
}
2020-06-17 13:32:29 +02:00
if git diff --name-only $oldrev $newrev | grep -Ee "^mix.(exs|lock)"; then
echo "Fetching deps"
mix deps.get || die "mix failed to update"
fi
# Compile assets
if git diff --name-only $oldrev $newrev | grep "^assets/"; then
echo "Compiling assets"
2020-03-26 18:25:22 +01:00
npm install --prefix ./assets || die "assets install failed"
npm run deploy --prefix ./assets
mix phx.digest || die "assets compile failed"
fi
echo "Building release"
2020-08-03 21:37:02 +02:00
mix release --overwrite || die "failed to generate release"
# Run migrations
if git diff --name-only $oldrev $newrev | grep "^priv/repo/migrations"; then
echo "Running database migrations"
_build/prod/rel/philomena/bin/philomena eval "Philomena.Release.migrate()" || die "ecto.migrate failed"
fi
2020-08-03 21:37:02 +02:00
# Include a task to restart your running appserver instances here.
#
# In general, you should have many app instances configured on different
# ports using the PORT environment variable, so as to allow you to roll
# releases and deploy new code with no visible downtime.
#
# You can use a reverse proxy like haproxy or nginx to load balance between
# different server instances automatically.