@@ -15,6 +15,8 @@ annotation_dir="$(pwd)/$(mktemp -d "junit-annotate-plugin-annotation-tmp.XXXXXXX
1515annotation_path=" ${annotation_dir} /annotation.md"
1616annotation_style=" info"
1717fail_build=0
18+ has_errors=0
19+ create_annotation=0
1820
1921function cleanup {
2022 rm -rf " ${artifacts_dir} "
@@ -54,8 +56,11 @@ exit_code=$?
5456set -e
5557
5658if [[ $exit_code -eq 64 ]]; then # special exit code to signal test failures
59+ has_errors=1
60+ create_annotation=1
5761 annotation_style=" error"
5862 if [[ " ${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR:- false} " =~ (true| on| 1) ]]; then
63+ echo " --- :boom: Build will fail due to errors being found"
5964 fail_build=1
6065 fi
6166elif [[ $exit_code -ne 0 ]]; then
6570
6671cat " $annotation_path "
6772
68- if grep -q " <details>" " $annotation_path " ; then
73+ if [ $has_errors -eq 0 ]; then
74+ # done in nested if to simplify outer conditions
75+ if [[ " ${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ALWAYS_ANNOTATE:- false} " =~ (true| on| 1) ]]; then
76+ echo " Will create annotation anyways"
77+ create_annotation=1
78+ fi
79+ elif ! check_size; then
80+ echo " --- :warning: Failures too large to annotate"
81+
82+ # creating a simplified version of the annotation
83+ mv " ${annotation_path} " " ${annotation_path} 2"
84+ head -4 " ${annotation_path} 2" > " ${annotation_path} "
85+ # || true is to avoid issues if no summary is found
86+ grep ' <summary>' " ${annotation_path} 2" >> " ${annotation_path} " || true
87+
6988 if ! check_size; then
70- echo " --- :warning: Failures too large to annotate"
71- msg=" The failures are too large to create a build annotation. Please inspect the failed JUnit artifacts manually."
72- echo " $msg "
89+ echo " The failures are too large to create a build annotation. Please inspect the failed JUnit artifacts manually."
90+ create_annotation=0
7391 else
74- echo " --- :buildkite: Creating annotation"
75- # shellcheck disable=SC2002
76- cat " $annotation_path " | buildkite-agent annotate --context " ${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_CONTEXT:- junit} " --style " $annotation_style "
92+ echo " The failures are too large to create complete annotation, using a simplified annotation"
7793 fi
7894fi
7995
80- if (( fail_build)) ; then
81- echo " --- :boom: Failing build due to error"
82- exit 1
83- else
84- exit 0
96+ if [ $create_annotation -ne 0 ]; then
97+ echo " --- :buildkite: Creating annotation"
98+ # shellcheck disable=SC2002
99+ cat " $annotation_path " | buildkite-agent annotate --context " ${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_CONTEXT:- junit} " --style " $annotation_style "
85100fi
101+
102+ exit $fail_build
0 commit comments