forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_docker_ci.sh
executable file
·165 lines (139 loc) · 4.55 KB
/
test_docker_ci.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
#!/bin/bash
# Run this with `./ci/test_docker_ci.sh`.
#
# Compares against data stored in `ci/test/docker`
#
# To commit what is currently produced use:
# `DOCKER_CI_TEST_COMMIT=1 ./ci/test_docker_ci.sh`
#
TESTS_MATCHING="$1"
FAILED=()
DOCKER_CI_FIX="${DOCKER_CI_FIX:-}"
DOCKER_CI_FIX_DIFF="${DOCKER_CI_FIX_DIFF:-}"
VERSION="1.73"
RELEASE_BRANCH="refs/heads/release/vXXX"
TAG_BRANCH="refs/tags/vXXX"
MAIN_BRANCH="refs/heads/main"
OTHER_BRANCH="refs/heads/something/else"
PLATFORMS=(linux windows)
TEST_TYPES=(dev nondev)
BRANCH_TYPES=(tag release main other)
_test () {
local test_type="$1" branch_type="$2" version branch platform name testdata
local platform="${3:-linux}"
name="${platform}_${test_type}_${branch_type}"
testdata="ci/test/docker/${platform}/${test_type}/${branch_type}"
if ! test_matches "${name}"; then
return
fi
if [[ "$branch_type" == "release" ]]; then
version="${VERSION}.3"
branch="$RELEASE_BRANCH"
elif [[ "$branch_type" == "tag" ]]; then
version="${VERSION}.3"
branch="$TAG_BRANCH"
elif [[ "$branch_type" == "other" ]]; then
version="${VERSION}.3"
branch="$OTHER_BRANCH"
else
branch="$MAIN_BRANCH"
version="${VERSION}.0"
fi
if [[ "$test_type" == "dev" ]]; then
version="${version}-dev"
fi
export ENVOY_VERSION="${version}"
export AZP_BRANCH="$branch"
# this should be ignored if the non-push
export DOCKERHUB_USERNAME=DHUSER
export DOCKERHUB_PASSWORD=DHPASSWORD
export DOCKER_CI_DRYRUN=1
export ENVOY_DOCKER_IMAGE_DIRECTORY=/non/existent/test/path
export DOCKER_IMAGE_PREFIX=mocktest/repo
if [[ "$platform" == "windows" ]]; then
export DOCKER_FAKE_WIN=1
fi
if [[ "$DOCKER_CI_TEST_COMMIT" ]]; then
echo "COMMIT(${name}): > ${testdata}"
echo " DOCKER_FAKE_WIN=${DOCKER_FAKE_WIN} ENVOY_VERSION=${version} ENVOY_DOCKER_IMAGE_DIRECTORY=/non/existent/test/path AZP_BRANCH=${branch} DOCKER_CI_DRYRUN=1 ./ci/docker_ci.sh | grep -E \"^>\""
./ci/docker_ci.sh | grep -E "^>" > "$testdata"
return
fi
echo "TEST(${name}): <> ${testdata}"
echo " DOCKER_FAKE_WIN=${DOCKER_FAKE_WIN} ENVOY_VERSION=${version} ENVOY_DOCKER_IMAGE_DIRECTORY=/non/existent/test/path AZP_BRANCH=${branch} DOCKER_CI_DRYRUN=1 ./ci/docker_ci.sh | grep -E \"^>\""
generated="$(mktemp)"
./ci/docker_ci.sh | grep -E "^>" > "$generated"
cmp --silent "$testdata" "$generated" || {
echo "files are different" >&2
diff "$testdata" "$generated" >&2
echo >&2
echo "--------------------------" >&2
cat "$generated"
echo >&2
FAILED+=("$name")
echo >&2
echo "--------------------------" >&2
}
rm "$generated"
}
test_matches () {
local test_type="$1"
if [[ -z "$TESTS_MATCHING" ]]; then
return 0
fi
if [[ "$test_type" =~ $TESTS_MATCHING ]]; then
return 0
fi
return 1
}
run_tests () {
local platform test_type branch_type
for platform in "${PLATFORMS[@]}"; do
for test_type in "${TEST_TYPES[@]}"; do
for branch_type in "${BRANCH_TYPES[@]}"; do
_test "$test_type" "$branch_type" "$platform"
done
done
done
}
handle_failure () {
local platform test_type branch_type
if [[ "${#FAILED[@]}" -eq 0 ]]; then
return
fi
echo >&2
echo "----------------------" >&2
echo "FAILED" >&2
for FAILURE in "${FAILED[@]}"; do
echo "$FAILURE" >&2
if [[ -n "$DOCKER_CI_FIX" ]]; then
platform="$(echo "$FAILURE" | cut -d_ -f1)"
test_type="$(echo "$FAILURE" | cut -d_ -f2)"
branch_type="$(echo "$FAILURE" | cut -d_ -f3)"
DOCKER_CI_TEST_COMMIT=1 _test "$test_type" "$branch_type" "$platform"
fi
done
if [[ -n "$DOCKER_CI_FIX" ]]; then
git add -N ci/test/docker
echo >&2
echo "----------------------" >&2
echo "DIFF APPLIED" >&2
echo >&2
git diff ci/test/docker >&2
if [[ -n "$DOCKER_CI_FIX_DIFF" ]]; then
git diff ci/test/docker > "$DOCKER_CI_FIX_DIFF"
fi
echo "----------------------" >&2
if [[ -e "$DOCKER_CI_FIX_DIFF" ]]; then
echo >&2
echo "Diff file with fixes will be uploaded. Please check the artefacts for this PR run in the azure pipeline." >&2
echo >&2
echo "Fixes will need to be checked before being committed." >&2
fi
fi
return 1
}
run_tests
handle_failure || {
exit 1
}