Skip to content

Commit 6632a6b

Browse files
committed
fix(build): git-release check if already tagged
The build fails if a tagged build is restarted on travis as the previous run would have already tagged the dependent repos. This commit adds a check to see if the error response to tag is about already_exists and returns a success code. Signed-off-by: kmova <[email protected]>
1 parent ee5f6c6 commit 6632a6b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

buildscripts/git-release

+21-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,24 @@ RELEASE_CREATE_JSON=$(echo \
6060
TEMP_RESP_FILE=temp-curl-response.txt
6161
rm -rf ${TEMP_RESP_FILE}
6262

63+
#is_release_already_exist verifies the output of API for error message
64+
#return 0 -- if release already exist
65+
#return 1 -- if release doesn't exist
66+
is_release_already_exist() {
67+
dfile=$1
68+
69+
msg=$(cat $dfile | jq -r '.message')
70+
code=$(cat $dfile | jq -r '.errors[0].code')
71+
resource=$(cat $dfile | jq -r '.errors[0].resource')
72+
error_len=$(cat $dfile | jq '.errors | length')
73+
74+
[[ "$msg" == "Validation Failed" ]] && \
75+
[[ "$code" == "already_exists" ]] && \
76+
[[ "$resource" -eq "Release" ]] && \
77+
[[ $error_len -eq 1 ]] && \
78+
echo 0 || echo 1
79+
}
80+
6381
response_code=$(curl -u ${GIT_NAME}:${GIT_TOKEN} \
6482
-w "%{http_code}" \
6583
--silent \
@@ -76,7 +94,7 @@ rc_code=0
7694
#Github returns 201 Created on successfully creating a new release
7795
#201 means the request has been fulfilled and has resulted in one
7896
#or more new resources being created.
79-
if [ $response_code != "201" ]; then
97+
if [ $response_code != "201" ] && [[ $(is_release_already_exist $TEMP_RESP_FILE) -ne 0 ]]; then
8098
echo "Error: Unable to create release. See below response for more details"
8199
#The GitHub error response is pretty well formatted.
82100
#Printing the body gives all the details to fix the errors
@@ -98,6 +116,8 @@ else
98116
#knowing that creation worked is all that matters now.
99117
echo "Successfully tagged $1 with release tag ${C_GIT_TAG_NAME} on branch ${C_GIT_TAG_BRANCH}"
100118
fi
119+
120+
101121
cat ${TEMP_RESP_FILE}
102122

103123
#delete the temporary response file

0 commit comments

Comments
 (0)