Created
November 24, 2021 17:57
-
-
Save chmouel/c629fadc83df1df35fd4bab2276d5c1d to your computer and use it in GitHub Desktop.
Bump a release from shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# need python-semver package https://pypi.org/project/semver/ | |
set -euf | |
VERSION=${1-""} | |
bumpversion() { | |
current=$(git describe --tags $(git rev-list --tags --max-count=1)) | |
echo "Current version is ${current}" | |
major=$(python3 -c "import semver,sys;print(str(semver.VersionInfo.parse(sys.argv[1]).bump_major()))" ${current}) | |
minor=$(python3 -c "import semver,sys;print(str(semver.VersionInfo.parse(sys.argv[1]).bump_minor()))" ${current}) | |
patch=$(python3 -c "import semver,sys;print(str(semver.VersionInfo.parse(sys.argv[1]).bump_patch()))" ${current}) | |
echo "If we bump we get, Major: ${major} Minor: ${minor} Patch: ${patch}" | |
read -p "To which version you would like to bump [M]ajor, Mi[n]or, [P]atch or Manua[l]: " ANSWER | |
if [[ ${ANSWER,,} == "m" ]];then | |
mode=major | |
elif [[ ${ANSWER,,} == "n" ]];then | |
mode=minor | |
elif [[ ${ANSWER,,} == "p" ]];then | |
mode=patch | |
elif [[ ${ANSWER,,} == "l" ]];then | |
read -p "Enter version: " -e VERSION | |
return | |
else | |
print "no or bad reply??" | |
exit | |
fi | |
VERSION=$(python3 -c "import semver,sys;print(str(semver.VersionInfo.parse(sys.argv[1]).bump_${mode}()))" ${current}) | |
[[ -z ${VERSION} ]] && { | |
echo "could not bump version automatically" | |
exit | |
} | |
echo "Releasing ${VERSION}" | |
} | |
[[ -z ${VERSION} ]] && bumpversion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment