1
- args :
2
- - name : version
3
- desc : " The version of the integration tests to use"
4
- required : true
5
- - name : namespace
6
- desc : " The namespace to run the integration test against"
7
- required : true
8
- - name : testPattern
9
- desc : " The test file pattern to filter the tests to run"
10
- required : false
11
1
pod :
12
2
serviceAccount : werft
13
3
nodeSelector :
18
8
- name : gcp-sa
19
9
secret :
20
10
secretName : gcp-sa-gitpod-dev-deployer
21
- - name : integration-test-user
22
- secret :
23
- secretName : integration-test-user
24
11
- name : config
25
12
emptyDir : {}
26
- initContainers :
13
+ containers :
27
14
- name : gcloud
28
15
image : eu.gcr.io/gitpod-core-dev/dev/dev-environment:cw-werft-cred.0
29
16
workingDir : /workspace
30
17
imagePullPolicy : IfNotPresent
31
- volumeMounts :
32
- - name : gcp-sa
33
- mountPath : /mnt/secrets/gcp-sa
34
- readOnly : true
35
- - name : config
36
- mountPath : /config
37
- readOnly : false
38
- command :
39
- - bash
40
- - -c
41
- - |
42
-
43
- echo "[prep] preparing config."
44
-
45
- gcloud auth activate-service-account --key-file /mnt/secrets/gcp-sa/service-account.json
46
- cp -R /home/gitpod/.config/gcloud /config/gcloud
47
- cp /home/gitpod/.kube/config /config/kubeconfig
48
-
49
- echo "[prep] copied config..."
50
- containers :
51
- - name : tests
52
- image : eu.gcr.io/gitpod-core-dev/build/integration-tests:{{ .Annotations.version }}
53
- workingDir : /workspace
54
- imagePullPolicy : IfNotPresent
55
- volumeMounts :
56
- - name : config
57
- mountPath : /config
58
- readOnly : true
59
18
env :
60
- - name : USERNAME
19
+ - name : NODENAME
61
20
valueFrom :
62
- secretKeyRef :
63
- name : integration-test-user
64
- key : username
65
- - name : USER_TOKEN
66
- valueFrom :
67
- secretKeyRef :
68
- name : integration-test-user
69
- key : token
21
+ fieldRef :
22
+ fieldPath : spec.nodeName
70
23
- name : ROBOQUAT_TOKEN
71
24
valueFrom :
72
25
secretKeyRef :
@@ -77,59 +30,140 @@ pod:
77
30
secretKeyRef :
78
31
name : slack-webhook-urls
79
32
key : workspace_jobs
33
+ - name : USERNAME
34
+ valueFrom :
35
+ secretKeyRef :
36
+ name : integration-test-user
37
+ key : username
38
+ - name : USER_TOKEN
39
+ valueFrom :
40
+ secretKeyRef :
41
+ name : integration-test-user
42
+ key : token
43
+ volumeMounts :
44
+ - name : gcp-sa
45
+ mountPath : /mnt/secrets/gcp-sa
46
+ readOnly : true
47
+ - name : config
48
+ mountPath : /config
49
+ readOnly : false
80
50
command :
81
- - /bin/ bash
51
+ - bash
82
52
- -c
83
53
- |
84
54
set -euo
85
55
86
- printf '{{ toJson .Annotations }}' > context.json
56
+ BRANCH="inte-test/"$(date +%Y%m%d%H%M%S)
57
+ export WERFT_CREDENTIAL_HELPER=/workspace/dev/preview/werft-credential-helper.sh
87
58
88
- echo "[prep] receiving config..."
89
- export GOOGLE_APPLICATION_CREDENTIALS="/config/gcloud/legacy_credentials/[email protected] /adc.json"
90
- echo "[prep] received config."
59
+ function cleanup ()
60
+ {
61
+ werft log phase "clean up" "clean up"
62
+ git push origin :$BRANCH | werft log slice "clean up"
63
+ werft log slice "clean up" --done
64
+ }
91
65
92
- echo "[prep] using username: $USERNAME"
93
-
94
- TEST_PATTERN="{{ .Annotations.testPattern }}"
95
- if [[ "$TEST_PATTERN" == "<no value>" ]]; then
96
- TEST_PATTERN=""
66
+ echo "preparing config." | werft log slice prepare
67
+ sudo chown -R gitpod:gitpod /workspace
68
+ gcloud auth activate-service-account --key-file /mnt/secrets/gcp-sa/service-account.json
69
+ export GOOGLE_APPLICATION_CREDENTIALS="/home/gitpod/.config/gcloud/legacy_credentials/[email protected] /adc.json"
70
+
71
+ git config --global user.name roboquat
72
+ git config --global user.email [email protected]
73
+ git remote set-url origin https://oauth2:[email protected] /gitpod-io/gitpod.git
74
+
75
+ echo "copied config..." | werft log slice prepare
76
+ go install github.com/csweichel/oci-tool@latest 2>&1 | werft log slice prepare
77
+ werft log slice prepare --done
78
+
79
+ werft log phase "build preview environment" "build preview environment"
80
+ echo integration test >> README.md
81
+ git checkout -B $BRANCH
82
+ git add README.md
83
+ git commit -m "integration test"
84
+ git push --set-upstream origin $BRANCH
85
+ trap cleanup SIGINT SIGTERM EXIT
86
+
87
+ BUILD_ID=$(werft job list repo.ref==refs/heads/${BRANCH} -o yaml | yq r - "result[0].name")
88
+ until [ "$BUILD_ID" != "" ]
89
+ do
90
+ sleep 1
91
+ BUILD_ID=$(werft job list repo.ref==refs/heads/${BRANCH} -o yaml | yq r - "result[0].name")
92
+ done
93
+ echo "start build preview environment, job name: ${BUILD_ID}, this will take long time" | werft log slice "build preview environment"
94
+ werft log result -d "build job" url "https://werft.gitpod-dev.com/job/${BUILD_ID}"
95
+
96
+ if ! werft job logs ${BUILD_ID} | werft log slice "build preview environment";
97
+ then
98
+ echo "build failed" | werft log slice "build preview environment"
99
+ exit 1
97
100
fi
98
- echo "[prep] using testPattern: $TEST_PATTERN"
101
+ echo "build success" | werft log slice "build preview environment"
102
+ werft log slice "build preview environment" --done
99
103
104
+ werft log phase "kubectx" "kubectx"
105
+ mkdir -p /home/gitpod/.ssh
106
+ /workspace/dev/preview/util/download-and-merge-harvester-kubeconfig.sh | werft log slice "kubectx"
107
+ /workspace/dev/preview/install-k3s-kubeconfig.sh | werft log slice "kubectx"
108
+ werft log slice "kubectx" --done
109
+
110
+ werft log phase "integration test" "integration test"
100
111
args=()
101
- [[ "$TEST_PATTERN" != "" ]] && args+=( "-testPattern=$TEST_PATTERN" )
102
- args+=( '-kubeconfig=/config/kubeconfig' )
103
- args+=( "-namespace={{ .Annotations.namespace }}" )
112
+ args+=( "-kubeconfig=/home/gitpod/.kube/config" )
113
+ args+=( "-namespace=default" )
104
114
[[ "$USERNAME" != "" ]] && args+=( "-username=$USERNAME" )
105
- echo "[prep|DONE]"
106
115
107
- /entrypoint.sh "${args[@]}" 2>&1 | tee entrypoint.sh.log | ts "[int-tests] "
116
+ 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)
117
+
118
+ FAILURE_COUNT=0
119
+ declare -A FAILURE_TESTS
120
+ for TEST_PATH in "${WK_TEST_LIST[@]}"
121
+ do
122
+ TEST_NAME=$(basename "${TEST_PATH}")
123
+ echo "running integration for ${TEST_NAME}" | werft log slice "test-${TEST_NAME}"
108
124
109
- RC=${PIPESTATUS[0]}
125
+ cd "${TEST_PATH}"
126
+ go test -v ./... "${args[@]}" 2>&1 | tee "${TEST_NAME}".log | werft log slice "test-${TEST_NAME}"
127
+
128
+
129
+ if [ "${PIPESTATUS[0]}" -ne "0" ]; then
130
+ FAILURE_COUNT=$((FAILURE_COUNT+1))
131
+ FAILURE_TESTS["${TEST_NAME}"]=$(grep "\-\-\- FAIL: " "${TEST_PATH}"/"${TEST_NAME}".log)
132
+ werft log slice "test-${TEST_NAME}" --fail "${PIPESTATUS[0]}"
133
+ else
134
+ werft log slice "test-${TEST_NAME}" --done
135
+ fi
136
+ done
137
+
138
+ werft log phase "slack notification" "slack notification"
110
139
context_name={{ .Name }}
111
140
context_repo={{ .Repository.Repo }}
112
141
werftJobUrl="https://werft.gitpod-dev.com/job/${context_name}"
113
142
114
- if [ $RC -eq 1 ]; then
143
+ if [ "${FAILURE_COUNT}" -ne "0" ]; then
115
144
title=":x: *Workspace integration test fail*"
116
-
117
- title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}\n_TestPattern_: {{ .Annotations.testPattern }}"
118
- errors=$(grep "\-\-\- FAIL: " entrypoint.sh.log)
119
- 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${errors}\\n\`\`\`\"}}]}"
120
-
121
- echo "[int-tests|FAIL]"
145
+ title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}"
146
+
147
+ errs=""
148
+ for TEST_NAME in ${!FAILURE_TESTS[*]}; do
149
+ title=$title"\n_Tests_: ${TEST_NAME}"
150
+ errs+="${FAILURE_TESTS["${TEST_NAME}"]}"
151
+ done
152
+ errs=$(echo "${errs}" | head)
153
+ 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\`\`\`\"}}]}"
122
154
else
123
155
title=":white_check_mark: *Workspace integration test pass*"
124
156
125
- title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}\n_TestPattern_: {{ .Annotations.testPattern }} "
157
+ title=$title"\n_Repo:_ ${context_repo}\n_Build:_ ${context_name}"
126
158
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\"}}]}"
127
-
128
- echo "[int-tests|DONE]"
129
159
fi
130
160
131
161
curl -X POST \
132
162
-H 'Content-type: application/json' \
133
163
-d "${BODY}" \
134
164
"https://hooks.slack.com/${SLACK_NOTIFICATION_PATH}"
135
- exit $RC
165
+ werft log result "slack notification" "${PIPESTATUS[0]}"
166
+
167
+ exit $FAILURE_COUNT
168
+ plugins :
169
+ cron : " @midnight"
0 commit comments