#!/bin/bash # Exit early # See: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#The-Set-Builtin set -e # About: # # 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 # # This script will do the following: # # 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 # # Usage: # # script/release # Variables tag_regex='v[0-9]+\.[0-9]+\.[0-9]+$' tag_glob='v[0-9].[0-9].[0-9]*' # Terminal colors OFF='\033[0m' BOLD_RED='\033[1;31m' BOLD_GREEN='\033[1;32m' BOLD_BLUE='\033[1;34m' BOLD_PURPLE='\033[1;35m' BOLD_UNDERLINED='\033[1;4m' BOLD='\033[1m' # Get the latest release tag if ! latest_tag=$(git describe --abbrev=0 --match="$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]" fi # Display the latest release tag echo -e "The latest release tag is: ${BOLD_BLUE}${latest_tag}${OFF}" # 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 if echo "$new_tag" | grep -q -E "$tag_regex"; then # Release tag is valid echo -e "Tag: ${BOLD_BLUE}$new_tag${OFF} is valid syntax" else # Release tag is not `vX.X.X` format echo -e "Tag: ${BOLD_BLUE}$new_tag${OFF} is ${BOLD_RED}not valid${OFF} (must be in ${BOLD}vX.X.X${OFF} format)" exit 1 fi # 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 # Tag the new release git tag "$new_tag" --annotate --message "$new_tag Release" echo -e "Tagged: ${BOLD_GREEN}$new_tag${OFF}" # Push the new tag to the remote git push --follow-tags echo -e "Tags: ${BOLD_GREEN}$new_tag${OFF} pushed to remote" echo -e "${BOLD_GREEN}Done!${OFF}"