Update release script to check for existing tag before creating a new one

This commit is contained in:
Riccardo Rigutini 2024-09-29 16:32:50 +00:00 committed by GitHub
parent ee7d438581
commit 90f50c603e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 25 additions and 2 deletions

27
script/release Normal file → Executable file
View File

@ -11,8 +11,9 @@
# #
# 1. Get the latest release tag # 1. Get the latest release tag
# 2. Prompt the user for a new release tag # 2. Prompt the user for a new release tag
# 3. Tag the new release # 3. Check if the tag exists and ask for confirmation to overwrite
# 4. Push the new tag to the remote # 4. Tag the new release
# 5. Push the new tag to the remote
# #
# Usage: # Usage:
# #
@ -49,6 +50,28 @@ else
exit 1 exit 1
fi 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 # Tag the new release
git tag -a "$new_tag" -m "$new_tag Release" git tag -a "$new_tag" -m "$new_tag Release"
echo -e "${GREEN}Tagged: $new_tag${OFF}" echo -e "${GREEN}Tagged: $new_tag${OFF}"