-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-matrix.sh
More file actions
executable file
·53 lines (43 loc) · 1.24 KB
/
test-matrix.sh
File metadata and controls
executable file
·53 lines (43 loc) · 1.24 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
#!/bin/bash
set -eu -o pipefail
BIN_DIR="$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")"
matrix_test() {
tags="$(docker buildx bake local --print 2>/dev/null | jq -r '.target[] | .tags[0]')"
# Initialize an array to store the exit codes
exit_codes=()
while read -r tag; do
echo "==> Testing ${tag}"
if [[ -n "$2" ]]; then
"${BIN_DIR}/test.sh" "${tag}" "$2" &
else
"${BIN_DIR}/test.sh" "${tag}" &
fi
pids+=($!)
done <<< "${tags}"
# Wait for all processes to finish and capture their exit codes
for pid in "${pids[@]}"; do
wait "$pid"
exit_codes+=($?)
done
# Print the collated exit codes
# shellcheck disable=SC2145
echo "Exit Codes: ${exit_codes[@]}"
# Calculate the overall exit code (e.g., 0 if all succeeded, non-zero if any failed)
overall_exit_code=0
for code in "${exit_codes[@]}"; do
if [ "$code" -ne 0 ]; then
overall_exit_code=$code
break
fi
done
# Exit with the overall exit code
exit "$overall_exit_code"
}
matrix_build=$(docker buildx bake --print 2>/dev/null | jq 'has("group")')
if [ "${matrix_build}" = 'true' ]; then
echo "==> Matrix build detected"
matrix_test "$@"
else
echo "==> Non-matrix build detected"
"${BIN_DIR}/test.sh" "$@"
fi