Created
January 23, 2024 17:41
-
-
Save clarkritchie/600297e23a05a629664bfbff20d03b51 to your computer and use it in GitHub Desktop.
Tag
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 | |
# | |
# This is a simple script to create/delete a Git tag in the form vA.B.C-sha | |
# | |
# Usage: | |
# | |
# ./build.sh 0.0.7 | |
# ./build.sh v0.0.7-54477d3 delete -- will delete this tag | |
# | |
# The "v" is automatically prepended and the current sha is appended when the tag is created. | |
# | |
# In the example above, you, a human, have to decide that 0.0.7 is the next version to use | |
# | |
TAG=$1 | |
DELETE=$2 | |
# show tags: | |
# git tag -l | sort -V | |
if [ -z ${TAG} ]; then | |
echo "Missing TAG, usage $0 v0.2.0 [delete]" | |
exit 1 | |
fi | |
if [ -z ${DELETE} ]; then | |
# append the v | |
TAG=v${TAG} | |
# append the current gitsha | |
SHA=$(git rev-parse --short HEAD) | |
TAG=${TAG}-${SHA} | |
read -p "Tag and push as ${TAG}? Are you sure? " -n 1 -r | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
git tag ${TAG} | |
git push origin ${TAG} | |
fi | |
echo "Release tag: $TAG" | |
else | |
read -p "Delete tag ${TAG}? Are you sure? " -n 1 -r | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
git tag -d ${TAG} | |
git push --delete origin ${TAG} | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment