Skip to content

Commit ddca153

Browse files
committed
Ensure fail-on-error works for large annotations
1 parent 4368cad commit ddca153

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

hooks/command

+6-7
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ cat "$annotation_path"
4646
if grep -q "<details>" "$annotation_path"; then
4747

4848
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
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+
else
52+
echo "--- :buildkite: Creating annotation"
53+
# shellcheck disable=SC2002
54+
cat "$annotation_path" | buildkite-agent annotate --context "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_CONTEXT:-junit}" --style error
5255
fi
5356

54-
echo "--- :buildkite: Creating annotation"
55-
# shellcheck disable=SC2002
56-
cat "$annotation_path" | buildkite-agent annotate --context "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_CONTEXT:-junit}" --style error
57-
5857
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR:-false}" =~ (true|on|1) ]]
5958
then
6059
echo "--- :boom: Failing build due to error"

tests/command.bats

+29
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,33 @@ load "$BATS_PATH/load.bash"
148148
unstub buildkite-agent
149149
unstub du
150150
unstub mktemp
151+
}
152+
153+
@test "returns an error if fail-build-on-error is true and annotation is too large" {
154+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
155+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR=true
156+
157+
artifacts_tmp="tests/tmp/$PWD/junit-artifacts"
158+
annotation_tmp="tests/tmp/$PWD/junit-annotation"
159+
160+
stub mktemp \
161+
"-d junit-annotate-plugin-artifacts-tmp.XXXXXXXXXX : mkdir -p $artifacts_tmp; echo $artifacts_tmp" \
162+
"-d junit-annotate-plugin-annotation-tmp.XXXXXXXXXX : mkdir -p $annotation_tmp; echo $annotation_tmp"
163+
164+
# 1KB over the 1MB size limit of annotations
165+
stub du "-k /plugin/tests/tmp//plugin/junit-annotation/annotation.md : echo 1025 /plugin/tests/tmp//plugin/junit-annotation/annotation.md"
166+
167+
stub buildkite-agent "artifact download junits/*.xml /plugin/tests/tmp//plugin/junit-artifacts : echo Downloaded artifacts"
168+
169+
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.7-alpine ruby /src/bin/annotate /junits : echo '<details>Failure</details>'"
170+
171+
run "$PWD/hooks/command"
172+
173+
assert_failure
174+
175+
assert_output --partial "Failures too large to annotate"
176+
177+
unstub mktemp
178+
unstub buildkite-agent
179+
unstub docker
151180
}

0 commit comments

Comments
 (0)