-
Notifications
You must be signed in to change notification settings - Fork 36
/
addReleaseTag
executable file
·177 lines (147 loc) · 4.16 KB
/
addReleaseTag
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
# Expects a releasePassword file to be ./
# get version------------
version=`cat ./supertokens/constants.go | grep -e 'const VERSION'`
while IFS='"' read -ra ADDR; do
counter=0
for i in "${ADDR[@]}"; do
if [ $counter == 1 ]
then
version=$i
fi
counter=$(($counter+1))
done
done <<< "$version"
branch_name="$(git symbolic-ref HEAD 2>/dev/null)" ||
branch_name="(unnamed branch)" # detached HEAD
branch_name=${branch_name##refs/heads/}
git fetch --prune --prune-tags
password=`cat ./apiPassword`
# we get from the server is the tests have passed or not.
testPassedJson=`curl -s -X GET \
"https://api.supertokens.io/0/driver?password=$password&version=$version&name=golang" \
-H 'api-version: 0'`
if [[ `echo $testPassedJson | jq .testPassed` == "null" ]]
then
testPassed="false"
else
testPassed=`echo $testPassedJson | jq .testPassed`
fi
if [[ $testPassed != "true" ]]
then
RED='\033[0;31m'
NC='\033[0m' # No Color
printf "${RED}All tests have not passed. So stopping process.${NC}\n"
exit 1
fi
# we get from the server if the current package can be released safely or not
if [[ $1 != "--forced" ]]
then
canReleaseSafelyResponse=`curl -s -X GET \
"https://api.supertokens.io/0/driver/release/check?password=$password&version=$version&name=golang" \
-H 'api-version: 0'`
if [[ `echo $canReleaseSafelyResponse | jq .canRelease` == "null" ]]
then
canReleaseSafely="false"
else
canReleaseSafely=`echo $canReleaseSafelyResponse | jq .canRelease`
fi
if [[ $canReleaseSafely != "true" ]]
then
RED='\033[0;31m'
NC='\033[0m' # No Color
printf "${RED}Cannot release core. Have you released corresponding core and frontend?${NC}\n"
exit 1
fi
fi
# check that current commit has a dev tag and that it is the correct version
# get current commit hash------------
if [ $# -eq 0 ]
then
commit_hash=`git log --pretty=format:'%H' -n 1`
else
commit_hash=$1
fi
# check if current commit already has a tag or not------------
currTag=`git tag -l --points-at $commit_hash`
expectedCurrTag=dev-v$version
if [[ $currTag == $expectedCurrTag ]]
then
continue=1
else
RED='\033[0;31m'
NC='\033[0m'
printf "${RED}This commit does not have the right tag for the version you want to release.${NC}\n"
exit 1
fi
releasePassword=`cat ./releasePassword`
# now we call the patch API to make it release mode
responseStatus=`curl -s -o /dev/null -w "%{http_code}" -X PATCH \
https://api.supertokens.io/0/driver \
-H 'Content-Type: application/json' \
-H 'api-version: 0' \
-d "{
\"password\": \"$releasePassword\",
\"name\":\"golang\",
\"version\":\"$version\",
\"release\": true
}"`
if [ $responseStatus -ne "200" ]
then
RED='\033[0;31m'
NC='\033[0m'
printf "${RED}patch api failed. Please try again.${NC}\n"
exit 1
fi
git tag --delete $currTag
git push --delete origin $currTag
git tag v$version
git push --tags
response=`curl -s -X GET \
"https://api.supertokens.io/0/driver/latest/check?password=$password&version=$version&name=golang" \
-H 'api-version: 0'`
response=`echo $response | jq .isLatest`
if [[ $response == "null" ]]
then
RED='\033[0;31m'
NC='\033[0m'
printf "${RED}error while determining if we should push to master or not. Please do so manually if needed:${NC}\n"
if [[ $branch_name == "(unnamed branch)" ]]
then
echo "git checkout -b forrelease"
echo "git merge master"
echo "git checkout master"
echo "git merge forrelease"
echo "git push"
echo "git checkout forrelease"
exit 1
else
echo "git merge master"
echo "git checkout master"
echo "git merge $branch_name"
echo "git push"
echo "git checkout $branch_name"
exit 1
fi
fi
if [[ $response == "true" ]]
then
echo "pushing to mater..."
if [[ $branch_name == "(unnamed branch)" ]]
then
git checkout -b forrelease
git merge master
git checkout master
git merge forrelease
git push
git checkout forrelease
echo "Done! Please delete this branch"
else
git merge master
git checkout master
git merge $branch_name
git push
git checkout $branch_name
echo "Done!"
fi
fi