telegram-bot-bash/dev/hooks/pre-push.sh
2019-04-25 13:54:31 +02:00

42 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-23-ga7d14f6
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script
GIT_DIR=$(git rev-parse --git-dir)
cd "$GIT_DIR/.." || exit 1
export HOOKDIR="dev/hooks"
LASTPUSH='.git/.lastpush'
REMOTEVER="$(git ls-remote -t --refs 2>/dev/null | tail -1 | sed 's/.*\/v//')"
VERSION="$(git describe --tags | sed -e 's/-.*//' -e 's/v//')"
# if any command inside script returns error, exit and return that error
set -e
echo "Running pre-push hook"
echo "............................"
unset IFS; set -f
# LOCAL version must greater than latest REMOTE release version
if (( $(echo "${VERSION} > ${REMOTEVER}" | bc -l) )); then
# update version in bashbot files on push
set +f
[ -f "${LASTPUSH}" ] && LASTFILES="$(find ./* -newer "${LASTPUSH}")"
[ "${LASTFILES}" = "" ] && exit
echo -n " "
# shellcheck disable=SC2086
dev/version.sh ${LASTFILES} 2>/dev/null || exit 1
echo " OK"
else
echo "Error: local version ${VERSION} must be greater than latest release version."
echo "use \"git tag ...\" to create a local version greater than ${REMOTEVER}"
exit 1
fi
# note date of last push for version
touch "${LASTPUSH}"