Files
mtm-ssh-menu/_release.sh
T

53 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
declare -r VERSION=${1:-}
declare -r MESSAGE=${2:-"Release ${VERSION}"}
declare -r TAGBRANCH=main
declare -r RELEASEBRANCH=dev
declare CURRENTBRANCH=""
showHelp() {
echo "Usage: ./_release.sh <version> [message]"
}
cleanup() {
if [ -n "${CURRENTBRANCH}" ] && [ "${CURRENTBRANCH}" != "$(git rev-parse --abbrev-ref HEAD)" ]; then
git checkout "${CURRENTBRANCH}" >/dev/null 2>&1 || true
fi
}
trap cleanup EXIT
if [ "${VERSION}" == "" ]; then
showHelp
echo ""
echo "No version provided!"
exit 1
fi
CURRENTBRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "${CURRENTBRANCH}" != "${RELEASEBRANCH}" ]; then
echo "You are not on the ${RELEASEBRANCH} branch!"
echo "Use ${RELEASEBRANCH} branch to make a release!"
exit 1
fi
if ! git diff --quiet || ! git diff --cached --quiet; then
echo "Working tree is not clean. Commit or stash your changes first."
exit 1
fi
if git rev-parse -q --verify "refs/tags/${VERSION}" >/dev/null; then
echo "Tag ${VERSION} already exists."
exit 1
fi
git checkout "${TAGBRANCH}"
git merge "${RELEASEBRANCH}"
git push origin "${TAGBRANCH}"
git tag -a "${VERSION}" -m "${MESSAGE}"
git push origin "${VERSION}"