chore: add release automation script
This commit is contained in:
Executable
+52
@@ -0,0 +1,52 @@
|
|||||||
|
#!/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}"
|
||||||
Reference in New Issue
Block a user