From 90f50c603eeb5fa5dc89d1109e87508488290441 Mon Sep 17 00:00:00 2001 From: Riccardo Rigutini <47950599+richardrigutins@users.noreply.github.com> Date: Sun, 29 Sep 2024 16:32:50 +0000 Subject: [PATCH] Update release script to check for existing tag before creating a new one --- script/release | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) mode change 100644 => 100755 script/release diff --git a/script/release b/script/release old mode 100644 new mode 100755 index 500cddf..9a96c34 --- a/script/release +++ b/script/release @@ -11,8 +11,9 @@ # # 1. Get the latest release tag # 2. Prompt the user for a new release tag -# 3. Tag the new release -# 4. Push the new tag to the remote +# 3. Check if the tag exists and ask for confirmation to overwrite +# 4. Tag the new release +# 5. Push the new tag to the remote # # Usage: # @@ -49,6 +50,28 @@ else exit 1 fi +# Check if the tag exists; if it does, ask the user for confirmation to overwrite +if git rev-parse -q --verify "refs/tags/$new_tag" >/dev/null; then + read -r -p "The tag already exists. Overwrite? [y/N] " response + if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then + echo -e "${RED}Aborted${OFF}" + exit 1 + else + # Delete the tag locally + git tag -d "$new_tag" + echo -e "${GREEN}Deleted local tag: $new_tag${OFF}" + # Delete the tag remotely + git push origin --delete "$new_tag" + echo -e "${GREEN}Deleted remote tag: $new_tag${OFF}" + fi +else + read -r -p "The tag does not exist and will be created. Continue? [y/N] " response + if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then + echo -e "${RED}Aborted${OFF}" + exit 1 + fi +fi + # Tag the new release git tag -a "$new_tag" -m "$new_tag Release" echo -e "${GREEN}Tagged: $new_tag${OFF}"