From 210a0bf86b09393ad77e53211cb2c6edcfc15934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Fri, 28 Oct 2022 17:46:50 -0300 Subject: [PATCH 1/3] Add ruby-image option --- README.md | 6 ++++++ hooks/command | 3 ++- plugin.yml | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a0bf946..14f6d8e 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,12 @@ Default: `0` Include the specified number of slowest tests in the annotation. The annotation will always be shown. +### `ruby-image` (optional) + +The docker image to use for running the analysis code. Must be a valid image reference that can run the corresponding ruby code and the agent running the step must be able to pull it if not already present. + +Default: `ruby:3.1-alpine@sha256:a39e26d0598837f08c75a42c8b0886d9ed5cc862c4b535662922ee1d05272fca` + ## Developing To test the plugin hooks (in Bash) and the junit parser (in Ruby): diff --git a/hooks/command b/hooks/command index 7db1f15..d69eb2d 100755 --- a/hooks/command +++ b/hooks/command @@ -9,6 +9,7 @@ fi PLUGIN_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)/.." MAX_SIZE=1024 # in KB +RUBY_IMAGE="${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_RUBY_IMAGE:-'ruby:3.1-alpine@sha256:a39e26d0598837f08c75a42c8b0886d9ed5cc862c4b535662922ee1d05272fca'}" artifacts_dir="$(pwd)/$(mktemp -d "junit-annotate-plugin-artifacts-tmp.XXXXXXXXXX")" annotation_dir="$(pwd)/$(mktemp -d "junit-annotate-plugin-annotation-tmp.XXXXXXXXXX")" @@ -49,7 +50,7 @@ docker \ --env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN:-}" \ --env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT:-}" \ --env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST:-}" \ - ruby:2.7-alpine ruby /src/bin/annotate /junits \ + "${RUBY_IMAGE}" ruby /src/bin/annotate /junits \ > "$annotation_path" exit_code=$? diff --git a/plugin.yml b/plugin.yml index cc03bd7..dc96fc0 100644 --- a/plugin.yml +++ b/plugin.yml @@ -22,6 +22,8 @@ configuration: type: string report-slowest: type: integer + ruby-image: + type: string required: - artifacts additionalProperties: false From bfddd4b6f22106900907906bb5791de4fc932ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Fri, 28 Oct 2022 17:47:13 -0300 Subject: [PATCH 2/3] Generalized tests to make them independent from images --- tests/command.bats | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/command.bats b/tests/command.bats index 0300156..81acf7e 100644 --- a/tests/command.bats +++ b/tests/command.bats @@ -25,7 +25,7 @@ export annotation_input="tests/tmp/annotation.input" "annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved" stub docker \ - "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo '
Failure
' && exit 64" + "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo '
Failure
' && exit 64" run "$PWD/hooks/command" @@ -53,7 +53,7 @@ export annotation_input="tests/tmp/annotation.input" "annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved" stub docker \ - "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo '
Failure
' && exit 64" + "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo '
Failure
' && exit 64" run "$PWD/hooks/command" @@ -80,7 +80,7 @@ export annotation_input="tests/tmp/annotation.input" "annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved" stub docker \ - "--log-level error run --rm --volume \* --volume \* --env BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN='custom_(*)_pattern.xml' --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo '
Failure
' && exit 64" + "--log-level error run --rm --volume \* --volume \* --env BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN='custom_(*)_pattern.xml' --env \* --env \* \* ruby /src/bin/annotate /junits : echo '
Failure
' && exit 64" run "$PWD/hooks/command" @@ -107,7 +107,7 @@ export annotation_input="tests/tmp/annotation.input" "annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved" stub docker \ - "--log-level error run --rm --volume \* --volume \* --env \* --env BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT='file' --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo '
Failure
' && exit 64" + "--log-level error run --rm --volume \* --volume \* --env \* --env BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT='file' --env \* \* ruby /src/bin/annotate /junits : echo '
Failure
' && exit 64" run "$PWD/hooks/command" @@ -132,7 +132,7 @@ export annotation_input="tests/tmp/annotation.input" "artifact download \* \* : echo Downloaded artifact \$3 to \$4" stub docker \ - "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo No test errors" + "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo No test errors" run "$PWD/hooks/command" @@ -156,7 +156,7 @@ export annotation_input="tests/tmp/annotation.input" "annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved" stub docker \ - "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo No test errors" + "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo No test errors" run "$PWD/hooks/command" @@ -194,7 +194,7 @@ export annotation_input="tests/tmp/annotation.input" "artifact download \* \* : echo Downloaded artifact \$3 to \$4" stub docker \ - "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo '
Failure
' && exit 64" + "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo '
Failure
' && exit 64" run "$PWD/hooks/command" @@ -226,7 +226,7 @@ export annotation_input="tests/tmp/annotation.input" "annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved" stub docker \ - "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : cat tests/2-tests-1-failure.output && exit 64" + "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : cat tests/2-tests-1-failure.output && exit 64" run "$PWD/hooks/command" @@ -256,7 +256,7 @@ export annotation_input="tests/tmp/annotation.input" "annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved" stub docker \ - "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo '
Failure
' && exit 64" + "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo '
Failure
' && exit 64" run "$PWD/hooks/command" @@ -285,7 +285,7 @@ export annotation_input="tests/tmp/annotation.input" "artifact download \* \* : echo Downloaded artifact \$3 to \$4" stub docker \ - "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo '
Failure
' && exit 64" + "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo '
Failure
' && exit 64" run "$PWD/hooks/command" @@ -311,7 +311,7 @@ export annotation_input="tests/tmp/annotation.input" "artifact download \* \* : echo Downloaded artifact \$3 to \$4" stub docker \ - "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo '
Failure
' && exit 147" + "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo '
Failure
' && exit 147" run "$PWD/hooks/command" From 4f6f35d74a3e6248bf4e33811805421805577fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Fri, 28 Oct 2022 17:49:41 -0300 Subject: [PATCH 3/3] Added test for special ruby image --- tests/command.bats | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/command.bats b/tests/command.bats index 81acf7e..3a41a5e 100644 --- a/tests/command.bats +++ b/tests/command.bats @@ -343,4 +343,32 @@ export annotation_input="tests/tmp/annotation.input" unstub mktemp unstub buildkite-agent +} + +@test "runs the annotator and creates the annotation with special image" { + export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml" + export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_RUBY_IMAGE="ruby:special" + + stub mktemp \ + "-d \* : mkdir -p '$artifacts_tmp'; echo '$artifacts_tmp'" \ + "-d \* : mkdir -p '$annotation_tmp'; echo '$annotation_tmp'" + + stub buildkite-agent \ + "artifact download \* \* : echo Downloaded artifact \$3 to \$4" \ + "annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved" + + stub docker \ + "--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:special ruby /src/bin/annotate /junits : echo '
Failure
' && exit 64" + + run "$PWD/hooks/command" + + assert_success + + assert_output --partial "Annotation added with context junit and style error" + assert_equal "$(cat "${annotation_input}")" '
Failure
' + + unstub mktemp + unstub buildkite-agent + unstub docker + rm "${annotation_input}" } \ No newline at end of file