diff --git a/.werft/workspace-run-integration-tests.yaml b/.werft/workspace-run-integration-tests.yaml index fb6b2c6e801ee2..98a8839e3e72fd 100644 --- a/.werft/workspace-run-integration-tests.yaml +++ b/.werft/workspace-run-integration-tests.yaml @@ -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" @@ -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" != "" ] @@ -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) @@ -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"