Skip to content

Commit 7ee2c3a

Browse files
committed
add release helper script
1 parent e2e6202 commit 7ee2c3a

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

script/release

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
# About:
4+
#
5+
# This is a helper script to tag and push a new release. GitHub Actions use
6+
# release tags to allow users to select a specific version of the action to use.
7+
#
8+
# See: https://github.com/actions/typescript-action#publishing-a-new-release
9+
#
10+
# This script will do the following:
11+
#
12+
# 1. Get the latest release tag
13+
# 2. Prompt the user for a new release tag
14+
# 3. Tag the new release
15+
# 4. Push the new tag to the remote
16+
#
17+
# Usage:
18+
#
19+
# script/release
20+
21+
# Terminal colors
22+
OFF='\033[0m'
23+
RED='\033[0;31m'
24+
GREEN='\033[0;32m'
25+
BLUE='\033[0;34m'
26+
27+
# Get the latest release tag
28+
latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
29+
30+
if [[ -z "$latest_tag" ]]; then
31+
# There are no existing release tags
32+
echo -e "No tags found (yet) - Continue to create and push your first tag"
33+
latest_tag="[unknown]"
34+
fi
35+
36+
# Display the latest release tag
37+
echo -e "The latest release tag is: ${BLUE}${latest_tag}${OFF}"
38+
39+
# Prompt the user for the new release tag
40+
read -r -p 'Enter a new release tag (vX.X.X format): ' new_tag
41+
42+
# Validate the new release tag
43+
tag_regex='v[0-9]+\.[0-9]+\.[0-9]+$'
44+
if echo "$new_tag" | grep -q -E "$tag_regex"; then
45+
echo -e "Tag: ${BLUE}$new_tag${OFF} is valid"
46+
else
47+
# Release tag is not `vX.X.X` format
48+
echo -e "Tag: ${BLUE}$new_tag${OFF} is ${RED}not valid${OFF} (must be in vX.X.X format)"
49+
exit 1
50+
fi
51+
52+
# Tag the new release
53+
git tag -a "$new_tag" -m "$new_tag Release"
54+
echo -e "${GREEN}Tagged: $new_tag${OFF}"
55+
56+
# Push the new tag to the remote
57+
git push --tags
58+
echo -e "${GREEN}Release tag pushed to remote${OFF}"
59+
echo -e "${GREEN}Done!${OFF}"

0 commit comments

Comments
 (0)