Skip to content

Commit

Permalink
fixing git-release file to ignore error if tag already exists
Browse files Browse the repository at this point in the history
Signed-off-by: mayank <[email protected]>
  • Loading branch information
mayank authored and kmova committed May 12, 2020
1 parent 794ab18 commit c4ab161
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ before_install:
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-get update -qq
- sudo apt-get install --yes -qq gcc-6 g++-6
- sudo apt-get install --yes -qq build-essential autoconf libtool gawk alien fakeroot linux-headers-$(uname -r) libaio-dev
- sudo apt-get install --yes -qq build-essential autoconf libtool gawk alien fakeroot linux-headers-$(uname -r) libaio-dev jq
- sudo apt-get install --yes -qq zlib1g-dev uuid-dev libattr1-dev libblkid-dev libselinux-dev libudev-dev libssl-dev libjson-c-dev
- sudo apt-get install --yes -qq lcov libjemalloc-dev
# packages for tests
Expand Down
22 changes: 21 additions & 1 deletion buildscripts/git-release
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ RELEASE_CREATE_JSON=$(echo \
TEMP_RESP_FILE=temp-curl-response.txt
rm -rf ${TEMP_RESP_FILE}

#is_release_already_exist verifies the output of API for error message
#return 0 -- if release already exist
#return 1 -- if release doesn't exist
is_release_already_exist() {
dfile=$1

msg=$(cat $dfile | jq -r '.message')
code=$(cat $dfile | jq -r '.errors[0].code')
resource=$(cat $dfile | jq -r '.errors[0].resource')
error_len=$(cat $dfile | jq '.errors | length')

[[ "$msg" == "Validation Failed" ]] && \
[[ "$code" == "already_exists" ]] && \
[[ "$resource" -eq "Release" ]] && \
[[ $error_len -eq 1 ]] && \
echo 0 || echo 1
}

response_code=$(curl -u ${GIT_NAME}:${GIT_TOKEN} \
-w "%{http_code}" \
--silent \
Expand All @@ -76,7 +94,7 @@ rc_code=0
#Github returns 201 Created on successfully creating a new release
#201 means the request has been fulfilled and has resulted in one
#or more new resources being created.
if [ $response_code != "201" ]; then
if [ $response_code != "201" ] && [[ $(is_release_already_exist $TEMP_RESP_FILE) -ne 0 ]]; then
echo "Error: Unable to create release. See below response for more details"
#The GitHub error response is pretty well formatted.
#Printing the body gives all the details to fix the errors
Expand All @@ -98,6 +116,8 @@ else
#knowing that creation worked is all that matters now.
echo "Successfully tagged $1 with release tag ${C_GIT_TAG_NAME} on branch ${C_GIT_TAG_BRANCH}"
fi


cat ${TEMP_RESP_FILE}

#delete the temporary response file
Expand Down

0 comments on commit c4ab161

Please sign in to comment.