improve var names and comments

This commit is contained in:
Paul Ebose 2024-07-01 17:21:55 +01:00
parent 6590bf4e0c
commit 8ca79d7247
No known key found for this signature in database
GPG Key ID: 2FF647AADFAC0FE8

View File

@ -23,17 +23,17 @@ set -e
# 7. Set 'is_major_release' variable
# 8. Point separate major release tag (e.g. v1, v2) to the new release
# 9. Push the new tags (with commits, if any) to remote
# 10. If this is a major release, create a 'releases/(latest_major_tag)' branch and push
# 10. If this is a major release, create a 'releases/v#' branch and push
#
# Usage:
#
# script/release
# Variables
tag_regex='v[0-9]+\.[0-9]+\.[0-9]+$'
tag_glob='v[0-9].[0-9].[0-9]*'
semver_tag_regex='v[0-9]+\.[0-9]+\.[0-9]+$'
semver_tag_glob='v[0-9].[0-9].[0-9]*'
git_remote='origin'
major_tag_regex='\(v[0-9]*\)'
major_semver_tag_regex='\(v[0-9]*\)'
# Terminal colors
OFF='\033[0m'
@ -45,7 +45,7 @@ BOLD_UNDERLINED='\033[1;4m'
BOLD='\033[1m'
# 1. Retrieve the latest release tag
if ! latest_tag=$(git describe --abbrev=0 --match="$tag_glob"); then
if ! latest_tag=$(git describe --abbrev=0 --match="$semver_tag_glob"); then
# There are no existing release tags
echo -e "No tags found (yet) - Continue to create and push your first tag"
latest_tag="[unknown]"
@ -58,7 +58,7 @@ echo -e "The latest release tag is: ${BOLD_BLUE}${latest_tag}${OFF}"
read -r -p 'Enter a new release tag (vX.X.X format): ' new_tag
# 4. Validate the new release tag
if echo "$new_tag" | grep -q -E "$tag_regex"; then
if echo "$new_tag" | grep -q -E "$semver_tag_regex"; then
# Release tag is valid
echo -e "Tag: ${BOLD_BLUE}$new_tag${OFF} is valid syntax"
else
@ -82,10 +82,10 @@ git tag "$new_tag" --annotate --message "$new_tag Release"
echo -e "Tagged: ${BOLD_GREEN}$new_tag${OFF}"
# 7. Set 'is_major_release' variable
latest_major_tag=$(expr "$latest_tag" : "$major_tag_regex")
new_major_tag=$(expr "$new_tag" : "$major_tag_regex")
latest_major_release_tag=$(expr "$latest_tag" : "$major_semver_tag_regex")
new_major_release_tag=$(expr "$new_tag" : "$major_semver_tag_regex")
if ! [[ "$new_major_tag" = "$latest_major_tag" ]]; then
if ! [[ "$new_major_release_tag" = "$latest_major_release_tag" ]]; then
is_major_release='yes'
else
is_major_release='no'
@ -93,13 +93,13 @@ fi
# 8. Point separate major release tag (e.g. v1, v2) to the new release
if [ $is_major_release = 'yes' ]; then
# Create a new major verison tag and point to this release
git tag "$new_major_tag" --annotate --message "$new_major_tag Release"
echo -e "New major version tag: ${BOLD_GREEN}$new_major_tag${OFF}"
# Create a new major verison tag and point it to this release
git tag "$new_major_release_tag" --annotate --message "$new_major_release_tag Release"
echo -e "New major version tag: ${BOLD_GREEN}$new_major_release_tag${OFF}"
else
# Update the major verison tag to point to this release
git tag "$latest_major_tag" --force --annotate --message "Sync $latest_major_tag tag with $new_tag"
echo -e "Synced ${BOLD_GREEN}$latest_major_tag${OFF} with ${BOLD_GREEN}$new_tag${OFF}"
# Update the major verison tag to point it to this release
git tag "$latest_major_release_tag" --force --annotate --message "Sync $latest_major_release_tag tag with $new_tag"
echo -e "Synced ${BOLD_GREEN}$latest_major_release_tag${OFF} with ${BOLD_GREEN}$new_tag${OFF}"
fi
# 9. Push the new tags (with commits, if any) to remote
@ -107,19 +107,19 @@ git push --follow-tags
if [ $is_major_release = 'yes' ]; then
# New major version tag is pushed with the '--follow-tags' flags
echo -e "Tags: ${BOLD_GREEN}$new_major_tag${OFF} and ${BOLD_GREEN}$new_tag${OFF} pushed to remote"
echo -e "Tags: ${BOLD_GREEN}$new_major_release_tag${OFF} and ${BOLD_GREEN}$new_tag${OFF} pushed to remote"
else
# Force push the updated major version tag
git push $git_remote "$latest_major_tag" --force
echo -e "Tags: ${BOLD_GREEN}$latest_major_tag${OFF} and ${BOLD_GREEN}$new_tag${OFF} pushed to remote"
git push $git_remote "$latest_major_release_tag" --force
echo -e "Tags: ${BOLD_GREEN}$latest_major_release_tag${OFF} and ${BOLD_GREEN}$new_tag${OFF} pushed to remote"
fi
# 10. If this is a major release, create a 'releases/(latest_major_tag)' branch and push
# 10. If this is a major release, create a 'releases/v#' branch and push
if [ $is_major_release = 'yes' ]; then
git branch "releases/$latest_major_tag" "$latest_major_tag"
echo -e "Branch: ${BOLD_BLUE}releases/$latest_major_tag${OFF} created from ${BOLD_BLUE}$latest_major_tag${OFF} tag"
git push --set-upstream $git_remote "releases/$latest_major_tag"
echo -e "Branch: ${BOLD_GREEN}releases/$latest_major_tag${OFF} pushed to remote"
git branch "releases/$latest_major_release_tag" "$latest_major_release_tag"
echo -e "Branch: ${BOLD_BLUE}releases/$latest_major_release_tag${OFF} created from ${BOLD_BLUE}$latest_major_release_tag${OFF} tag"
git push --set-upstream $git_remote "releases/$latest_major_release_tag"
echo -e "Branch: ${BOLD_GREEN}releases/$latest_major_release_tag${OFF} pushed to remote"
fi
# Completed