package uploader: when script exit, return status code '1' if there errors occurred

package_uploader.sh should not exit on error when package processing is not finished
by allowing to do as much as possible.

But we need some mechanizm to notify maintainers when errors occurred on CI/CD
on package operations.
This commit is contained in:
Leonid Pliushch 2019-03-25 16:43:30 +02:00
parent c6bb942333
commit 512bcdbea5

View File

@ -59,6 +59,16 @@ PACKAGE_CLEANUP_MODE=false
PACKAGE_DELETION_MODE=false PACKAGE_DELETION_MODE=false
SCRIPT_EMERG_EXIT=false SCRIPT_EMERG_EXIT=false
# Special variable to force script to exit with error status
# when everything finished. Should be set only when non-script
# errors occur, e.g. curl request failure.
#
# Useful in case if there was an error when uploading packages
# via CI/CD so packages are still uploaded where possible but
# maintainers will be notified about error because pipeline
# will be marked as "failed".
SCRIPT_ERROR_EXIT=false
# Bintray-specific configuration. # Bintray-specific configuration.
BINTRAY_REPO_NAME="termux-packages-24" BINTRAY_REPO_NAME="termux-packages-24"
BINTRAY_REPO_GITHUB="termux/termux-packages" BINTRAY_REPO_GITHUB="termux/termux-packages"
@ -180,15 +190,13 @@ recalculate_metadata() {
http_status_code=$(echo "$curl_response" | cut -d'|' -f2) http_status_code=$(echo "$curl_response" | cut -d'|' -f2)
api_response_message=$(echo "$curl_response" | cut -d'|' -f1 | jq -r .message) api_response_message=$(echo "$curl_response" | cut -d'|' -f1 | jq -r .message)
case "$http_status_code" in if [ "$http_status_code" = "202" ]; then
202) msg "done"
msg "done" else
;; msg "failure"
*) msg "[!] $api_response_message"
msg "failure" SCRIPT_ERROR_EXIT=true
msg "[!] $api_response_message" fi
;;
esac
} }
@ -225,6 +233,7 @@ delete_package() {
msg "success" msg "success"
else else
msg "$api_response_message" msg "$api_response_message"
SCRIPT_ERROR_EXIT=true
fi fi
if $SCRIPT_EMERG_EXIT; then if $SCRIPT_EMERG_EXIT; then
@ -271,6 +280,7 @@ delete_old_versions_from_package() {
) )
else else
msg "$api_response_message." msg "$api_response_message."
SCRIPT_ERROR_EXIT=true
return 1 return 1
fi fi
@ -302,6 +312,7 @@ delete_old_versions_from_package() {
if [ "$http_status_code" != "200" ] && [ "$http_status_code" != "404" ]; then if [ "$http_status_code" != "200" ] && [ "$http_status_code" != "404" ]; then
msg "$api_response_message" msg "$api_response_message"
SCRIPT_ERROR_EXIT=true
return 1 return 1
fi fi
@ -359,6 +370,7 @@ upload_package() {
if [ ${#debfiles_catalog[@]} -eq 0 ]; then if [ ${#debfiles_catalog[@]} -eq 0 ]; then
set -o nounset set -o nounset
msg " * ${1}: skipping because no files to upload." msg " * ${1}: skipping because no files to upload."
SCRIPT_ERROR_EXIT=true
return 1 return 1
fi fi
set -o nounset set -o nounset
@ -385,6 +397,7 @@ upload_package() {
if [ "$http_status_code" != "201" ] && [ "$http_status_code" != "409" ]; then if [ "$http_status_code" != "201" ] && [ "$http_status_code" != "409" ]; then
msg "$api_response_message" msg "$api_response_message"
SCRIPT_ERROR_EXIT=true
return 1 return 1
fi fi
@ -420,6 +433,7 @@ upload_package() {
if [ "$http_status_code" != "201" ] && [ "$http_status_code" != "409" ]; then if [ "$http_status_code" != "201" ] && [ "$http_status_code" != "409" ]; then
msg "$api_response_message" msg "$api_response_message"
SCRIPT_ERROR_EXIT=true
return 1 return 1
fi fi
@ -450,6 +464,7 @@ upload_package() {
msg -e "\\r\\e[2K * ${1}: success" msg -e "\\r\\e[2K * ${1}: success"
else else
msg "$api_response_message" msg "$api_response_message"
SCRIPT_ERROR_EXIT=true
return 1 return 1
fi fi
} }
@ -524,6 +539,7 @@ process_packages() {
else else
if [ ! -f "$TERMUX_PACKAGES_BASEDIR/packages/$package_name/build.sh" ]; then if [ ! -f "$TERMUX_PACKAGES_BASEDIR/packages/$package_name/build.sh" ]; then
msg " * ${package_name}: skipping because such package does not exist." msg " * ${package_name}: skipping because such package does not exist."
SCRIPT_ERROR_EXIT=true
continue continue
fi fi
@ -532,27 +548,32 @@ process_packages() {
PACKAGE_METADATA["LICENSES"]=$(get_package_property "$package_name" "TERMUX_PKG_LICENSE") PACKAGE_METADATA["LICENSES"]=$(get_package_property "$package_name" "TERMUX_PKG_LICENSE")
if [ -z "${PACKAGE_METADATA['LICENSES']}" ]; then if [ -z "${PACKAGE_METADATA['LICENSES']}" ]; then
msg " * ${package_name}: skipping because field 'TERMUX_PKG_LICENSE' is empty." msg " * ${package_name}: skipping because field 'TERMUX_PKG_LICENSE' is empty."
SCRIPT_ERROR_EXIT=true
continue continue
elif grep -qP '.*custom.*' <(echo "${PACKAGE_METADATA['LICENSES']}"); then elif grep -qP '.*custom.*' <(echo "${PACKAGE_METADATA['LICENSES']}"); then
msg " * ${package_name}: skipping because it has custom license." msg " * ${package_name}: skipping because it has custom license."
SCRIPT_ERROR_EXIT=true
continue continue
fi fi
PACKAGE_METADATA["DESCRIPTION"]=$(get_package_property "$package_name" "TERMUX_PKG_DESCRIPTION") PACKAGE_METADATA["DESCRIPTION"]=$(get_package_property "$package_name" "TERMUX_PKG_DESCRIPTION")
if [ -z "${PACKAGE_METADATA['DESCRIPTION']}" ]; then if [ -z "${PACKAGE_METADATA['DESCRIPTION']}" ]; then
msg " * ${package_name}: skipping because field 'TERMUX_PKG_DESCRIPTION' is empty." msg " * ${package_name}: skipping because field 'TERMUX_PKG_DESCRIPTION' is empty."
SCRIPT_ERROR_EXIT=true
continue continue
fi fi
PACKAGE_METADATA["WEBSITE_URL"]=$(get_package_property "$package_name" "TERMUX_PKG_HOMEPAGE") PACKAGE_METADATA["WEBSITE_URL"]=$(get_package_property "$package_name" "TERMUX_PKG_HOMEPAGE")
if [ -z "${PACKAGE_METADATA['WEBSITE_URL']}" ]; then if [ -z "${PACKAGE_METADATA['WEBSITE_URL']}" ]; then
msg " * ${package_name}: skipping because field 'TERMUX_PKG_HOMEPAGE' is empty." msg " * ${package_name}: skipping because field 'TERMUX_PKG_HOMEPAGE' is empty."
SCRIPT_ERROR_EXIT=true
continue continue
fi fi
PACKAGE_METADATA["VERSION"]=$(get_package_property "$package_name" "TERMUX_PKG_VERSION") PACKAGE_METADATA["VERSION"]=$(get_package_property "$package_name" "TERMUX_PKG_VERSION")
if [ -z "${PACKAGE_METADATA['VERSION']}" ]; then if [ -z "${PACKAGE_METADATA['VERSION']}" ]; then
msg " * ${package_name}: skipping because field 'TERMUX_PKG_VERSION' is empty." msg " * ${package_name}: skipping because field 'TERMUX_PKG_VERSION' is empty."
SCRIPT_ERROR_EXIT=true
continue continue
fi fi
@ -751,4 +772,9 @@ if [ -z "$BINTRAY_GPG_SUBJECT" ]; then
fi fi
process_packages "$@" process_packages "$@"
exit 0
if $SCRIPT_ERROR_EXIT; then
exit 1
else
exit 0
fi