-
Notifications
You must be signed in to change notification settings - Fork 348
Expand file tree
/
Copy pathintegration.sh
More file actions
executable file
·178 lines (147 loc) · 4.44 KB
/
Copy pathintegration.sh
File metadata and controls
executable file
·178 lines (147 loc) · 4.44 KB
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
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
ROOTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
readonly ROOTDIR
# shellcheck source=SCRIPTDIR/.util/print.sh
source "${ROOTDIR}/scripts/.util/print.sh"
# shellcheck source=SCRIPTDIR/.util/tools.sh
source "${ROOTDIR}/scripts/.util/tools.sh"
function usage() {
cat <<-USAGE
integration.sh --github-token <token> [OPTIONS]
Runs the integration tests.
OPTIONS
--help -h prints the command usage
--github-token <token> GitHub token to use when making API requests
--platform <cf|docker> Switchblade platform to execute the tests against
--keep-failed-containers Preserve failed test containers for debugging (default: false)
USAGE
}
function main() {
local src stack platform token cached parallel keep_failed
src="$(find "${ROOTDIR}/src" -mindepth 1 -maxdepth 1 -type d )"
stack="${CF_STACK:-$(jq -r -S .stack "${ROOTDIR}/config.json")}"
platform="cf"
keep_failed="false"
while [[ "${#}" != 0 ]]; do
case "${1}" in
--platform)
platform="${2}"
shift 2
;;
--github-token)
token="${2}"
shift 2
;;
--cached)
cached="${2}"
shift 2
;;
--parallel)
parallel="${2}"
shift 2
;;
--keep-failed-containers)
keep_failed="true"
shift 1
;;
--help|-h)
shift 1
usage
exit 0
;;
"")
# skip if the argument is empty
shift 1
;;
*)
util::print::error "unknown argument \"${1}\""
esac
done
if [[ -z "${token:-}" ]]; then
util::print::error "Missing required github token. This is used as COMPOSER_GITHUB_OAUTH_TOKEN for the build"
fi
util::print::info "The provided github token is also being used as COMPOSER_GITHUB_OAUTH_TOKEN for the build"
if [[ "${platform}" == "docker" ]]; then
if [[ "$(jq -r -S .integration.harness "${ROOTDIR}/config.json")" != "switchblade" ]]; then
util::print::warn "NOTICE: This integration suite does not support Docker."
fi
fi
declare -a matrix
if [[ "${cached:-}" != "" && "${parallel:-}" != "" ]]; then
matrix+=("{\"cached\":${cached},\"parallel\":${parallel}}")
else
IFS=$'\n' read -r -d '' -a matrix < <(
jq -r -S -c .integration.matrix[] "${ROOTDIR}/config.json" \
&& printf "\0"
)
fi
util::tools::buildpack-packager::install --directory "${ROOTDIR}/.bin"
util::tools::cf::install --directory "${ROOTDIR}/.bin"
for row in "${matrix[@]}"; do
local cached parallel
cached="$(jq -r -S .cached <<<"${row}")"
parallel="$(jq -r -S .parallel <<<"${row}")"
echo "Running integration suite (cached: ${cached}, parallel: ${parallel})"
specs::run "${cached}" "${parallel}" "${stack}" "${platform}" "${token:-}" "${keep_failed}"
done
}
function specs::run() {
local cached parallel stack platform token keep_failed
cached="${1}"
parallel="${2}"
stack="${3}"
platform="${4}"
token="${5}"
keep_failed="${6}"
local nodes cached_flag serial_flag platform_flag stack_flag token_flag keep_failed_flag
cached_flag="--cached=${cached}"
serial_flag="--serial=true"
platform_flag="--platform=${platform}"
stack_flag="--stack=${stack}"
token_flag="--github-token=${token}"
keep_failed_flag="--keep-failed-containers=${keep_failed}"
nodes=1
if [[ "${parallel}" == "true" ]]; then
nodes=3
serial_flag=""
fi
local buildpack_file version
version="$(cat "${ROOTDIR}/VERSION")"
buildpack_file="$(buildpack::package "${version}" "${cached}" "${stack}")"
CF_STACK="${stack}" \
COMPOSER_GITHUB_OAUTH_TOKEN="${token}" \
BUILDPACK_FILE="${BUILDPACK_FILE:-"${buildpack_file}"}" \
GOMAXPROCS="${GOMAXPROCS:-"${nodes}"}" \
go test \
-count=1 \
-timeout=0 \
-mod vendor \
-v \
"${src}/integration" \
"${cached_flag}" \
"${platform_flag}" \
"${token_flag}" \
"${stack_flag}" \
"${serial_flag}" \
"${keep_failed_flag}"
}
function buildpack::package() {
local version cached
version="${1}"
cached="${2}"
stack="${3}"
local cached_flag
cached_flag=""
if [[ "${cached}" == "true" ]]; then
cached_flag="--cached"
fi
bash "${ROOTDIR}/scripts/package.sh" \
--stack "${stack}" \
"${cached_flag}" > /dev/null
# this is the default output location of the package.sh script
echo "${ROOTDIR}/build/buildpack.zip"
}
main "${@:-}"