Skip to content

Commit

Permalink
Merge pull request #180 from buildkite-plugins/toote_ruby_tag
Browse files Browse the repository at this point in the history
Customize ruby tag (and update image to ruby 3.1)
  • Loading branch information
pzeballos authored Nov 2, 2022
2 parents b3dcdc9 + 5753a37 commit 8c6477f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,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):
Expand Down
3 changes: 2 additions & 1 deletion hooks/command
Original file line number Diff line number Diff line change
Expand Up @@ -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")"
Expand Down Expand Up @@ -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=$?
Expand Down
2 changes: 2 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ configuration:
type: integer
report-slowest:
type: integer
ruby-image:
type: string
required:
- artifacts
additionalProperties: false
56 changes: 42 additions & 14 deletions tests/command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<details>Failure</details>' && exit 64"
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo '<details>Failure</details>' && exit 64"

run "$PWD/hooks/command"

Expand Down Expand Up @@ -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 : 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"

Expand All @@ -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 : cat tests/2-tests-1-failure.output && 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 : cat tests/2-tests-1-failure.output && exit 64"

run "$PWD/hooks/command"

Expand All @@ -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 : cat tests/2-tests-1-failure.output && exit 64"
"--log-level error run --rm --volume \* --volume \* --env \* --env BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT='file' --env \* \* ruby /src/bin/annotate /junits : cat tests/2-tests-1-failure.output && exit 64"

run "$PWD/hooks/command"

Expand All @@ -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 'Total tests: 0'"
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo 'Total tests: 0'"

run "$PWD/hooks/command"

Expand All @@ -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 'Total tests: 0'"
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo 'Total tests: 0'"

run "$PWD/hooks/command"

Expand Down Expand Up @@ -195,7 +195,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 : 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"

Expand Down Expand Up @@ -227,7 +227,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"

Expand Down Expand Up @@ -257,7 +257,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"

Expand Down Expand Up @@ -286,7 +286,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 : 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"

Expand All @@ -312,7 +312,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 : cat tests/2-tests-1-failure.output && exit 147"
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : cat tests/2-tests-1-failure.output && exit 147"

run "$PWD/hooks/command"

Expand Down Expand Up @@ -359,7 +359,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 'Total tests: 0'"
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo 'Total tests: 0'"

run "$PWD/hooks/command"

Expand All @@ -385,7 +385,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 'Total tests: 100'"
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo 'Total tests: 100'"

run "$PWD/hooks/command"

Expand All @@ -411,7 +411,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"

Expand All @@ -421,4 +421,32 @@ export annotation_input="tests/tmp/annotation.input"
unstub mktemp
unstub buildkite-agent
unstub docker
}

@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 '<details>Failure</details>' && exit 64"

run "$PWD/hooks/command"

assert_success

assert_output --partial "Annotation added with context junit and style error"
assert_equal "$(cat "${annotation_input}")" '<details>Failure</details>'

unstub mktemp
unstub buildkite-agent
unstub docker
rm "${annotation_input}"
}

0 comments on commit 8c6477f

Please sign in to comment.