Skip to content

Commit 5753a37

Browse files
committed
Mergeback from master and resolve conflicts
2 parents 4f6f35d + b3dcdc9 commit 5753a37

File tree

4 files changed

+118
-21
lines changed

4 files changed

+118
-21
lines changed

README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ steps:
1414
- wait: ~
1515
continue_on_failure: true
1616
- plugins:
17-
- junit-annotate#v2.1.0:
17+
- junit-annotate#v2.2.0:
1818
artifacts: tmp/junit-*.xml
1919
```
2020
@@ -30,37 +30,42 @@ Example: `tmp/junit-*.xml`
3030

3131
Forces the creation of the annotation even when no failures or errors are found
3232

33+
### `context` (optional)
34+
35+
Default: `junit`
36+
37+
The buildkite annotation context to use. Useful to differentiate multiple runs of this plugin in a single pipeline.
38+
3339
### `job-uuid-file-pattern` (optional)
40+
3441
Default: `-(.*).xml`
3542

36-
The regular expression (with capture group) that matches the job UUID in the junit file names. This is used to create the job links in the annotation.
43+
The regular expression (with capture group) that matches the job UUID in the junit file names. This is used to create the job links in the annotation.
3744

3845
To use this, configure your test reporter to embed the `$BUILDKITE_JOB_ID` environment variable into your junit file names. For example `"junit-buildkite-job-$BUILDKITE_JOB_ID.xml"`.
3946

4047
### `failure-format` (optional)
41-
Default: `classname`
4248

4349
This setting controls the format of your failed test in the main annotation summary.
4450

4551
There are two options for this:
46-
* `classname`
52+
* `classname` (the default)
4753
* displays: `MyClass::UnderTest text of the failed expectation in path.to.my_class.under_test`
4854
* `file`
4955
* displays: `MyClass::UnderTest text of the failed expectation in path/to/my_class/under_test.file_ext`
5056

5157
### `fail-build-on-error` (optional)
58+
5259
Default: `false`
5360

54-
If this setting is true and any errors are found in the JUnit XML files during
55-
parsing, the annotation step will exit with a non-zero value, which should cause
56-
the build to fail.
61+
If this setting is true and any errors are found in the JUnit XML files during parsing, the annotation step will exit with a non-zero value, which should cause the build to fail.
5762

58-
### `context` (optional)
59-
Default: `junit`
63+
### `min-tests` (optional, integer)
6064

61-
The buildkite annotation context to use. Useful to differentiate multiple runs of this plugin in a single pipeline.
65+
Minimum amount of run tests that need to be analyzed or a failure will be reported. It is useful to ensure that tests are actually run and report files to analyze do contain information.
6266

6367
### `report-slowest` (optional)
68+
6469
Default: `0`
6570

6671
Include the specified number of slowest tests in the annotation. The annotation will always be shown.
@@ -93,7 +98,7 @@ To test your plugin in your builds prior to opening a pull request, you can refe
9398
steps:
9499
- label: Annotate
95100
plugins:
96-
- YourGithubHandle/junit-annotate#v2.1.0:
101+
- YourGithubHandle/junit-annotate#v2.2.0:
97102
...
98103
```
99104

hooks/command

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ if [ $has_errors -eq 0 ]; then
7777
echo "Will create annotation anyways"
7878
create_annotation=1
7979
fi
80+
81+
if [[ -e "${annotation_path}" ]]; then
82+
TOTAL_TESTS=$(head -4 "${annotation_path}" | grep 'Total tests' | cut -d\ -f3)
83+
else
84+
TOTAL_TESTS=0
85+
fi
86+
87+
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_MIN_TESTS:-0}" -gt "${TOTAL_TESTS}" ]]; then
88+
create_annotation=1
89+
fail_build=1
90+
echo ":warning: Less than ${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_MIN_TESTS} tests analyzed"
91+
fi
8092
elif ! check_size; then
8193
echo "--- :warning: Failures too large to annotate"
8294

plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ configuration:
2020
type: boolean
2121
job-uuid-file-pattern:
2222
type: string
23+
min-tests:
24+
type: integer
2325
report-slowest:
2426
type: integer
2527
ruby-image:

tests/command.bats

