Skip to content

Commit 2864fdf

Browse files
jondongHanks10100
authored andcommitted
[WEEX-525] Created the automate beta branch-off scripts. (apache#1353)
The script beta-branchoff.sh is to automate the weekly beta release branch-off procedure. It helps to identify which is the latest non-RC version number and release a new beta branch with the number. The branch will be branched-off from origin/master and will be pushed onto apache after its creation. A valid beta version number looks like: 0.18.0-beta1 A Valid beta branch name looks like: 0.18.0-beta1-180720 common.sh provides some useful gadgets for the scripts and can be shared across scripts.
1 parent 2e9a078 commit 2864fdf

File tree

2 files changed

+174
-0
lines changed

2 files changed

+174
-0
lines changed

scripts/beta-branchoff.sh

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/usr/bin/env bash
2+
3+
dir_name=$(dirname $0)
4+
source ${dir_name}/common.sh
5+
6+
function isValidVersion () {
7+
echo "$1" | awk '/^[0-9]+\.[0-9]+(\.[0-9]+){0,2}(-rc[0-9]+|-beta[0-9]+)?$/ {print $0}'
8+
}
9+
10+
function isBetaVersion () {
11+
echo "$1" | awk '/^[0-9]+\.[0-9]+(\.[0-9]+){0,2}-beta[0-9]+$/ {print $0}'
12+
}
13+
14+
function isRCVersion () {
15+
echo "$1" | awk '/^[0-9]+\.[0-9]+(\.[0-9]+){0,2}-rc[0-9]+$/ {print $0}'
16+
}
17+
18+
function latestVersion () {
19+
git tag -l | awk '/^0\.[0-9]+(\.[0-9]+){0,2}(-rc[0-9]+|-beta[0-9]+)?$/ { print $0 }' | sort -rV | head -n 1
20+
}
21+
22+
function latestNotRCVersion () {
23+
git tag -l | awk '/^0\.[0-9]+(\.[0-9]+){0,2}(-beta[0-9]+)?$/ { print $0 }' | sort -rV | head -n 1
24+
}
25+
26+
function betaNumber () {
27+
echo "$1" | awk -F 'beta' '{print $2}'
28+
}
29+
30+
function rcNumber () {
31+
echo "$1" | awk -F 'rc' '{print $2}'
32+
}
33+
34+
function gitRepoModified () {
35+
git status --short | awk '/^[ M][ M] / { print $0 }'
36+
}
37+
38+
function increaseBetaVersion () {
39+
if [ $(isRCVersion "$1") ]; then
40+
# Unable to increase beta version number on a RC version, exit.
41+
return 1
42+
fi
43+
if [ $(isBetaVersion "$1") ]; then
44+
echo "$1" | awk -F 'beta' '{printf("%sbeta%d\n", $1, $2+1)}'
45+
else
46+
echo "$1" | awk -F '.' '/^([0-9]+\.){1,3}([0-9]+)$/ {
47+
for(i=1;i<=NF;i++) {
48+
if (i==NF) {
49+
printf("%d-beta1\n", $i+1)
50+
} else {
51+
printf("%d.", $i)
52+
}
53+
}
54+
}'
55+
fi
56+
}
57+
58+
function increaseRCVersion () {
59+
if [ $(isBetaVersion "$1") ]; then
60+
# Unable to increase rc version number on a beta version, exit.
61+
return 1
62+
fi
63+
if [ $(isRCVersion "$1") ]; then
64+
echo "$1" | awk -F 'rc' '{printf("%src%d\n", $1, $2+1)}'
65+
else
66+
echo "$1" | awk -F '.' '/^([0-9]+\.){1,3}([0-9]+)$/ {
67+
for(i=1;i<=NF;i++) {
68+
if (i==NF) {
69+
printf("%d-rc1\n", $i+1)
70+
} else {
71+
printf("%d.", $i)
72+
}
73+
}
74+
}'
75+
fi
76+
}
77+
78+
read -e -p "Your upstream git remote is? [origin]"
79+
remote=${REPLY:="origin"}
80+
81+
info "Fetching latest changes and prune ${LGREEN}$remote${RESTORE}..."
82+
git fetch -p -t "$remote"
83+
if [ $? ]; then
84+
error "It is not able to fetch codes from your $remote, check if there is any issue."
85+
exit 1
86+
fi
87+
git remote prune "$remote"
88+
info "${GREEN}Done.${RESTORE}"
89+
90+
latest_ver=$(latestNotRCVersion)
91+
beta_ver="0.0.1-beta1"
92+
if [ -z "$latest_ver" ]; then
93+
echo "Use ${YELLOW}$beta_ver${RESTORE} as the version number."
94+
else
95+
beta_ver=$(increaseBetaVersion "$latest_ver")
96+
fi
97+
98+
beta_branch="$beta_ver-$(date "+%y%m%d")"
99+
100+
info "\nThe latest non-RC version is: ${CYAN}'$latest_ver'${RESTORE}"
101+
info "This beta version number should be: ${CYAN}'$beta_ver'${RESTORE}"
102+
info "The beta release branch name should be: ${CYAN}'$beta_branch'${RESTORE}."
103+
104+
is_remote_branch_exist=$(git branch -r | awk '/'"$beta_ver"'/ {print $0}')
105+
if [ "$is_remote_branch_exist" ]; then
106+
warning "Remote branch with beta version $beta_ver already exists, will quit."
107+
exit 1
108+
fi
109+
110+
latest_sha=$(git show --format=%h -s)
111+
notice "\nMake sure the latest commit SHA on master is:"
112+
notice "${GREEN}$latest_sha${RESTORE}"
113+
notice "If it is not the branch-off point you want, update the $remote/master first."
114+
notice "Also make sure you have the permisison to push branch onto your $remote."
115+
116+
read -e -p "Continue? [Y/n] " -n 1
117+
shouldContinue=${REPLY:=y}
118+
if [ ${shouldContinue,,} = n ]; then
119+
info "Sure, bye."
120+
exit 0
121+
fi
122+
123+
if [ "$(gitRepoModified)" ]; then
124+
read -e -p "Your working directory is modified, stash it? [Y/n]" -n 1
125+
shouldStash=${REPLY:=y}
126+
if [ ${shouldStash,,} = y ]; then
127+
git stash
128+
else
129+
info "Change ignored."
130+
fi
131+
fi
132+
133+
echo -e "\nCreating local branch: ${YELLOW}$beta_branch${RESTORE}..."
134+
git checkout -B "$beta_branch" "$latest_sha"
135+
136+
echo -e "\nPushing ${YELLOW}$beta_branch${RESTORE} onto $remote..."
137+
git push "$remote" "$beta_branch":"$beta_branch"
138+
git branch --set-upstream-to="$remote/$beta_branch"
139+
echo "${GREEN}Done.${RESTORE}"

