2021-11-29 08:07:17 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2022-03-11 18:38:32 +00:00
|
|
|
source .utils
|
|
|
|
|
2021-11-29 08:07:17 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
print_usage() {
|
2022-03-11 18:38:32 +00:00
|
|
|
orange "gs-release - create a new release of a Giant Swarm repo"
|
2021-11-29 08:07:17 +00:00
|
|
|
echo " "
|
2022-03-11 18:38:32 +00:00
|
|
|
underline "Usage:"
|
2021-11-29 08:07:17 +00:00
|
|
|
echo "gs-release [SEMVER LEVEL]"
|
|
|
|
echo " "
|
|
|
|
echo " "
|
2022-03-11 18:38:32 +00:00
|
|
|
underline "Options:"
|
2021-11-29 08:07:17 +00:00
|
|
|
echo "-h, --help show this help text"
|
|
|
|
}
|
|
|
|
|
|
|
|
while test $# -gt 0; do
|
|
|
|
case "$1" in
|
|
|
|
-h|--help)
|
|
|
|
print_usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
SEMVER=$1
|
|
|
|
|
2022-03-01 11:48:47 +00:00
|
|
|
CURRENT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
2021-11-29 08:07:17 +00:00
|
|
|
MAIN_BRANCH=$(git remote show origin 2>/dev/null|grep HEAD|sed 's/.* //')
|
|
|
|
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
|
|
|
|
|
|
|
|
if [ "$MAIN_BRANCH" != "$CURRENT_BRANCH" ]; then
|
|
|
|
echo "Not currently on main branch, please switch to ${MAIN_BRANCH} to perform a release"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
VERSION_PARTS=($(echo $CURRENT_TAG | tr "." "\n"))
|
2021-12-17 07:25:45 +00:00
|
|
|
VERSION_MAJOR=${VERSION_PARTS[0]}
|
|
|
|
VERSION_MINOR=${VERSION_PARTS[1]}
|
|
|
|
VERSION_PATCH=${VERSION_PARTS[2]}
|
2021-11-29 08:07:17 +00:00
|
|
|
|
|
|
|
echo "The latest released version is ${CURRENT_TAG}"
|
|
|
|
echo ""
|
|
|
|
|
2022-01-19 11:18:11 +00:00
|
|
|
echo "The release will include:"
|
|
|
|
sed -n "/^## \[Unreleased\]$/,/^## /p" CHANGELOG.md | tail -n +3 | tail -r | tail -n +2 | tail -r | sed "s/^/ /g"
|
|
|
|
echo ""
|
|
|
|
|
2021-11-29 08:07:17 +00:00
|
|
|
if [[ "$SEMVER" == "" ]]; then
|
|
|
|
printf "What semver release level? (patch, minor or major): "
|
|
|
|
read SEMVER
|
|
|
|
fi
|
|
|
|
|
|
|
|
case ${SEMVER} in
|
|
|
|
patch)
|
|
|
|
VERSION_PATCH=$((VERSION_PATCH+1))
|
|
|
|
;;
|
|
|
|
|
|
|
|
minor)
|
|
|
|
VERSION_MINOR=$((VERSION_MINOR+1))
|
|
|
|
VERSION_PATCH=0
|
|
|
|
;;
|
|
|
|
|
|
|
|
major)
|
|
|
|
if [[ ${VERSION_MAJOR:0:1} == "v" ]]; then
|
|
|
|
VERSION_MAJOR="v$((VERSION_MAJOR+1))"
|
|
|
|
else
|
|
|
|
VERSION_MAJOR=$((VERSION_MAJOR+1))
|
|
|
|
fi
|
|
|
|
VERSION_MINOR=0
|
|
|
|
VERSION_PATCH=0
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
echo "Unknown Semver level provided"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
NEW_VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
|
|
|
|
NEW_BRANCH="${MAIN_BRANCH}#release#${NEW_VERSION}"
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ "
|
|
|
|
echo "Current version ${CURRENT_TAG}"
|
|
|
|
echo " New version ${NEW_VERSION}"
|
|
|
|
echo " Release branch ${NEW_BRANCH}"
|
|
|
|
echo "✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ ✨ "
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
printf "Confirm? (y/n): "
|
|
|
|
read CONFIRM
|
|
|
|
|
|
|
|
if [ "${CONFIRM}" = "y" ]; then
|
2022-06-22 08:07:06 +00:00
|
|
|
echo ""
|
2021-11-29 08:07:17 +00:00
|
|
|
echo "Publishing new release branch..."
|
2022-06-22 08:07:06 +00:00
|
|
|
echo ""
|
2021-11-29 08:07:17 +00:00
|
|
|
git checkout -b "${NEW_BRANCH}"
|
|
|
|
git push -u origin "${NEW_BRANCH}"
|
|
|
|
|
|
|
|
ORG_NAME=$(git remote get-url origin | sed 's/.*github.com[:|\/]//' | sed 's/\.git$//' | tr '/' ' ' | awk '{print $1}')
|
|
|
|
REPO_NAME=$(git remote get-url origin | sed 's/.*github.com[:|\/]//' | sed 's/\.git$//' | tr '/' ' ' | awk '{print $2}')
|
|
|
|
|
2022-06-22 08:07:06 +00:00
|
|
|
echo ""
|
|
|
|
echo "🚀 Keep an eye on $(underline "https://github.com/${ORG_NAME}/${REPO_NAME}/pulls") for the new release PR"
|
2022-07-08 06:53:28 +00:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
echo "Switching back to the main git branch"
|
|
|
|
git checkout $(git remote show origin 2>/dev/null|grep HEAD|sed 's/.* //') &> /dev/null
|
|
|
|
git pull &> /dev/null
|
2021-11-29 08:07:17 +00:00
|
|
|
else
|
|
|
|
echo "Aborting..."
|
|
|
|
exit 1
|
|
|
|
fi
|