Skip to content

Commit 47eda7c

Browse files
mads-hartmannroboquat
authored andcommitted
Poll for job status instead of tailing logs
This commit also cleans up Werft slice output slightly
1 parent 9a9d0f0 commit 47eda7c

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

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

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ FAILURE_COUNT=0
77
RUN_COUNT=0
88
declare -A FAILURE_TESTS
99

10+
context_name=$1
11+
context_repo=$2
12+
1013
function cleanup ()
1114
{
1215
werft log phase "slack notification" "slack notification"
13-
context_name="{{ .Name }}"
14-
context_repo="{{ .Repository.Repo }}"
1516
werftJobUrl="https://werft.gitpod-dev.com/job/${context_name}"
1617

1718
if [ "${RUN_COUNT}" -eq "0" ]; then
@@ -49,7 +50,6 @@ function cleanup ()
4950
werft log slice "clean up" --done
5051
}
5152

52-
echo "preparing config." | werft log slice prepare
5353
sudo chown -R gitpod:gitpod /workspace
5454
gcloud auth activate-service-account --key-file /mnt/secrets/gcp-sa/service-account.json
5555
export GOOGLE_APPLICATION_CREDENTIALS="/home/gitpod/.config/gcloud/legacy_credentials/[email protected]/adc.json"
@@ -59,12 +59,17 @@ git config --global user.email [email protected]
5959
git remote set-url origin https://oauth2:"${ROBOQUAT_TOKEN}"@github.com/gitpod-io/gitpod.git
6060

6161
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
62+
63+
# Create branch off main and ask Werft to create a preview environment for it
64+
( \
65+
git checkout -B "${BRANCH}" && \
66+
echo "integration test" >> README.md && \
67+
git add README.md && \
68+
git commit -m "integration test" && \
69+
git push --set-upstream origin "${BRANCH}" && \
70+
werft run github -a with-preview=true
71+
) | werft log slice "build preview environment"
72+
6873
trap cleanup SIGINT SIGTERM EXIT
6974

7075
BUILD_ID=$(werft job list repo.ref==refs/heads/"${BRANCH}" -o yaml | yq4 '.result[] | select(.metadata.annotations[].key == "with-preview") | .name' | head -1)
@@ -73,14 +78,28 @@ do
7378
sleep 1
7479
BUILD_ID=$(werft job list repo.ref==refs/heads/"${BRANCH}" -o yaml | yq4 '.result[] | select(.metadata.annotations[].key == "with-preview") | .name' | head -1)
7580
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}"
7881

79-
if ! werft job logs "${BUILD_ID}" | werft log slice "build preview environment";
80-
then
82+
job_url="https://werft.gitpod-dev.com/job/${BUILD_ID}"
83+
echo "start build preview environment, job name: ${BUILD_ID}, job url: ${job_url}, this will take long time" | werft log slice "build preview environment"
84+
werft log result -d "Build job for integration test branch" url "${job_url}"
85+
86+
while true; do
87+
job_phase=$(werft job get "${BUILD_ID}" -o json | jq --raw-output '.phase')
88+
if [[ ${job_phase} != "PHASE_DONE" ]]; then
89+
echo "Waiting for ${BUILD_ID} to finish running. Current phase: ${job_phase}. Sleeping 10 seconds." | werft log slice "build preview environment";
90+
sleep 10
91+
else
92+
echo "Phase reached ${job_phase}. continuing." | werft log slice "build preview environment";
93+
break
94+
fi
95+
done
96+
97+
job_success="$(werft job get "${BUILD_ID}" -o json | jq --raw-output '.conditions.success')"
98+
if [[ ${job_success} == "null" ]]; then
8199
echo "build failed" | werft log slice "build preview environment"
82100
exit 1
83101
fi
102+
84103
echo "build success" | werft log slice "build preview environment"
85104
werft log slice "build preview environment" --done
86105

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#
2+
# During development side-load the bash script:
3+
#
4+
# werft job run github -j .werft/workspace-run-integration-tests.yaml -s .werft/workspace-run-integration-tests.sh
5+
#
16
pod:
27
serviceAccount: werft
38
nodeSelector:
@@ -61,5 +66,7 @@ pod:
6166
command:
6267
- bash
6368
- .werft/workspace-run-integration-tests.sh
69+
- "{{ .Name }}"
70+
- "{{ .Repository.Repo }}"
6471
plugins:
6572
cron: "@midnight"

0 commit comments

Comments
 (0)