2023-10-31 23:50:45 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-07-01 01:39:31 +00:00
|
|
|
# Exit early
|
|
|
|
# See: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#The-Set-Builtin
|
|
|
|
set -e
|
|
|
|
|
2023-10-31 23:52:55 +00:00
|
|
|
# About:
|
2024-02-01 15:23:43 +00:00
|
|
|
#
|
|
|
|
# This is a helper script to tag and push a new release. GitHub Actions use
|
|
|
|
# release tags to allow users to select a specific version of the action to use.
|
|
|
|
#
|
|
|
|
# See: https://github.com/actions/typescript-action#publishing-a-new-release
|
|
|
|
#
|
2023-10-31 23:52:55 +00:00
|
|
|
# This script will do the following:
|
2024-02-01 15:23:43 +00:00
|
|
|
#
|
2023-10-31 23:52:55 +00:00
|
|
|
# 1. Get the latest release tag
|
2024-02-01 15:23:43 +00:00
|
|
|
# 2. Prompt the user for a new release tag
|
2023-10-31 23:52:55 +00:00
|
|
|
# 3. Tag the new release
|
|
|
|
# 4. Push the new tag to the remote
|
2024-02-01 15:23:43 +00:00
|
|
|
#
|
2023-10-31 23:50:45 +00:00
|
|
|
# Usage:
|
2024-02-01 15:23:43 +00:00
|
|
|
#
|
2023-10-31 23:50:45 +00:00
|
|
|
# script/release
|
|
|
|
|
2024-07-01 01:17:03 +00:00
|
|
|
# Variables
|
|
|
|
tag_regex='v[0-9]+\.[0-9]+\.[0-9]+$'
|
2024-07-01 01:37:14 +00:00
|
|
|
tag_glob='v[0-9].[0-9].[0-9]*'
|
2024-07-01 02:26:29 +00:00
|
|
|
git_remote='origin'
|
|
|
|
major_tag_regex='\(v[0-9]*\)'
|
2024-07-01 01:17:03 +00:00
|
|
|
|
2024-02-01 15:23:43 +00:00
|
|
|
# Terminal colors
|
2023-10-31 23:50:45 +00:00
|
|
|
OFF='\033[0m'
|
2024-07-01 01:42:58 +00:00
|
|
|
BOLD_RED='\033[1;31m'
|
|
|
|
BOLD_GREEN='\033[1;32m'
|
|
|
|
BOLD_BLUE='\033[1;34m'
|
2024-07-01 02:06:46 +00:00
|
|
|
BOLD_PURPLE='\033[1;35m'
|
|
|
|
BOLD_UNDERLINED='\033[1;4m'
|
2024-07-01 02:22:26 +00:00
|
|
|
BOLD='\033[1m'
|
2023-10-31 23:50:45 +00:00
|
|
|
|
2024-02-01 15:23:43 +00:00
|
|
|
# Get the latest release tag
|
2024-07-01 01:39:31 +00:00
|
|
|
if ! latest_tag=$(git describe --abbrev=0 --match="$tag_glob"); then
|
2024-02-22 14:47:59 +00:00
|
|
|
# There are no existing release tags
|
|
|
|
echo -e "No tags found (yet) - Continue to create and push your first tag"
|
|
|
|
latest_tag="[unknown]"
|
2023-10-31 23:55:51 +00:00
|
|
|
fi
|
|
|
|
|
2024-02-01 15:23:43 +00:00
|
|
|
# Display the latest release tag
|
2024-07-01 01:42:58 +00:00
|
|
|
echo -e "The latest release tag is: ${BOLD_BLUE}${latest_tag}${OFF}"
|
2023-11-01 00:15:24 +00:00
|
|
|
|
2024-02-01 15:23:43 +00:00
|
|
|
# Prompt the user for the new release tag
|
|
|
|
read -r -p 'Enter a new release tag (vX.X.X format): ' new_tag
|
|
|
|
|
|
|
|
# Validate the new release tag
|
2023-11-01 00:15:24 +00:00
|
|
|
if echo "$new_tag" | grep -q -E "$tag_regex"; then
|
2024-07-01 02:22:26 +00:00
|
|
|
# Release tag is valid
|
|
|
|
echo -e "Tag: ${BOLD_BLUE}$new_tag${OFF} is valid syntax"
|
2023-11-01 00:15:24 +00:00
|
|
|
else
|
2024-02-22 14:47:59 +00:00
|
|
|
# Release tag is not `vX.X.X` format
|
2024-07-01 02:22:26 +00:00
|
|
|
echo -e "Tag: ${BOLD_BLUE}$new_tag${OFF} is ${BOLD_RED}not valid${OFF} (must be in ${BOLD}vX.X.X${OFF} format)"
|
2024-02-22 14:47:59 +00:00
|
|
|
exit 1
|
2023-10-31 23:50:45 +00:00
|
|
|
fi
|
|
|
|
|
2024-07-01 02:06:46 +00:00
|
|
|
# Remind user to update the version field in package.json
|
|
|
|
echo -e -n "Make sure the version field in package.json is ${BOLD_BLUE}$new_tag${OFF}. Yes? [Y/${BOLD_UNDERLINED}n${OFF}] "
|
|
|
|
read -r YN
|
|
|
|
|
|
|
|
if [[ ! ($YN == "y" || $YN == "Y") ]]; then
|
|
|
|
# Package.json version field is not up to date
|
|
|
|
echo -e "Please update the package.json version to ${BOLD_PURPLE}$new_tag${OFF} and commit your changes"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-02-01 15:23:43 +00:00
|
|
|
# Tag the new release
|
2024-07-01 02:25:01 +00:00
|
|
|
git tag "$new_tag" --annotate --message "$new_tag Release"
|
2024-07-01 02:22:26 +00:00
|
|
|
echo -e "Tagged: ${BOLD_GREEN}$new_tag${OFF}"
|
2023-10-31 23:50:45 +00:00
|
|
|
|
2024-02-01 15:23:43 +00:00
|
|
|
# Push the new tag to the remote
|
2024-07-01 01:41:04 +00:00
|
|
|
git push --follow-tags
|
2024-07-01 02:22:26 +00:00
|
|
|
echo -e "Tags: ${BOLD_GREEN}$new_tag${OFF} pushed to remote"
|
2024-07-01 02:26:29 +00:00
|
|
|
|
|
|
|
# Check if the latest major release tag and the new major release tag are the same
|
|
|
|
latest_major_tag=$(expr "$latest_tag" : "$major_tag_regex")
|
|
|
|
new_major_tag=$(expr "$new_tag" : "$major_tag_regex")
|
|
|
|
|
|
|
|
if [[ "$new_major_tag" = "$latest_major_tag" ]]; then
|
|
|
|
# This is a minor or patch release
|
|
|
|
# Point major release tag (e.g. v1, v2) 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}"
|
|
|
|
# Push major tag to remote
|
|
|
|
git push $git_remote "$latest_major_tag" --force
|
|
|
|
echo -e "Tags: ${BOLD_GREEN}$latest_major_tag${OFF} pushed to remote"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Completed
|
2024-07-01 01:42:58 +00:00
|
|
|
echo -e "${BOLD_GREEN}Done!${OFF}"
|