File tree Expand file tree Collapse file tree 3 files changed +45
-1
lines changed Expand file tree Collapse file tree 3 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ the build to fail.
53
53
54
54
# # Developing
55
55
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 ) :
57
57
58
58
` ` ` bash
59
59
docker-compose run --rm plugin &&
Original file line number Diff line number Diff line change 3
3
set -euo pipefail
4
4
5
5
PLUGIN_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) /.."
6
+ MAX_SIZE=100 # in KB
6
7
7
8
echo " --- :junit: Download the junits"
8
9
@@ -15,6 +16,12 @@ function cleanup {
15
16
rm -rf " ${annotation_dir} "
16
17
}
17
18
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
+
18
25
trap cleanup EXIT
19
26
20
27
buildkite-agent artifact download \
@@ -37,6 +44,13 @@ docker \
37
44
cat " $annotation_path "
38
45
39
46
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
+
40
54
echo " --- :buildkite: Creating annotation"
41
55
# shellcheck disable=SC2002
42
56
cat " $annotation_path " | buildkite-agent annotate --context junit --style error
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ load "$BATS_PATH/load.bash"
6
6
# export MKTEMP_STUB_DEBUG=/dev/tty
7
7
# export BUILDKITE_AGENT_STUB_DEBUG=/dev/tty
8
8
# export DOCKER_STUB_DEBUG=/dev/tty
9
+ # export DU_STUB_DEBUG=/dev/tty
9
10
10
11
@test " runs the annotator and creates the annotation" {
11
12
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS=" junits/*.xml"
@@ -118,3 +119,32 @@ load "$BATS_PATH/load.bash"
118
119
119
120
assert_output --partial " BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS: unbound variable"
120
121
}
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
+ }
You can’t perform that action at this time.
0 commit comments