Skip to content

Instantly share code, notes, and snippets.

@clarkritchie
Created January 23, 2024 17:41
Show Gist options
  • Save clarkritchie/600297e23a05a629664bfbff20d03b51 to your computer and use it in GitHub Desktop.
Save clarkritchie/600297e23a05a629664bfbff20d03b51 to your computer and use it in GitHub Desktop.
Tag
#!/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