diff --git a/.werft/workspace-run-integration-tests.sh b/.werft/workspace-run-integration-tests.sh index 6db87f4dde9362..eb413bba17b47d 100755 --- a/.werft/workspace-run-integration-tests.sh +++ b/.werft/workspace-run-integration-tests.sh @@ -2,9 +2,16 @@ set -euo pipefail +TEMP_COMMIT_MSG="integration test" +# TODO(toru): Fix weird repeat running behavior +# https://github.com/gitpod-io/gitpod/issues/12795 +LAST_COMMIT_MSG=$(git log --pretty=format:"%s" -1) +if [[ $LAST_COMMIT_MSG == "$TEMP_COMMIT_MSG" ]]; then exit 0; fi + BRANCH="wk-inte-test/"$(date +%Y%m%d%H%M%S) FAILURE_COUNT=0 -RUN_COUNT=0 +RUN_COUNT=0 # Prevent multiple cleanup runs +DO_CLEANUP=0 declare -A FAILURE_TESTS declare SIGNAL # used to record signal caught by trap @@ -13,46 +20,50 @@ context_repo=$2 function cleanup () { - werft log phase "slack notification and cleanup $SIGNAL" "Slack notification and cleanup: $SIGNAL" - - 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 - - echo "Sending Slack notificaition" | werft log slice "slack notification" - curl -X POST \ - -H 'Content-type: application/json' \ - -d "${BODY}" \ - "https://hooks.slack.com/${SLACK_NOTIFICATION_PATH}" - werft log result "slack notification" "${PIPESTATUS[0]}" - werft log slice "slack notification" --done - - git push origin :"${BRANCH}" | werft log slice "clean up" - - echo "Finished cleaning up based on signal $SIGNAL" | werft log slice "clean up" - werft log slice "clean up" --done + if [[ $DO_CLEANUP -eq 0 ]]; then + return 0 + fi + DO_CLEANUP=1 + werft log phase "slack notification and cleanup $SIGNAL" "Slack notification and cleanup: $SIGNAL" + + 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 + + echo "Sending Slack notificaition" | werft log slice "slack notification" + curl -X POST \ + -H 'Content-type: application/json' \ + -d "${BODY}" \ + "https://hooks.slack.com/${SLACK_NOTIFICATION_PATH}" + werft log result "slack notification" "${PIPESTATUS[0]}" + werft log slice "slack notification" --done + + git push origin :"${BRANCH}" | werft log slice "clean up" + + echo "Finished cleaning up based on signal $SIGNAL" | werft log slice "clean up" + werft log slice "clean up" --done } sudo chown -R gitpod:gitpod /workspace @@ -68,7 +79,7 @@ werft log phase "build preview environment" "build preview environment" # Create a new branch and asks Werft to create a preview environment for it ( \ git checkout -B "${BRANCH}" && \ - git commit -m "integration test" --allow-empty && \ + git commit -m "${TEMP_COMMIT_MSG}" --allow-empty && \ git push --set-upstream origin "${BRANCH}" && \ werft run github -a with-preview=true ) | werft log slice "build preview environment" @@ -97,13 +108,21 @@ echo "start build preview environment, job name: ${BUILD_ID}, job url: ${job_url werft log result -d "Build job for integration test branch" url "${job_url}" while true; do - job_phase=$(werft job get "${BUILD_ID}" -o json | jq --raw-output '.phase') - if [[ ${job_phase} != "PHASE_DONE" ]]; then - echo "Waiting for ${BUILD_ID} to finish running. Current phase: ${job_phase}. Sleeping 10 seconds." | werft log slice "build preview environment"; + set +e + job_log=$(werft job get "${BUILD_ID}" -o json 2>&1) + set -e + if echo "$job_log" | grep -q "code = Unavailable"; then + echo "Werft returned 50X for some reason. Waiting for ${BUILD_ID} to finish running. Sleeping 10 seconds." | werft log slice "build preview environment"; sleep 10 else - echo "Phase reached ${job_phase}. continuing." | werft log slice "build preview environment"; - break + job_phase=$(echo "$job_log" | jq --raw-output '.phase') + if [[ ${job_phase} != "PHASE_DONE" ]]; then + echo "Waiting for ${BUILD_ID} to finish running. Current phase: ${job_phase}. Sleeping 10 seconds." | werft log slice "build preview environment"; + sleep 10 + else + echo "Phase reached ${job_phase}. continuing." | werft log slice "build preview environment"; + break + fi fi done @@ -137,7 +156,7 @@ args=() args+=( "-kubeconfig=/home/gitpod/.kube/config" ) args+=( "-namespace=default" ) [[ "$USERNAME" != "" ]] && args+=( "-username=$USERNAME" ) -args+=( "-timeout=60m" ) +args+=( "-timeout=120m" ) args+=( "-p=1" ) 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)