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