From c3dfc37859a19d02c2804192e2b958eb3aa801ce Mon Sep 17 00:00:00 2001 From: Colin Mitchell Date: Wed, 3 Nov 2021 13:23:06 -0400 Subject: [PATCH 1/2] Add option for annotation with notice if too many errors overall --- hooks/command | 37 ++++++++++++++++++++++++++----------- plugin.yml | 4 ++++ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/hooks/command b/hooks/command index 4a874df..2a4d676 100755 --- a/hooks/command +++ b/hooks/command @@ -103,17 +103,27 @@ if [ $has_errors -eq 0 ]; then elif ! check_size; then echo "--- :warning: Failures too large to annotate" - # creating a simplified version of the annotation - mv "${annotation_path}" "${annotation_path}2" - head -5 "${annotation_path}2" >"${annotation_path}" - # || true is to avoid issues if no summary is found - grep '' "${annotation_path}2" >>"${annotation_path}" || true - - if ! check_size; then - echo "The failures are too large to create a build annotation. Please inspect the failed JUnit artifacts manually." - create_annotation=0 + if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ADD_ERROR_ANNOTATION:-false}" =~ (true|on|1) ]]; then + fail_build=1 + echo "--- :buildkite: Creating failure annotation" + annotation_path="${annotation_dir}/failed-annotation.md" + echo "
The failures are too large to create a build annotation. Please inspect the failures manually.
" > ${annotation_path} + # | buildkite-agent annotate --context "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_CONTEXT:-junit}" --style "$annotation_style" + + create_annotation=1 else - echo "The failures are too large to create complete annotation, using a simplified annotation" + # creating a simplified version of the annotation + mv "${annotation_path}" "${annotation_path}2" + head -5 "${annotation_path}2" >"${annotation_path}" + # || true is to avoid issues if no summary is found + grep '' "${annotation_path}2" >>"${annotation_path}" || true + + if ! check_size; then + echo "The failures are too large to create a build annotation. Please inspect the failed JUnit artifacts manually." + create_annotation=0 + else + echo "The failures are too large to create complete annotation, using a simplified annotation" + fi fi fi @@ -123,4 +133,9 @@ if [ $create_annotation -ne 0 ]; then cat "$annotation_path" | buildkite-agent annotate --context "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_CONTEXT:-junit}" --style "$annotation_style" fi -exit $fail_build +if ((fail_build)); then + echo "--- :boom: Failing build due to error" + exit 1 +else + exit 0 +fi \ No newline at end of file diff --git a/plugin.yml b/plugin.yml index c2da785..a3a69f4 100644 --- a/plugin.yml +++ b/plugin.yml @@ -22,6 +22,10 @@ configuration: type: integer job-uuid-file-pattern: type: string + add-error-annotation: + type: boolean + context: + type: string min-tests: type: integer report-skipped: From 92d017f75f2f17059044dff00ba17d23933b2a26 Mon Sep 17 00:00:00 2001 From: muffinista Date: Fri, 2 Aug 2024 12:54:54 -0400 Subject: [PATCH 2/2] Add style config variable --- hooks/command | 6 +++--- plugin.yml | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/hooks/command b/hooks/command index 2a4d676..1d9e467 100755 --- a/hooks/command +++ b/hooks/command @@ -14,11 +14,12 @@ RUBY_IMAGE="${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_RUBY_IMAGE:-ruby:3.1-alpine@sha256 artifacts_dir="$(pwd)/$(mktemp -d "junit-annotate-plugin-artifacts-tmp.XXXXXXXXXX")" annotation_dir="$(pwd)/$(mktemp -d "junit-annotate-plugin-annotation-tmp.XXXXXXXXXX")" annotation_path="${annotation_dir}/annotation.md" -annotation_style="info" +annotation_style="${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_STYLE:-info}" fail_build=0 has_errors=0 create_annotation=0 + # shellcheck disable=2317 # this is a signal function function cleanup { rm -rf "${artifacts_dir}" @@ -65,7 +66,7 @@ set -e if [[ $exit_code -eq 64 ]]; then # special exit code to signal test failures has_errors=1 create_annotation=1 - annotation_style="error" + # annotation_style="error" if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR:-false}" =~ (true|on|1) ]]; then echo "--- :boom: Build will fail due to errors being found" fail_build=1 @@ -108,7 +109,6 @@ elif ! check_size; then echo "--- :buildkite: Creating failure annotation" annotation_path="${annotation_dir}/failed-annotation.md" echo "
The failures are too large to create a build annotation. Please inspect the failures manually.
" > ${annotation_path} - # | buildkite-agent annotate --context "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_CONTEXT:-junit}" --style "$annotation_style" create_annotation=1 else diff --git a/plugin.yml b/plugin.yml index a3a69f4..676127d 100644 --- a/plugin.yml +++ b/plugin.yml @@ -36,6 +36,8 @@ configuration: type: string run-in-docker: type: boolean + style: + type: string required: - artifacts additionalProperties: false