Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return non-zero if any errors occur #53

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions gitrise.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build_slug=""
build_url=""
build_status=0
current_build_status_text=""
exit_code=""
exit_code=0
log_url=""
build_artifacts_slugs=()

Expand Down Expand Up @@ -224,7 +224,7 @@ function process_build() {
if [[ $TESTING_ENABLED == true ]] && [[ "${FUNCNAME[1]}" != "testFailureUponReceivingHTMLREsponse" ]]; then break; fi
sleep "$STATUS_POLLING_INTERVAL"
done
if [ "$build_status" = 1 ]; then exit_code=0; else exit_code=1; fi
if [ "$build_status" != 1 ]; then exit_code=$(( exit_code + 1 )); fi
}

function check_build_status() {
Expand Down Expand Up @@ -406,7 +406,7 @@ function download_single_artifact() {
artifact_title=$(echo "$response" | jq ".data.title" | sed 's/"//g')
printf "%b" "Downloading build artifact $artifact_title\n"
curl -X GET "$artifact_url" --output "./build_artifacts/$artifact_title"
exit_code=$?
exit_code=$(( exit_code + $? ))
}

function download_build_artifacts() {
Expand Down Expand Up @@ -437,4 +437,4 @@ if [ "$0" = "${BASH_SOURCE[0]}" ] && [ -z "${TESTING_ENABLED}" ]; then
build_status_message "$build_status"
[ -n "$BUILD_ARTIFACTS" ] && download_build_artifacts
exit ${exit_code}
fi
fi
51 changes: 51 additions & 0 deletions tests/download_single_artifacts_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash

# shellcheck disable=SC1091,SC2155,SC2154,SC2034
# Not following: (error message here)
# Declare and assign separately to avoid masking return values.
# var is referenced but not assigned.
# var appears unused

source ./gitrise.sh -T

testExitCodeRemainsZeroWhenSuccessful() {
exit_code=0
# shellcheck disable=SC2317 # Don't warn about unreachable commands in this function
curl() {
return 0
}

download_single_artifact "some-slug" &> /dev/null
local expected_code=0
assertEquals "Status codes did not match" "$expected_code" "${exit_code}"
}

testDoesNotOverrideExistingExitCode() {
exit_code=1
# shellcheck disable=SC2317 # Don't warn about unreachable commands in this function
curl() {
return 0
}

download_single_artifact "some-slug" &> /dev/null
local expected_code=1
assertEquals "Status codes did not match" "$expected_code" "${exit_code}"
}

testAccumulatesErrorsOnCurlFailures() {
exit_code=1
# shellcheck disable=SC2317 # Don't warn about unreachable commands in this function
curl() {
return 1
}

download_single_artifact "some-slug" &> /dev/null
local expected_code=2
assertEquals "Status codes did not match" "$expected_code" "${exit_code}"
}

tearDown() {
build_status=0
}

. ./tests/shunit2