-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathaddReleaseTag
executable file
·182 lines (153 loc) · 4.51 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
178
179
180
181
182
#!/bin/bash
# Expects a releasePassword file to be ./
# get version------------
version=`cat package.json | grep -e '"version":'`
while IFS='"' read -ra ADDR; do
counter=0
for i in "${ADDR[@]}"; do
if [ $counter == 3 ]
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/frontend?password=$password&version=$version&name=web-js" \
-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
# 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/frontend \
-H 'Content-Type: application/json' \
-H 'api-version: 0' \
-d "{
\"password\": \"$releasePassword\",
\"name\":\"web-js\",
\"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/frontend/latest/check?password=$password&version=$version&name=web-js" \
-H 'api-version: 0'`
response=`echo $response | jq .isLatest`
# Initialize an empty JSON object string
jsonPayload="{\"password\": \"$releasePassword\""
# Iterate through all files in the ./bundle directory
for file in ./bundle/*; do
# Extract the filename without the path
filename=$(basename "$file")
# Extract the name part (before the first dot)
name="${filename%%.*}"
# Add the key-value pair to the JSON object string
if [ -n "$jsonPayload" ] && [ "$jsonPayload" != "{" ]; then
jsonPayload+=","
fi
jsonPayload+="\"$name\":\"https://cdn.jsdelivr.net/gh/supertokens/supertokens-web-js@v${version}/bundle/$filename\""
done
# Close the JSON object
jsonPayload+="}"
responseStatus=`curl -s -o /dev/null -w "%{http_code}" -X PUT \
https://api.supertokens.io/0/frontend/web-js \
-H 'Content-Type: application/json' \
-H 'api-version: 0' \
-d "${jsonPayload}"`
if [ "$responseStatus" -ne 200 ]
then
echo "failed PUT API to update js deliver uri on server with status code: $responseStatus. You need to manually call this API with the right url!"
exit 1
fi
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 master..."
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