21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-04-26 05:50:50 +02:00
chexpire/script/to_production
2022-02-13 20:23:58 +01:00

52 lines
1.2 KiB
Bash
Executable file

#!/bin/bash
# Copyright (C) 2018 Colin Darie <colin@darie.eu>, 2018 Evolix <info@evolix.fr>
# License: GNU AGPL-3+ (see full text in LICENSE file)
set -e
[ -n "$DEBUG" ] && set -x
# git name-rev is fail
CURRENT=$(git rev-parse --abbrev-ref HEAD)
TIMESTAMP=$(date +"%s")
echo "👀 Fetching git repository information…"
git fetch origin --quiet
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
CURRENT_HEAD=$(git rev-parse HEAD)
ORIGIN_HEAD=$(git rev-parse origin/master)
if [ "master" != "${CURRENT_BRANCH}" ]; then
echo "😕 Only master can be deployed to production"
exit 1
fi
if [ "${CURRENT_HEAD}" != "${ORIGIN_HEAD}" ]; then
echo "😕 Local master is not up to date with origin"
exit 1
fi
read -p "👉 Deploy master to production ? (y/N) " confirmed
if [ "${confirmed}" != "y" ]; then
echo "😞 Abort, bye."
exit 1
fi
echo "🚀 Deploying ${CURRENT_BRANCH} to production !"
# une branche "production" est (re)initialisée sur le commit courant
git branch -f production
# … et poussée sur le mote "origin"
git push --force origin production
# et le déploiement a lieu
bundle exec cap production deploy
# création du tag
TAG="prod-${TIMESTAMP}-$(logname)"
git tag ${TAG} && git push origin tag ${TAG}
echo "😎 Done !"