1
1
# Upload test logs on failure, if there are any.
2
- if [[ "${BUILDKITE_COMMAND_EXIT_STATUS}" -ne "0" ]]; then
3
- declare log_count=0
4
- for log in $(make testlogs 2>/dev/null | sort | uniq); do
5
- buildkite-agent artifact upload "${log}"
6
- log_count=$((${log_count}+1))
7
- # N.B. If *all* tests fail due to some common cause, then we will
8
- # end up spending way too much time uploading logs. Instead, we just
9
- # upload the first 100 and stop. That is hopefully enough to debug.
10
- if [[ "${log_count}" -ge 100 ]]; then
11
- echo "Only uploaded first 100 failures; skipping the rest."
12
- break
13
- fi
14
- done
2
+ if test "${BUILDKITE_COMMAND_EXIT_STATUS}" -ne "0"; then
3
+ # Generate a metafile that ends with .output, and contains all the
4
+ # test failures that have been uploaded. These will all be sorted and
5
+ # aggregated by a failure stage in the build pipeline.
6
+ declare output=$(mktemp "${BUILDKITE_JOB_ID}".XXXXXX.output)
7
+ make -s testlogs 2>/dev/null | grep // | sort | uniq | (
8
+ declare log_count=0
9
+ while read target log; do
10
+ if test -z "${target}"; then
11
+ continue
12
+ fi
13
+
14
+ # N.B. If *all* tests fail due to some common cause, then we will
15
+ # end up spending way too much time uploading logs. Instead, we just
16
+ # upload the first 10 and stop. That is hopefully enough to debug.
17
+ #
18
+ # We include this test in the metadata, but note that we cannot
19
+ # upload the actual test logs. The user should rerun locally.
20
+ log_count=$((${log_count}+1))
21
+ if test "${log_count}" -ge 10; then
22
+ echo " * ${target} (no upload)" | tee -a "${output}"
23
+ else
24
+ buildkite-agent artifact upload "${log}"
25
+ echo " * [${target}](artifact://${log#/})" | tee -a "${output}"
26
+ fi
27
+ done
28
+ )
29
+
30
+ # Upload if we had outputs.
31
+ if test -s "${output}"; then
32
+ buildkite-agent artifact upload "${output}"
33
+ fi
34
+ rm -rf "${output}"
35
+
15
36
# Attempt to clear the cache and shut down.
16
37
make clean || echo "make clean failed with code $?"
17
38
make bazel-shutdown || echo "make bazel-shutdown failed with code $?"
18
39
fi
19
40
41
+ # Upload all profiles, and include in an annotation.
42
+ if test -d /tmp/profile; then
43
+ # Same as above.
44
+ declare profile_output=$(mktemp "${BUILDKITE_JOB_ID}".XXXXXX.profile_output)
45
+ for file in $(find /tmp/profile -name \*.pprof -print 2>/dev/null | sort); do
46
+ # Generate a link to speedscope, with a URL-encoded link to the BuildKite
47
+ # artifact location. Note that we use do a fixed URL encode below, since
48
+ # the link can be uniquely determined. If the storage location changes,
49
+ # this schema may break and these links may stop working. The artifacts
50
+ # uploaded however, will still work just fine.
51
+ profile_name="${file#/tmp/profile/}"
52
+ public_url="https://storage.googleapis.com/gvisor-buildkite/${BUILDKITE_BUILD_ID}/${BUILDKITE_JOB_ID}/${file#/}"
53
+ encoded_url=$(jq -rn --arg x "${public_url}" '$x|@uri')
54
+ encoded_title=$(jq -rn --arg x "${profile_name}" '$x|@uri')
55
+ profile_url="https://speedscope.app/#profileURL=${encoded_url}&title=${encoded_title}"
56
+ buildkite-agent artifact upload "${file}"
57
+ echo " * [${profile_name}](${profile_url}) ([pprof](artifact://${file#/}))" | tee -a "${profile_output}"
58
+ done
59
+
60
+ # Upload if we had outputs.
61
+ if test -s "${profile_output}"; then
62
+ buildkite-agent artifact upload "${profile_output}"
63
+ fi
64
+ rm -rf "${profile_output}"
65
+
66
+ # Remove stale profiles, which may be owned by root.
67
+ sudo rm -rf /tmp/profile
68
+ fi
69
+
20
70
# Kill any running containers (clear state).
21
71
CONTAINERS="$(docker ps -q)"
22
- if ! [[ -z "${CONTAINERS}" ]] ; then
72
+ if ! test -z "${CONTAINERS}"; then
23
73
docker container kill ${CONTAINERS} 2>/dev/null || true
24
- fi
74
+ fi
0 commit comments