Skip to content

Commit a9941d4

Browse files
authored
Merge pull request #101 from simpsonjulian/huge-junits-2
Don't send annotations if they're too large for the API
2 parents edecfa5 + 5f82e5b commit a9941d4

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ the build to fail.
5353

5454
## Developing
5555

56-
To test the junit parser (in Ruby) and plugin hooks (in Bash):
56+
To test the plugin hooks (in Bash) and the junit parser (in Ruby):
5757

5858
```bash
5959
docker-compose run --rm plugin &&

hooks/command

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
set -euo pipefail
44

55
PLUGIN_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)/.."
6+
MAX_SIZE=100 # in KB
67

78
echo "--- :junit: Download the junits"
89

@@ -15,6 +16,12 @@ function cleanup {
1516
rm -rf "${annotation_dir}"
1617
}
1718

19+
function check_size {
20+
local size_in_kb
21+
size_in_kb=$(du -k "${annotation_path}" | cut -f 1)
22+
[ "${size_in_kb}" -lt "${MAX_SIZE}" ]
23+
}
24+
1825
trap cleanup EXIT
1926

2027
buildkite-agent artifact download \
@@ -37,6 +44,13 @@ docker \
3744
cat "$annotation_path"
3845

3946
if grep -q "<details>" "$annotation_path"; then
47+
48+
if ! check_size; then
49+
echo "--- :warning: Failures too large to annotate"
50+
echo "The failures are too large to create a build annotation. Please inspect the failed JUnit artifacts manually."
51+
exit 0
52+
fi
53+
4054
echo "--- :buildkite: Creating annotation"
4155
# shellcheck disable=SC2002
4256
cat "$annotation_path" | buildkite-agent annotate --context junit --style error

tests/command.bats

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ load "$BATS_PATH/load.bash"
66
# export MKTEMP_STUB_DEBUG=/dev/tty
77
# export BUILDKITE_AGENT_STUB_DEBUG=/dev/tty
88
# export DOCKER_STUB_DEBUG=/dev/tty
9+
# export DU_STUB_DEBUG=/dev/tty
910

1011
@test "runs the annotator and creates the annotation" {
1112
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
@@ -118,3 +119,32 @@ load "$BATS_PATH/load.bash"
118119

119120
assert_output --partial "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS: unbound variable"
120121
}
122+
123+
@test "fails if the annotation is larger than " {
124+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
125+
126+
artifacts_tmp="tests/tmp/$PWD/junit-artifacts"
127+
annotation_tmp="tests/tmp/$PWD/junit-annotation"
128+
129+
stub mktemp \
130+
"-d junit-annotate-plugin-artifacts-tmp.XXXXXXXXXX : mkdir -p $artifacts_tmp; echo $artifacts_tmp" \
131+
"-d junit-annotate-plugin-annotation-tmp.XXXXXXXXXX : mkdir -p $annotation_tmp; echo $annotation_tmp"
132+
133+
# 1kb over the 100k size limit of annotations
134+
stub du "-k /plugin/tests/tmp//plugin/junit-annotation/annotation.md : echo 101 /plugin/tests/tmp//plugin/junit-annotation/annotation.md"
135+
136+
stub buildkite-agent "artifact download junits/*.xml /plugin/tests/tmp//plugin/junit-artifacts : echo Downloaded artifacts"
137+
138+
stub docker "--log-level error run --rm --volume /plugin/tests/tmp//plugin/junit-artifacts:/junits --volume /plugin/hooks/../ruby:/src --env BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN= --env BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT= ruby:2.5-alpine /src/bin/annotate /junits : echo '<details>Failure</details>'"
139+
140+
run "$PWD/hooks/command"
141+
142+
assert_success
143+
144+
assert_output --partial "Failures too large to annotate"
145+
146+
unstub docker
147+
unstub buildkite-agent
148+
unstub du
149+
unstub mktemp
150+
}

0 commit comments

Comments
 (0)