Skip to content

Commit 9a9d0f0

Browse files
mads-hartmannroboquat
authored andcommitted
Move shell script to stand-alone file
1 parent f5d79ca commit 9a9d0f0

File tree

2 files changed

+122
-121
lines changed

2 files changed

+122
-121
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
BRANCH="wk-inte-test/"$(date +%Y%m%d%H%M%S)
6+
FAILURE_COUNT=0
7+
RUN_COUNT=0
8+
declare -A FAILURE_TESTS
9+
10+
function cleanup ()
11+
{
12+
werft log phase "slack notification" "slack notification"
13+
context_name="{{ .Name }}"
14+
context_repo="{{ .Repository.Repo }}"
15+
werftJobUrl="https://werft.gitpod-dev.com/job/${context_name}"
16+
17+
if [ "${RUN_COUNT}" -eq "0" ]; then
18+
title=":x: *Workspace integration test fail*"
19+
title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}"
20+
21+
errs="Failed at preparing the preview environment"
22+
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\`\`\`\"}}]}"
23+
elif [ "${FAILURE_COUNT}" -ne "0" ]; then
24+
title=":x: *Workspace integration test fail*"
25+
title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}"
26+
27+
errs=""
28+
for TEST_NAME in ${!FAILURE_TESTS[*]}; do
29+
title=$title"\n_Tests_: ${TEST_NAME}"
30+
errs+="${FAILURE_TESTS["${TEST_NAME}"]}"
31+
done
32+
errs=$(echo "${errs}" | head)
33+
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\`\`\`\"}}]}"
34+
else
35+
title=":white_check_mark: *Workspace integration test pass*"
36+
37+
title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}"
38+
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\"}}]}"
39+
fi
40+
41+
curl -X POST \
42+
-H 'Content-type: application/json' \
43+
-d "${BODY}" \
44+
"https://hooks.slack.com/${SLACK_NOTIFICATION_PATH}"
45+
werft log result "slack notification" "${PIPESTATUS[0]}"
46+
47+
werft log phase "clean up" "clean up"
48+
git push origin :"${BRANCH}" | werft log slice "clean up"
49+
werft log slice "clean up" --done
50+
}
51+
52+
echo "preparing config." | werft log slice prepare
53+
sudo chown -R gitpod:gitpod /workspace
54+
gcloud auth activate-service-account --key-file /mnt/secrets/gcp-sa/service-account.json
55+
export GOOGLE_APPLICATION_CREDENTIALS="/home/gitpod/.config/gcloud/legacy_credentials/[email protected]/adc.json"
56+
57+
git config --global user.name roboquat
58+
git config --global user.email [email protected]
59+
git remote set-url origin https://oauth2:"${ROBOQUAT_TOKEN}"@github.com/gitpod-io/gitpod.git
60+
61+
werft log phase "build preview environment" "build preview environment"
62+
echo integration test >> README.md
63+
git checkout -B "${BRANCH}"
64+
git add README.md
65+
git commit -m "integration test"
66+
git push --set-upstream origin "${BRANCH}"
67+
werft run github -a with-preview=true
68+
trap cleanup SIGINT SIGTERM EXIT
69+
70+
BUILD_ID=$(werft job list repo.ref==refs/heads/"${BRANCH}" -o yaml | yq4 '.result[] | select(.metadata.annotations[].key == "with-preview") | .name' | head -1)
71+
until [ "$BUILD_ID" != "" ]
72+
do
73+
sleep 1
74+
BUILD_ID=$(werft job list repo.ref==refs/heads/"${BRANCH}" -o yaml | yq4 '.result[] | select(.metadata.annotations[].key == "with-preview") | .name' | head -1)
75+
done
76+
echo "start build preview environment, job name: ${BUILD_ID}, this will take long time" | werft log slice "build preview environment"
77+
werft log result -d "build job" url "https://werft.gitpod-dev.com/job/${BUILD_ID}"
78+
79+
if ! werft job logs "${BUILD_ID}" | werft log slice "build preview environment";
80+
then
81+
echo "build failed" | werft log slice "build preview environment"
82+
exit 1
83+
fi
84+
echo "build success" | werft log slice "build preview environment"
85+
werft log slice "build preview environment" --done
86+
87+
werft log phase "kubectx" "kubectx"
88+
mkdir -p /home/gitpod/.ssh
89+
/workspace/dev/preview/util/download-and-merge-harvester-kubeconfig.sh | werft log slice "kubectx"
90+
/workspace/dev/preview/install-k3s-kubeconfig.sh | werft log slice "kubectx"
91+
werft log slice "kubectx" --done
92+
93+
werft log phase "integration test" "integration test"
94+
args=()
95+
args+=( "-kubeconfig=/home/gitpod/.kube/config" )
96+
args+=( "-namespace=default" )
97+
[[ "$USERNAME" != "" ]] && args+=( "-username=$USERNAME" )
98+
99+
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)
100+
for TEST_PATH in "${WK_TEST_LIST[@]}"
101+
do
102+
TEST_NAME=$(basename "${TEST_PATH}")
103+
echo "running integration for ${TEST_NAME}" | werft log slice "test-${TEST_NAME}"
104+
105+
cd "${TEST_PATH}"
106+
set +e
107+
go test -v ./... "${args[@]}" 2>&1 | tee "${TEST_NAME}".log | werft log slice "test-${TEST_NAME}"
108+
RC=${PIPESTATUS[0]}
109+
set -e
110+
111+
RUN_COUNT=$((RUN_COUNT+1))
112+
if [ "${RC}" -ne "0" ]; then
113+
FAILURE_COUNT=$((FAILURE_COUNT+1))
114+
FAILURE_TESTS["${TEST_NAME}"]=$(grep "\-\-\- FAIL: " "${TEST_PATH}"/"${TEST_NAME}".log)
115+
werft log slice "test-${TEST_NAME}" --fail "${RC}"
116+
else
117+
werft log slice "test-${TEST_NAME}" --done
118+
fi
119+
done
120+
121+
exit $FAILURE_COUNT

.werft/workspace-run-integration-tests.yaml

Lines changed: 1 addition & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -60,126 +60,6 @@ pod:
6060
name: github-token-gitpod-bot
6161
command:
6262
- 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
18464
plugins:
18565
cron: "@midnight"

0 commit comments

Comments
 (0)