-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelease
executable file
·82 lines (72 loc) · 2.33 KB
/
release
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# 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. Check if the tag exists and ask for confirmation to overwrite
# 4. Tag the new release
# 5. Push the new tag to the remote
#
# Usage:
#
# script/release
# Terminal colors
OFF='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
# Get the latest release tag
latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
if [[ -z "$latest_tag" ]]; 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: ${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
tag_regex='v[0-9]+(\.[0-9]+){0,2}$'
if echo "$new_tag" | grep -q -E "$tag_regex"; then
echo -e "Tag: ${BLUE}$new_tag${OFF} is valid"
else
# 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
fi
# Check if the tag exists; if it does, ask the user for confirmation to overwrite
if git rev-parse -q --verify "refs/tags/$new_tag" >/dev/null; then
read -r -p "The tag already exists. Overwrite? [y/N] " response
if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo -e "${RED}Aborted${OFF}"
exit 1
else
# Delete the tag locally
git tag -d "$new_tag"
echo -e "${GREEN}Deleted local tag: $new_tag${OFF}"
# Delete the tag remotely
git push origin --delete "$new_tag"
echo -e "${GREEN}Deleted remote tag: $new_tag${OFF}"
fi
else
read -r -p "The tag does not exist and will be created. Continue? [y/N] " response
if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo -e "${RED}Aborted${OFF}"
exit 1
fi
fi
# Tag the new release
git tag -a "$new_tag" -m "$new_tag Release"
echo -e "${GREEN}Tagged: $new_tag${OFF}"
# Push the new tag to the remote
git push --tags
echo -e "${GREEN}Release tag pushed to remote${OFF}"
echo -e "${GREEN}Done!${OFF}"