typescript-action/script/release

60 lines
1.5 KiB
Plaintext
Raw Normal View History

2023-10-31 23:50:45 +00:00
#!/bin/bash
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-02-01 15:23:43 +00:00
# Terminal colors
2023-10-31 23:50:45 +00:00
OFF='\033[0m'
2023-11-01 00:15:24 +00:00
RED='\033[0;31m'
2023-10-31 23:50:45 +00:00
GREEN='\033[0;32m'
BLUE='\033[0;34m'
2024-02-01 15:23:43 +00:00
# Get the latest release tag
2023-11-01 00:02:57 +00:00
latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
if [[ -z "$latest_tag" ]]; 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]"
fi
2024-02-01 15:23:43 +00:00
# Display the latest release tag
2023-10-31 23:50:45 +00:00
echo -e "The latest release tag is: ${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
tag_regex='v[0-9]+\.[0-9]+\.[0-9]+$'
if echo "$new_tag" | grep -q -E "$tag_regex"; then
2024-02-22 14:47:59 +00:00
echo -e "Tag: ${BLUE}$new_tag${OFF} is valid"
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
echo -e "Tag: ${BLUE}$new_tag${OFF} is ${RED}not valid${OFF} (must be in vX.X.X format)"
exit 1
2023-10-31 23:50:45 +00:00
fi
2024-02-01 15:23:43 +00:00
# Tag the new release
2023-11-01 00:15:24 +00:00
git tag -a "$new_tag" -m "$new_tag Release"
2024-02-01 15:23:43 +00:00
echo -e "${GREEN}Tagged: $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
2023-10-31 23:50:45 +00:00
git push --tags
2024-02-01 15:23:43 +00:00
echo -e "${GREEN}Release tag pushed to remote${OFF}"
echo -e "${GREEN}Done!${OFF}"