|
60 | 60 | name: github-token-gitpod-bot
|
61 | 61 | command:
|
62 | 62 | - bash
|
63 |
| - - -c |
64 |
| - - | |
65 |
| - set -euo pipefail |
66 |
| -
|
67 |
| - BRANCH="wk-inte-test/"$(date +%Y%m%d%H%M%S) |
68 |
| - FAILURE_COUNT=0 |
69 |
| - RUN_COUNT=0 |
70 |
| - declare -A FAILURE_TESTS |
71 |
| -
|
72 |
| - function cleanup () |
73 |
| - { |
74 |
| - werft log phase "slack notification" "slack notification" |
75 |
| - context_name="{{ .Name }}" |
76 |
| - context_repo="{{ .Repository.Repo }}" |
77 |
| - werftJobUrl="https://werft.gitpod-dev.com/job/${context_name}" |
78 |
| -
|
79 |
| - if [ "${RUN_COUNT}" -eq "0" ]; then |
80 |
| - title=":x: *Workspace integration test fail*" |
81 |
| - title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}" |
82 |
| -
|
83 |
| - errs="Failed at preparing the preview environment" |
84 |
| - 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\`\`\`\"}}]}" |
85 |
| - elif [ "${FAILURE_COUNT}" -ne "0" ]; then |
86 |
| - title=":x: *Workspace integration test fail*" |
87 |
| - title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}" |
88 |
| -
|
89 |
| - errs="" |
90 |
| - for TEST_NAME in ${!FAILURE_TESTS[*]}; do |
91 |
| - title=$title"\n_Tests_: ${TEST_NAME}" |
92 |
| - errs+="${FAILURE_TESTS["${TEST_NAME}"]}" |
93 |
| - done |
94 |
| - errs=$(echo "${errs}" | head) |
95 |
| - 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\`\`\`\"}}]}" |
96 |
| - else |
97 |
| - title=":white_check_mark: *Workspace integration test pass*" |
98 |
| -
|
99 |
| - title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}" |
100 |
| - 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\"}}]}" |
101 |
| - fi |
102 |
| -
|
103 |
| - curl -X POST \ |
104 |
| - -H 'Content-type: application/json' \ |
105 |
| - -d "${BODY}" \ |
106 |
| - "https://hooks.slack.com/${SLACK_NOTIFICATION_PATH}" |
107 |
| - werft log result "slack notification" "${PIPESTATUS[0]}" |
108 |
| -
|
109 |
| - werft log phase "clean up" "clean up" |
110 |
| - git push origin :"${BRANCH}" | werft log slice "clean up" |
111 |
| - werft log slice "clean up" --done |
112 |
| - } |
113 |
| -
|
114 |
| - echo "preparing config." | werft log slice prepare |
115 |
| - sudo chown -R gitpod:gitpod /workspace |
116 |
| - gcloud auth activate-service-account --key-file /mnt/secrets/gcp-sa/service-account.json |
117 |
| - export GOOGLE_APPLICATION_CREDENTIALS="/home/gitpod/.config/gcloud/legacy_credentials/[email protected]/adc.json" |
118 |
| -
|
119 |
| - git config --global user.name roboquat |
120 |
| - git config --global user.email [email protected] |
121 |
| - git remote set-url origin https://oauth2:"${ROBOQUAT_TOKEN}"@github.com/gitpod-io/gitpod.git |
122 |
| -
|
123 |
| - werft log phase "build preview environment" "build preview environment" |
124 |
| - echo integration test >> README.md |
125 |
| - git checkout -B "${BRANCH}" |
126 |
| - git add README.md |
127 |
| - git commit -m "integration test" |
128 |
| - git push --set-upstream origin "${BRANCH}" |
129 |
| - werft run github -a with-preview=true |
130 |
| - trap cleanup SIGINT SIGTERM EXIT |
131 |
| -
|
132 |
| - BUILD_ID=$(werft job list repo.ref==refs/heads/"${BRANCH}" -o yaml | yq4 '.result[] | select(.metadata.annotations[].key == "with-preview") | .name' | head -1) |
133 |
| - until [ "$BUILD_ID" != "" ] |
134 |
| - do |
135 |
| - sleep 1 |
136 |
| - BUILD_ID=$(werft job list repo.ref==refs/heads/"${BRANCH}" -o yaml | yq4 '.result[] | select(.metadata.annotations[].key == "with-preview") | .name' | head -1) |
137 |
| - done |
138 |
| - echo "start build preview environment, job name: ${BUILD_ID}, this will take long time" | werft log slice "build preview environment" |
139 |
| - werft log result -d "build job" url "https://werft.gitpod-dev.com/job/${BUILD_ID}" |
140 |
| -
|
141 |
| - if ! werft job logs "${BUILD_ID}" | werft log slice "build preview environment"; |
142 |
| - then |
143 |
| - echo "build failed" | werft log slice "build preview environment" |
144 |
| - exit 1 |
145 |
| - fi |
146 |
| - echo "build success" | werft log slice "build preview environment" |
147 |
| - werft log slice "build preview environment" --done |
148 |
| -
|
149 |
| - werft log phase "kubectx" "kubectx" |
150 |
| - mkdir -p /home/gitpod/.ssh |
151 |
| - /workspace/dev/preview/util/download-and-merge-harvester-kubeconfig.sh | werft log slice "kubectx" |
152 |
| - /workspace/dev/preview/install-k3s-kubeconfig.sh | werft log slice "kubectx" |
153 |
| - werft log slice "kubectx" --done |
154 |
| -
|
155 |
| - werft log phase "integration test" "integration test" |
156 |
| - args=() |
157 |
| - args+=( "-kubeconfig=/home/gitpod/.kube/config" ) |
158 |
| - args+=( "-namespace=default" ) |
159 |
| - [[ "$USERNAME" != "" ]] && args+=( "-username=$USERNAME" ) |
160 |
| -
|
161 |
| - 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) |
162 |
| - for TEST_PATH in "${WK_TEST_LIST[@]}" |
163 |
| - do |
164 |
| - TEST_NAME=$(basename "${TEST_PATH}") |
165 |
| - echo "running integration for ${TEST_NAME}" | werft log slice "test-${TEST_NAME}" |
166 |
| -
|
167 |
| - cd "${TEST_PATH}" |
168 |
| - set +e |
169 |
| - go test -v ./... "${args[@]}" 2>&1 | tee "${TEST_NAME}".log | werft log slice "test-${TEST_NAME}" |
170 |
| - RC=${PIPESTATUS[0]} |
171 |
| - set -e |
172 |
| -
|
173 |
| - RUN_COUNT=$((RUN_COUNT+1)) |
174 |
| - if [ "${RC}" -ne "0" ]; then |
175 |
| - FAILURE_COUNT=$((FAILURE_COUNT+1)) |
176 |
| - FAILURE_TESTS["${TEST_NAME}"]=$(grep "\-\-\- FAIL: " "${TEST_PATH}"/"${TEST_NAME}".log) |
177 |
| - werft log slice "test-${TEST_NAME}" --fail "${RC}" |
178 |
| - else |
179 |
| - werft log slice "test-${TEST_NAME}" --done |
180 |
| - fi |
181 |
| - done |
182 |
| -
|
183 |
| - exit $FAILURE_COUNT |
| 63 | + - .werft/workspace-run-integration-tests.sh |
184 | 64 | plugins:
|
185 | 65 | cron: "@midnight"
|
0 commit comments