-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathbuild-and-test
executable file
·125 lines (108 loc) · 2.79 KB
/
build-and-test
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
#! /usr/bin/env nix-shell
#! nix-shell ../nix/shell.nix -i bash
set -euo pipefail
declare SCRIPT_DIR
SCRIPT_DIR="$( realpath "${BASH_SOURCE[0]}" )"
SCRIPT_DIR="${SCRIPT_DIR%/*}"
cd "$( dirname "$SCRIPT_DIR" )"
declare -a FAILURES=( )
function on_exit() {
echo
if [[ "${#FAILURES[@]}" -gt 0 ]]; then
echo "error: running tests in ${FAILURES[@]} was not successful"
exit 1
elif [[ $? -eq 0 ]]; then
echo "all tests passed."
fi
} >&2
trap on_exit EXIT
if [[ ${BZLMOD_ENABLED-} = true ]]; then
declare -ra build_dirs=(
core
toolchains/go
toolchains/java
toolchains/nodejs
toolchains/posix
toolchains/rust
toolchains/python
)
declare -ra test_dirs=(
core/testing
toolchains/nodejs/testing
testing/core
testing/core/tests/intermediate_module
testing/go-bzlmod
testing/java
testing/posix
testing/rust
testing/python
)
declare -ra extra_flags=(
--config=bzlmod
)
else
declare -ra build_dirs=(
core
)
declare -ra test_dirs=(
.
docs
toolchains/go
toolchains/java
toolchains/cc
toolchains/python
toolchains/posix
toolchains/rust
toolchains/nodejs
toolchains/nodejs/testing
testing/core
testing/go-workspace
testing/java
testing/posix
testing/rust
testing/python
)
declare -ra extra_flags=(
)
fi
run_command() {
local -r cmd=$1
local -r dir=$2
echo "::group::Running \`bazel $1\` in $dir"
pushd $dir >/dev/null
if ! bazel $1 //... "${extra_flags[@]}" ; then
FAILURES+=( "$dir" )
fi
bazel shutdown
popd >/dev/null
echo '::endgroup::'
}
write_summary() {
if [ -v GITHUB_STEP_SUMMARY ]; then
echo "$@" >> "$GITHUB_STEP_SUMMARY"
fi
}
for dir in "${build_dirs[@]}"; do
# bazel test //... fails in modules that don't define any test targets, use
# bazel build in those instead. Workaround for
# https://github.com/bazelbuild/bazel/issues/7291#issuecomment-1283970438
run_command build $dir
done
write_summary '### Test results'
write_summary '| Test | Result | Elapsed Time |'
write_summary '| ---- | :----: | -----------: |'
declare start elapsed failed
for dir in "${test_dirs[@]}"; do
start=$EPOCHSECONDS
failed=${#FAILURES[@]}
run_command test $dir
elapsed=$(( EPOCHSECONDS - start ))
if [[ "$failed" < "${#FAILURES[@]}" ]]; then
write_summary "| $dir | Fail :red_circle: | $( TZ=UTC0 printf '%(%H:%M:%S)T' $elapsed ) |"
else
write_summary "| $dir | Pass :white_check_mark: | $( TZ=UTC0 printf '%(%H:%M:%S)T' $elapsed ) |"
fi
done
# Local Variables:
# mode: sh
# End: