-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun-regression-tests.sh
executable file
·232 lines (208 loc) · 7.45 KB
/
run-regression-tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#! /usr/bin/env bash
#
# Copyright contributors to the Galasa project
#
# SPDX-License-Identifier: EPL-2.0
#
#-----------------------------------------------------------------------------------------
# Objective: Run regression tests from a given branch in a given repo.
#-----------------------------------------------------------------------------------------
BASEDIR=$(dirname "$0");pushd $BASEDIR 2>&1 >> /dev/null;BASEDIR=$(pwd);popd 2>&1 >> /dev/null
cd "${BASEDIR}/.."
WORKSPACE_DIR=$(pwd)
cd "${BASEDIR}"
#-----------------------------------------------------------------------------------------
# Set Colors
#-----------------------------------------------------------------------------------------
bold=$(tput bold)
underline=$(tput sgr 0 1)
reset=$(tput sgr0)
red=$(tput setaf 1)
green=$(tput setaf 76)
white=$(tput setaf 7)
tan=$(tput setaf 202)
blue=$(tput setaf 25)
#-----------------------------------------------------------------------------------------
# Headers and Logging
#-----------------------------------------------------------------------------------------
underline() { printf "${underline}${bold}%s${reset}\n" "$@"
}
h1() { printf "\n${underline}${bold}${blue}%s${reset}\n" "$@"
}
h2() { printf "\n${underline}${bold}${white}%s${reset}\n" "$@"
}
debug() { printf "${white}%s${reset}\n" "$@"
}
info() { printf "${white}➜ %s${reset}\n" "$@"
}
success() { printf "${green}✔ %s${reset}\n" "$@"
}
error() { printf "${red}✖ %s${reset}\n" "$@"
}
warn() { printf "${tan}➜ %s${reset}\n" "$@"
}
bold() { printf "${bold}%s${reset}\n" "$@"
}
#-----------------------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------------------
function usage {
info "usage: run-regression-tests.sh [OPTIONS]"
cat << EOF
Options are:
-r <repo_name> | --repo <repo_name> : The name of the GitHub repository that the branch to build from can be found within.
-b <branch> | --branch <branch> : The name of the branch that will be built from.
-bs <URI> | --bootstrap <URI> : The URI of the bootstrap properties for galasactl to use (mandatory).
-h | --help : Display usage information.
EOF
}
function verifyTool {
which "$1" 2>&1 > /dev/null
rc=$?
if [[ "${rc}" != "0" ]]; then
info "The $1 tool is not available. Install it and try again."
exit 1
fi
}
#-----------------------------------------------------------------------------------------
# Process parameters
#-----------------------------------------------------------------------------------------
targetRepository="wrapping"
targetBranch="main"
bootstrap=""
while [ "$1" != "" ]; do
case $1 in
-r | --repo ) shift
targetRepository="$1"
;;
-b | --branch ) shift
targetBranch="$1"
;;
-bs | --bootstrap ) shift
bootstrap="$1"
;;
-h | --help ) usage
exit
;;
* ) error "Unexpected argument $1"
usage
exit 1
esac
shift
done
if [[ "${bootstrap}" == "" ]]; then
error "Need to specify --bootstrap <URI>."
usage
exit 1
fi
#-----------------------------------------------------------------------------------------
# Main logic
#-----------------------------------------------------------------------------------------
verifyTool "argocd"
verifyTool "tkn"
verifyTool "go"
if [[ ! -e "../cli" ]]; then
error "../cli is not present. Clone the CLI repository from https://github.com/galasa-dev/cli"
exit 1
fi
# Create a new Argo CD app if a branch other than main is specified, otherwise just run regression tests from main
appName="${targetBranch}-maven-repos"
if [[ "${targetBranch}" != "main" ]]; then
h1 "Creating Argo CD app ${appName}"
repositories=(
'wrapping'
'maven'
'gradle'
'framework'
'extensions'
'managers'
'obr'
)
index=-1
for i in "${!repositories[@]}"; do
if [[ "${targetRepository}" == "${repositories[$i]}" ]]; then
index=$i
break
fi
done
if [[ ${index} -eq -1 ]]; then
error "Repository '${targetRepository}' not found."
exit 1
fi
h2 "Logging into Argo CD"
argocd login argocd.galasa.dev --sso --grpc-web
h2 "Creating app"
argocd app create "${appName}" \
--project default \
--sync-policy auto \
--sync-option Prune=true \
--repo https://github.com/galasa-dev/automation \
--revision HEAD \
--path infrastructure/galasa-plan-b-lon02/galasa-development/branch-maven-repository \
--dest-server https://kubernetes.default.svc \
--dest-namespace galasa-development \
--grpc-web
rc=$? ; if [[ "${rc}" != "0" ]]; then error "Failed to create ${appName}." ; exit 1 ; fi
h2 "Configuring helm parameters"
for repo in "${repositories[@]:${index}}"; do
argocd app set "${appName}" \
--helm-set "${repo}.branch=${targetBranch}" \
--helm-set "${repo}.imageTag=${targetBranch}" \
--helm-set "${repo}.deploy=true" \
--grpc-web
done
success "${appName} app created."
pipeline="branch-${targetRepository}"
h1 "Starting ${pipeline} build pipeline"
tkn pipeline start "${pipeline}" \
--param fromBranch="main" \
--param toBranch="${targetBranch}" \
--param imageTag="${targetBranch}" \
--param refspec="refs/heads/${targetBranch}:refs/heads/${targetBranch}" \
--param appname="${appName}" \
--workspace name=git-workspace,volumeClaimTemplateFile=pipelines/templates/git-workspace-template.yaml \
--pod-template pipelines/templates/pod-template.yaml \
--serviceaccount galasa-build-bot \
-n galasa-build
rc=$? ; if [[ "${rc}" != "0" ]]; then error "Failed to start ${pipeline} pipeline." ; exit 1 ; fi
info "Waiting for builds to complete..."
while [[
"$(curl "https://development.galasa.dev/${targetBranch}/maven-repo/obr/" \
--silent \
--output /dev/null \
--write-out "%{response_code}")" != "200"
]]; do
sleep 5
done
success "Builds complete."
fi
h1 "Creating regression test portfolio"
cd "${WORKSPACE_DIR}/cli"
galasactlPath="cmd/galasactl/main.go"
go run ${galasactlPath} runs prepare \
--portfolio test.yaml \
--bootstrap "${bootstrap}" \
--stream inttests \
--package local
rc=$? ; if [[ "${rc}" != "0" ]]; then error "Failed to create regression test portfolio." ; exit 1 ; fi
success "Portfolio created."
h1 "Starting regression tests"
go run ${galasactlPath} runs submit \
--bootstrap "${bootstrap}" \
--portfolio test.yaml \
--reportyaml tests.yaml \
--reportjson tests.json \
--reportjunit junit.xml \
--override galasaecosystem.runtime.repository="https://development.galasa.dev/${targetBranch}/maven-repo/obr/" \
--throttle 6 \
--poll 10 \
--progress 1 \
--trace
cd ${BASEDIR}
success "Regression tests complete."
if [[ "${targetBranch}" != "main" ]]; then
h1 "Deleting ${appName} Argo CD app"
argocd app delete "${appName}" -y --grpc-web
rc=$? ; if [[ "${rc}" != "0" ]]; then error "Failed to delete ${appName}." ; exit 1 ; fi
success "${appName} app deleted successfully."
fi