From 04d6bc511908ac99f06957b11470fbe267a1ff21 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Wed, 2 May 2018 13:33:14 -0700 Subject: [PATCH] Update email script to find status till one is found The determine-email-body script would only look at the previous commit's status to determine whether to send a success email or not. If no status was found (this happens when commits are pushed close to each other and CI only runs the latest one), it would send a successful email even if the last CI run was successful. --- ci/scripts/determine-email-body.sh | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/ci/scripts/determine-email-body.sh b/ci/scripts/determine-email-body.sh index b900f934b9..5e9938e5bb 100755 --- a/ci/scripts/determine-email-body.sh +++ b/ci/scripts/determine-email-body.sh @@ -4,9 +4,30 @@ set -e pushd git-repo > /dev/null PREV_SHA=$( git rev-parse HEAD^1 ) popd > /dev/null -PREV_STATUSES=$( curl https://api.github.com/repos/spring-projects/spring-boot/commits/$PREV_SHA/statuses -H "Authorization: token ${ACCESS_TOKEN}" ) -PREV_STATES=$( echo $PREV_STATUSES | jq -r --arg BUILD_JOB_NAME "$BUILD_JOB_NAME" '.[] | select(.context == $BUILD_JOB_NAME) | .state' ) + +function getPreviousSha() { + pushd git-repo > /dev/null + PREV_SHA=$( git rev-parse "$1"^1 ) + popd > /dev/null + echo "$PREV_SHA" +} + +function getPreviousStates() { + PREV_STATUSES=$( curl https://api.github.com/repos/spring-projects/spring-boot/commits/"$1"/statuses -H "Authorization: token ${ACCESS_TOKEN}" ) + PREV_STATES=$( echo "$PREV_STATUSES" | jq -r --arg BUILD_JOB_NAME "$BUILD_JOB_NAME" '.[] | select(.context == $BUILD_JOB_NAME) | .state' ) + echo "$PREV_STATES" +} + +PREV_STATES=$( getPreviousStates "$PREV_SHA" ) WAS_PREV_SUCCESSFUL=$( echo "$PREV_STATES" | grep 'success' || true ) +IS_PREV_FAILURE=$( echo "$PREV_STATES" | grep 'failure' || true ) + +while [[ $WAS_PREV_SUCCESSFUL == "" ]] && [[ $IS_PREV_FAILURE == "" ]]; do + PREV_SHA=$( getPreviousSha "$PREV_SHA" ) + PREV_STATES=$(getPreviousStates "$PREV_SHA") + WAS_PREV_SUCCESSFUL=$( echo "$PREV_STATES" | grep 'success' || true ) + IS_PREV_FAILURE=$( echo "$PREV_STATES" | grep 'failure' || true ) +done if [[ $STATE == "success" ]];then echo "Build SUCCESSFUL ${BUILD_PIPELINE_NAME} / ${BUILD_JOB_NAME}" > email-details/subject