forked from CMSgov/design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·97 lines (84 loc) · 2.44 KB
/
release.sh
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
NC='\033[0m' # No color
read_previous_commit_tags() {
# Grep the last commit message for package versions
PACKAGE_VERSIONS=$(git log -1 --pretty=%B | grep -o "@.*$")
# Take the first one we find to use in example command
PACKAGE_VERSION=$(echo "$PACKAGE_VERSIONS" | head -1)
# Get it all on one line so we can push these tags at once
TAGS=$(echo "$PACKAGE_VERSIONS" | tr '\n' ' ')
}
DELETE_LAST=false
EXTRA_OPTS=()
# Parse options
while [[ $# -gt 0 ]]
do
case "$1" in
-u|--undo)
DELETE_LAST=true
shift # past argument
;;
*)
# unknown option
EXTRA_OPTS+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
git fetch --tags
if [ "$DELETE_LAST" = true ]; then
read_previous_commit_tags
echo "${RED}This release branch and the following tags will be deleted locally and on origin${NC}"
echo ""
echo "${PACKAGE_VERSIONS}"
echo ""
read -p "Are you sure want to continue? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "${GREEN}Undoing last release...${NC}"
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
git tag -d $TAGS
git push origin --delete $TAGS
git push origin --delete $CURRENT_BRANCH
git checkout -
git branch -D $CURRENT_BRANCH
fi
exit 0
fi
echo "${GREEN}Creating release branch...${NC}"
BRANCHREF=$(git rev-parse --short HEAD)
BRANCH="release-${BRANCHREF}"
git checkout -b $BRANCH
echo "${GREEN}Bumping version...${NC}"
PRE_VERSION_HASH=$(git rev-parse HEAD)
yarn lerna version --no-push --exact ${EXTRA_OPTS[@]}
POST_VERSION_HASH=$(git rev-parse HEAD)
if [ "$PRE_VERSION_HASH" = "$POST_VERSION_HASH" ]; then
echo "${RED}No bump commit detected. Removing release branch and exiting...${NC}"
git checkout -
git branch -D $BRANCH
exit 1
fi
echo "${GREEN}Pushing tag and release commit to Github...${NC}"
read_previous_commit_tags
git push --set-upstream origin $BRANCH
git push origin $TAGS
echo ""
echo "${GREEN}Release has been tagged and pushed to origin.${NC}"
echo ""
echo "${PACKAGE_VERSIONS}"
echo ""
echo "${YELLOW}-------${NC}"
echo ""
echo "${YELLOW}NEXT STEPS:${NC}"
echo ""
echo "${YELLOW} 1. Create a pull request for merging \`${CYAN}$BRANCH${YELLOW}\` into master to save the version bump${NC}"
echo ""
echo "${YELLOW} 2. Publish this release to npm using the \`${CYAN}publish-packages${YELLOW}\` job${NC}"
echo ""