Skip to content

Commit 8c6477f

Browse files
authored
Merge pull request #180 from buildkite-plugins/toote_ruby_tag
Customize ruby tag (and update image to ruby 3.1)
2 parents b3dcdc9 + 5753a37 commit 8c6477f

File tree

4 files changed

+52
-15
lines changed

4 files changed

+52
-15
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ Default: `0`
7070

7171
Include the specified number of slowest tests in the annotation. The annotation will always be shown.
7272

73+
### `ruby-image` (optional)
74+
75+
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.
76+
77+
Default: `ruby:3.1-alpine@sha256:a39e26d0598837f08c75a42c8b0886d9ed5cc862c4b535662922ee1d05272fca`
78+
7379
## Developing
7480

7581
To test the plugin hooks (in Bash) and the junit parser (in Ruby):

hooks/command

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fi
99

1010
PLUGIN_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)/.."
1111
MAX_SIZE=1024 # in KB
12+
RUBY_IMAGE="${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_RUBY_IMAGE:-'ruby:3.1-alpine@sha256:a39e26d0598837f08c75a42c8b0886d9ed5cc862c4b535662922ee1d05272fca'}"
1213

1314
artifacts_dir="$(pwd)/$(mktemp -d "junit-annotate-plugin-artifacts-tmp.XXXXXXXXXX")"
1415
annotation_dir="$(pwd)/$(mktemp -d "junit-annotate-plugin-annotation-tmp.XXXXXXXXXX")"
@@ -49,7 +50,7 @@ docker \
4950
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN:-}" \
5051
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT:-}" \
5152
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST:-}" \
52-
ruby:2.7-alpine ruby /src/bin/annotate /junits \
53+
"${RUBY_IMAGE}" ruby /src/bin/annotate /junits \
5354
> "$annotation_path"
5455

5556
exit_code=$?

plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ configuration:
2424
type: integer
2525
report-slowest:
2626
type: integer
27+
ruby-image:
28+
type: string
2729
required:
2830
- artifacts
2931
additionalProperties: false

tests/command.bats

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export annotation_input="tests/tmp/annotation.input"
2525
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
2626

2727
stub docker \
28-
"--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"
28+
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo '<details>Failure</details>' && exit 64"
2929

3030
run "$PWD/hooks/command"
3131

@@ -53,7 +53,7 @@ export annotation_input="tests/tmp/annotation.input"
5353
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
5454

5555
stub docker \
56-
"--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"
56+
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : cat tests/2-tests-1-failure.output && exit 64"
5757

5858
run "$PWD/hooks/command"
5959

@@ -80,7 +80,7 @@ export annotation_input="tests/tmp/annotation.input"
8080
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
8181

8282
stub docker \
83-
"--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"
83+
"--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"
8484

8585
run "$PWD/hooks/command"
8686

@@ -107,7 +107,7 @@ export annotation_input="tests/tmp/annotation.input"
107107
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
108108

109109
stub docker \
110-
"--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"
110+
"--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"
111111

112112
run "$PWD/hooks/command"
113113

@@ -132,7 +132,7 @@ export annotation_input="tests/tmp/annotation.input"
132132
"artifact download \* \* : echo Downloaded artifact \$3 to \$4"
133133

134134
stub docker \
135-
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo 'Total tests: 0'"
135+
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo 'Total tests: 0'"
136136

137137
run "$PWD/hooks/command"
138138

@@ -156,7 +156,7 @@ export annotation_input="tests/tmp/annotation.input"
156156
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
157157

158158
stub docker \
159-
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo 'Total tests: 0'"
159+
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo 'Total tests: 0'"
160160

161161
run "$PWD/hooks/command"
162162

@@ -195,7 +195,7 @@ export annotation_input="tests/tmp/annotation.input"
195195
"artifact download \* \* : echo Downloaded artifact \$3 to \$4"
196196

197197
stub docker \
198-
"--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"
198+
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : cat tests/2-tests-1-failure.output && exit 64"
199199

200200
run "$PWD/hooks/command"
201201

@@ -227,7 +227,7 @@ export annotation_input="tests/tmp/annotation.input"
227227
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
228228

229229
stub docker \
230-
"--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"
230+
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : cat tests/2-tests-1-failure.output && exit 64"
231231

232232
run "$PWD/hooks/command"
233233

@@ -257,7 +257,7 @@ export annotation_input="tests/tmp/annotation.input"
257257
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
258258

259259
stub docker \
260-
"--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"
260+
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : cat tests/2-tests-1-failure.output && exit 64"
261261

262262
run "$PWD/hooks/command"
263263

@@ -286,7 +286,7 @@ export annotation_input="tests/tmp/annotation.input"
286286
"artifact download \* \* : echo Downloaded artifact \$3 to \$4"
287287

288288
stub docker \
289-
"--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"
289+
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : cat tests/2-tests-1-failure.output && exit 64"
290290

291291
run "$PWD/hooks/command"
292292

@@ -312,7 +312,7 @@ export annotation_input="tests/tmp/annotation.input"
312312
"artifact download \* \* : echo Downloaded artifact \$3 to \$4"
313313

314314
stub docker \
315-
"--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"
315+
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : cat tests/2-tests-1-failure.output && exit 147"
316316

317317
run "$PWD/hooks/command"
318318

@@ -359,7 +359,7 @@ export annotation_input="tests/tmp/annotation.input"
359359
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
360360

361361
stub docker \
362-
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo 'Total tests: 0'"
362+
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo 'Total tests: 0'"
363363

364364
run "$PWD/hooks/command"
365365

@@ -385,7 +385,7 @@ export annotation_input="tests/tmp/annotation.input"
385385
"artifact download \* \* : echo Downloaded artifact \$3 to \$4"
386386

387387
stub docker \
388-
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo 'Total tests: 100'"
388+
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo 'Total tests: 100'"
389389

390390
run "$PWD/hooks/command"
391391

@@ -411,7 +411,7 @@ export annotation_input="tests/tmp/annotation.input"
411411
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
412412

413413
stub docker \
414-
"--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"
414+
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : cat tests/2-tests-1-failure.output && exit 64"
415415

416416
run "$PWD/hooks/command"
417417

@@ -421,4 +421,32 @@ export annotation_input="tests/tmp/annotation.input"
421421
unstub mktemp
422422
unstub buildkite-agent
423423
unstub docker
424+
}
425+
426+
@test "runs the annotator and creates the annotation with special image" {
427+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
428+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_RUBY_IMAGE="ruby:special"
429+
430+
stub mktemp \
431+
"-d \* : mkdir -p '$artifacts_tmp'; echo '$artifacts_tmp'" \
432+
"-d \* : mkdir -p '$annotation_tmp'; echo '$annotation_tmp'"
433+
434+
stub buildkite-agent \
435+
"artifact download \* \* : echo Downloaded artifact \$3 to \$4" \
436+
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
437+
438+
stub docker \
439+
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:special ruby /src/bin/annotate /junits : echo '<details>Failure</details>' && exit 64"
440+
441+
run "$PWD/hooks/command"
442+
443+
assert_success
444+
445+
assert_output --partial "Annotation added with context junit and style error"
446+
assert_equal "$(cat "${annotation_input}")" '<details>Failure</details>'
447+
448+
unstub mktemp
449+
unstub buildkite-agent
450+
unstub docker
451+
rm "${annotation_input}"
424452
}

0 commit comments

Comments
 (0)