@@ -7,11 +7,12 @@ FAILURE_COUNT=0
7
7
RUN_COUNT=0
8
8
declare -A FAILURE_TESTS
9
9
10
+ context_name=$1
11
+ context_repo=$2
12
+
10
13
function cleanup ()
11
14
{
12
15
werft log phase " slack notification" " slack notification"
13
- context_name=" {{ .Name }}"
14
- context_repo=" {{ .Repository.Repo }}"
15
16
werftJobUrl=" https://werft.gitpod-dev.com/job/${context_name} "
16
17
17
18
if [ " ${RUN_COUNT} " -eq " 0" ]; then
@@ -49,7 +50,6 @@ function cleanup ()
49
50
werft log slice " clean up" --done
50
51
}
51
52
52
- echo " preparing config." | werft log slice prepare
53
53
sudo chown -R gitpod:gitpod /workspace
54
54
gcloud auth activate-service-account --key-file /mnt/secrets/gcp-sa/service-account.json
55
55
export GOOGLE_APPLICATION_CREDENTIALS=
" /home/gitpod/.config/gcloud/legacy_credentials/[email protected] /adc.json"
59
59
git remote set-url origin https://oauth2:" ${ROBOQUAT_TOKEN} " @github.com/gitpod-io/gitpod.git
60
60
61
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
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
+
68
73
trap cleanup SIGINT SIGTERM EXIT
69
74
70
75
BUILD_ID=$( werft job list repo.ref==refs/heads/" ${BRANCH} " -o yaml | yq4 ' .result[] | select(.metadata.annotations[].key == "with-preview") | .name' | head -1)
73
78
sleep 1
74
79
BUILD_ID=$( werft job list repo.ref==refs/heads/" ${BRANCH} " -o yaml | yq4 ' .result[] | select(.metadata.annotations[].key == "with-preview") | .name' | head -1)
75
80
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
81
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
81
99
echo " build failed" | werft log slice " build preview environment"
82
100
exit 1
83
101
fi
102
+
84
103
echo " build success" | werft log slice " build preview environment"
85
104
werft log slice " build preview environment" --done
86
105
0 commit comments