scripts/common.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
RESTORE=$(echo -en '\033[0m')
4+
RED=$(echo -en '\033[00;31m')
5+
GREEN=$(echo -en '\033[00;32m')
6+
YELLOW=$(echo -en '\033[00;33m')
7+
BLUE=$(echo -en '\033[00;34m')
8+
MAGENTA=$(echo -en '\033[00;35m')
9+
PURPLE=$(echo -en '\033[00;35m')
10+
CYAN=$(echo -en '\033[00;36m')
11+
LIGHTGRAY=$(echo -en '\033[00;37m')
12+
LRED=$(echo -en '\033[01;31m')
13+
LGREEN=$(echo -en '\033[01;32m')
14+
LYELLOW=$(echo -en '\033[01;33m')
15+
LBLUE=$(echo -en '\033[01;34m')
16+
LMAGENTA=$(echo -en '\033[01;35m')
17+
LPURPLE=$(echo -en '\033[01;35m')
18+
LCYAN=$(echo -en '\033[01;36m')
19+
WHITE=$(echo -en '\033[01;37m')
20+
21+
function info () {
22+
echo -e $*
23+
}
24+
25+
function notice () {
26+
echo -e "${CYAN}$*${RESTORE}"
27+
}
28+
29+
function warning () {
30+
echo -e "${YELLOW}$*${RESTORE}"
31+
}
32+
33+
function error () {
34+
echo -e "${RED}$*${RESTORE}"
35+
}

0 commit comments

Comments
 (0)