Lines changed: 88 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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 /src/bin/annotate /junits : echo '<details>Failure</details>' && 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 /src/bin/annotate /junits : echo '<details>Failure</details>' && 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 /src/bin/annotate /junits : echo '<details>Failure</details>' && 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 /src/bin/annotate /junits : echo No test errors"
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,13 +156,14 @@ 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 /src/bin/annotate /junits : echo No test errors"
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

163163
assert_success
164-
assert_output --partial "No test errors"
164+
assert_output --partial "Total tests: 0"
165165
assert_output --partial "Will create annotation anyways"
166+
assert_equal "$(cat "${annotation_input}")" 'Total tests: 0'
166167

167168
unstub mktemp
168169
unstub buildkite-agent
@@ -194,7 +195,7 @@ export annotation_input="tests/tmp/annotation.input"
194195
"artifact download \* \* : echo Downloaded artifact \$3 to \$4"
195196

196197
stub docker \
197-
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo '<details>Failure</details>' && 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"
198199

199200
run "$PWD/hooks/command"
200201

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

258259
stub docker \
259-
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo '<details>Failure</details>' && 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"
260261

261262
run "$PWD/hooks/command"
262263

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

287288
stub docker \
288-
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo '<details>Failure</details>' && 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"
289290

290291
run "$PWD/hooks/command"
291292

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

313314
stub docker \
314-
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo '<details>Failure</details>' && 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"
315316

316317
run "$PWD/hooks/command"
317318

@@ -345,6 +346,83 @@ export annotation_input="tests/tmp/annotation.input"
345346
unstub buildkite-agent
346347
}
347348

349+
@test "creates annotation with no failures but min tests triggers" {
350+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
351+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_MIN_TESTS=1
352+
353+
stub mktemp \
354+
"-d \* : mkdir -p '$artifacts_tmp'; echo '$artifacts_tmp'" \
355+
"-d \* : mkdir -p '$annotation_tmp'; echo '$annotation_tmp'"
356+
357+
stub buildkite-agent \
358+
"artifact download \* \* : echo Downloaded artifact \$3 to \$4" \
359+
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
360+
361+
stub docker \
362+
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo 'Total tests: 0'"
363+
364+
run "$PWD/hooks/command"
365+
366+
assert_failure
367+
assert_output --partial "Total tests: 0"
368+
assert_output --partial "Less than 1 tests analyzed"
369+
assert_equal "$(cat "${annotation_input}")" 'Total tests: 0'
370+
371+
unstub mktemp
372+
unstub buildkite-agent
373+
unstub docker
374+
}
375+
376+
@test "no failures and min-tests ok does not create annotation" {
377+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
378+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_MIN_TESTS=12
379+
380+
stub mktemp \
381+
"-d \* : mkdir -p '$artifacts_tmp'; echo '$artifacts_tmp'" \
382+
"-d \* : mkdir -p '$annotation_tmp'; echo '$annotation_tmp'"
383+
384+
stub buildkite-agent \
385+
"artifact download \* \* : echo Downloaded artifact \$3 to \$4"
386+
387+
stub docker \
388+
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* \* ruby /src/bin/annotate /junits : echo 'Total tests: 100'"
389+
390+
run "$PWD/hooks/command"
391+
392+
assert_success
393+
assert_output --partial "Total tests: 100"
394+
refute_output --partial "Less than 12 tests analyzed"
395+
396+
unstub mktemp
397+
unstub buildkite-agent
398+
unstub docker
399+
}
400+
401+
@test "min-tests doesn't interfere with actual failures" {
402+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
403+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_MIN_TESTS=10000
404+
405+
stub mktemp \
406+
"-d \* : mkdir -p '$artifacts_tmp'; echo '$artifacts_tmp'" \
407+
"-d \* : mkdir -p '$annotation_tmp'; echo '$annotation_tmp'"
408+
409+
stub buildkite-agent \
410+
"artifact download \* \* : echo Downloaded artifact \$3 to \$4" \
411+
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
412+
413+
stub docker \
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"
415+
416+
run "$PWD/hooks/command"
417+
418+
assert_success
419+
assert_output --partial "Total tests: 2"
420+
421+
unstub mktemp
422+
unstub buildkite-agent
423+
unstub docker
424+
}
425+
348426
@test "runs the annotator and creates the annotation with special image" {
349427
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
350428
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_RUBY_IMAGE="ruby:special"

0 commit comments

Comments
 (0)