forked from cloudfoundry/python-buildpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration.sh
More file actions
executable file
·167 lines (137 loc) · 3.85 KB
/
integration.sh
File metadata and controls
executable file
·167 lines (137 loc) · 3.85 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
#!/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
USAGE
}
function main() {
local src stack platform token cached parallel
src="$(find "${ROOTDIR}/src" -mindepth 1 -maxdepth 1 -type d )"
stack="${CF_STACK:-$(jq -r -S .stack "${ROOTDIR}/config.json")}"
platform="cf"
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
;;
--help|-h)
shift 1
usage
exit 0
;;
"")
# skip if the argument is empty
shift 1
;;
*)
util::print::error "unknown argument \"${1}\""
esac
done
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:-}"
done
}
function specs::run() {
local cached parallel stack platform token
cached="${1}"
parallel="${2}"
stack="${3}"
platform="${4}"
token="${5}"
local nodes cached_flag serial_flag platform_flag stack_flag token_flag
cached_flag="--cached=${cached}"
serial_flag="--serial=true"
platform_flag="--platform=${platform}"
stack_flag="--stack=${stack}"
token_flag="--github-token=${token}"
nodes=1
if [[ "${parallel}" == "true" ]]; then
nodes=3
serial_flag=""
fi
local buildpack_file
buildpack_file="$(buildpack::package "1.2.3" "${cached}" "${stack}")"
CF_STACK="${stack}" \
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}"
}
function buildpack::package() {
local version cached
version="${1}"
cached="${2}"
stack="${3}"
local name cached_flag
name="buildpack-${stack}-v${version}-uncached.zip"
cached_flag=""
if [[ "${cached}" == "true" ]]; then
cached_flag="--cached"
name="buildpack-${stack}-v${version}-cached.zip"
fi
local output
output="$(mktemp -d)/${name}"
bash "${ROOTDIR}/scripts/package.sh" \
--version "${version}" \
--output "${output}" \
--stack "${stack}" \
"${cached_flag}" > /dev/null
printf "%s" "${output}"
}
main "${@:-}"