Skip to content

Commit

Permalink
Add pipefail to integration test
Browse files Browse the repository at this point in the history
Signed-off-by: JenTing Hsiao <hsiaoairplane@gmail.com>
  • Loading branch information
jenting committed May 25, 2022
1 parent e148325 commit d354b86
Showing 1 changed file with 47 additions and 36 deletions.
83 changes: 47 additions & 36 deletions .werft/workspace-run-integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,53 @@ pod:
- bash
- -c
- |
set -euo
set -euo pipefail
BRANCH="inte-test/"$(date +%Y%m%d%H%M%S)
FAILURE_COUNT=0
RUN_COUNT=0
declare -A FAILURE_TESTS
export WERFT_CREDENTIAL_HELPER=/workspace/dev/preview/werft-credential-helper.sh
function cleanup ()
function notify()
{
werft log phase "slack notification" "slack notification"
context_name="{{ .Name }}"
context_repo="{{ .Repository.Repo }}"
werftJobUrl="https://werft.gitpod-dev.com/job/${context_name}"
if [ "${RUN_COUNT}" -eq "0" ]; then
title=":x: *Workspace integration test fail*"
title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}"
errs="Failed at preparing the preview environment"
BODY="{\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"${title}\"},\"accessory\":{\"type\":\"button\",\"text\":{\"type\":\"plain_text\",\"text\":\":werft: Go to Werft\",\"emoji\":true},\"value\":\"click_me_123\",\"url\":\"${werftJobUrl}\",\"action_id\":\"button-action\"}},{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"\`\`\`\\n${errs}\\n\`\`\`\"}}]}"
elif [ "${FAILURE_COUNT}" -ne "0" ]; then
title=":x: *Workspace integration test fail*"
title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}"
errs=""
for TEST_NAME in ${!FAILURE_TESTS[*]}; do
title=$title"\n_Tests_: ${TEST_NAME}"
errs+="${FAILURE_TESTS["${TEST_NAME}"]}"
done
errs=$(echo "${errs}" | head)
BODY="{\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"${title}\"},\"accessory\":{\"type\":\"button\",\"text\":{\"type\":\"plain_text\",\"text\":\":werft: Go to Werft\",\"emoji\":true},\"value\":\"click_me_123\",\"url\":\"${werftJobUrl}\",\"action_id\":\"button-action\"}},{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"\`\`\`\\n${errs}\\n\`\`\`\"}}]}"
else
title=":white_check_mark: *Workspace integration test pass*"
title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}"
BODY="{\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"${title}\"},\"accessory\":{\"type\":\"button\",\"text\":{\"type\":\"plain_text\",\"text\":\":werft: Go to Werft\",\"emoji\":true},\"value\":\"click_me_123\",\"url\":\"${werftJobUrl}\",\"action_id\":\"button-action\"}}]}"
fi
curl -X POST \
-H 'Content-type: application/json' \
-d "${BODY}" \
"https://hooks.slack.com/${SLACK_NOTIFICATION_PATH}"
werft log result "slack notification" "${PIPESTATUS[0]}"
}
function cleanup()
{
werft log phase "clean up" "clean up"
git push origin "${BRANCH}" | werft log slice "clean up"
Expand All @@ -82,7 +123,7 @@ pod:
git add README.md
git commit -m "integration test"
git push --set-upstream origin "${BRANCH}"
trap cleanup SIGINT SIGTERM EXIT
trap notify cleanup SIGINT SIGTERM EXIT
BUILD_ID=$(werft job list repo.ref==refs/heads/"${BRANCH}" -o yaml | yq r - "result[0].name")
until [ "$BUILD_ID" != "" ]
Expand Down Expand Up @@ -114,18 +155,17 @@ pod:
[[ "$USERNAME" != "" ]] && args+=( "-username=$USERNAME" )
WK_TEST_LIST=(/workspace/test/tests/components/content-service /workspace/test/tests/components/image-builder /workspace/test/tests/components/ws-daemon /workspace/test/tests/components/ws-manager /workspace/test/tests/workspace)
FAILURE_COUNT=0
declare -A FAILURE_TESTS
for TEST_PATH in "${WK_TEST_LIST[@]}"
do
TEST_NAME=$(basename "${TEST_PATH}")
echo "running integration for ${TEST_NAME}" | werft log slice "test-${TEST_NAME}"
cd "${TEST_PATH}"
set +e
go test -v ./... "${args[@]}" 2>&1 | tee "${TEST_NAME}".log | werft log slice "test-${TEST_NAME}"
set -e
RUN_COUNT=$((RUN_COUNT+1))
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
FAILURE_COUNT=$((FAILURE_COUNT+1))
FAILURE_TESTS["${TEST_NAME}"]=$(grep "\-\-\- FAIL: " "${TEST_PATH}"/"${TEST_NAME}".log)
Expand All @@ -135,35 +175,6 @@ pod:
fi
done
werft log phase "slack notification" "slack notification"
context_name="{{ .Name }}"
context_repo="{{ .Repository.Repo }}"
werftJobUrl="https://werft.gitpod-dev.com/job/${context_name}"
if [ "${FAILURE_COUNT}" -ne "0" ]; then
title=":x: *Workspace integration test fail*"
title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}"
errs=""
for TEST_NAME in ${!FAILURE_TESTS[*]}; do
title=$title"\n_Tests_: ${TEST_NAME}"
errs+="${FAILURE_TESTS["${TEST_NAME}"]}"
done
errs=$(echo "${errs}" | head)
BODY="{\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"${title}\"},\"accessory\":{\"type\":\"button\",\"text\":{\"type\":\"plain_text\",\"text\":\":werft: Go to Werft\",\"emoji\":true},\"value\":\"click_me_123\",\"url\":\"${werftJobUrl}\",\"action_id\":\"button-action\"}},{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"\`\`\`\\n${errs}\\n\`\`\`\"}}]}"
else
title=":white_check_mark: *Workspace integration test pass*"
title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}"
BODY="{\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"${title}\"},\"accessory\":{\"type\":\"button\",\"text\":{\"type\":\"plain_text\",\"text\":\":werft: Go to Werft\",\"emoji\":true},\"value\":\"click_me_123\",\"url\":\"${werftJobUrl}\",\"action_id\":\"button-action\"}}]}"
fi
curl -X POST \
-H 'Content-type: application/json' \
-d "${BODY}" \
"https://hooks.slack.com/${SLACK_NOTIFICATION_PATH}"
werft log result "slack notification" "${PIPESTATUS[0]}"
exit $FAILURE_COUNT
plugins:
cron: "@midnight"

0 comments on commit d354b86

Please sign in to comment.