diff --git a/openebs/buildscripts/git-release b/openebs/buildscripts/git-release index 60a9aadd62b..f79067434cf 100755 --- a/openebs/buildscripts/git-release +++ b/openebs/buildscripts/git-release @@ -1,4 +1,19 @@ #!/bin/bash + +# Copyright 2020 The OpenEBS Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + set -e if [ "$#" -ne 3 ]; then @@ -46,6 +61,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 \ @@ -62,7 +95,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