Skip to content

Commit 4babc44

Browse files
Jd updates (#3)
* Merge pull request buildkite-plugins#166 from buildkite-plugins/renovate/ruby-3.1-alpine Update ruby:3.1-alpine Docker digest to c5acbb8 * Merge pull request buildkite-plugins#173 from buildkite-plugins/toote_test_revamp Test revamp & dependency update * Merge pull request buildkite-plugins#174 from buildkite-plugins/toote_summary_issue_136 Test summary Co-authored-by: Matías Bellone <[email protected]>
1 parent c866d54 commit 4babc44

File tree

9 files changed

+416
-179
lines changed

9 files changed

+416
-179
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ The local directory holding the JUnit XML files.
2323

2424
Example: `tmp/junit-*.xml`
2525

26+
### `always-annotate` (optional, boolean)
27+
28+
Forces the creation of the annotation even when no failures or errors are found
29+
2630
### `job-uuid-file-pattern` (optional)
2731
Default: `-(.*).xml`
2832

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ services:
66
volumes:
77
- ".:/plugin"
88
plugin:
9-
image: buildkite/plugin-tester:latest@sha256:476a1024936901889147f53d2a3d8e71e99d76404972d583825514f5608083dc
9+
image: buildkite/plugin-tester:v3.0.1
1010
volumes:
1111
- ".:/plugin"
1212
depends_on:
1313
- ruby
1414
ruby:
15-
image: ruby:3.1-alpine@sha256:0b91e98c4613c2287bb7274a1584ea141b68960fb6b0edd7fe32127dc888d1a0
15+
image: ruby:3.1-alpine@sha256:c5acbb8bcc57cc3cb8da7f28077ec23c9c05217f26bd4e156d7b87df6dcf0c00
1616
command: rake
1717
working_dir: /src
1818
volumes:

hooks/post-command

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ annotation_dir="$(pwd)/$(mktemp -d "junit-annotate-plugin-annotation-tmp.XXXXXXX
1515
annotation_path="${annotation_dir}/annotation.md"
1616
annotation_style="info"
1717
fail_build=0
18+
has_errors=0
19+
create_annotation=0
1820

1921
function cleanup {
2022
rm -rf "${annotation_dir}"
@@ -45,39 +47,58 @@ docker \
4547
ruby:2.7-alpine ruby /src/bin/annotate /junits \
4648
> "$annotation_path"
4749

48-
if [[ $? -eq 64 ]]; then # special exit code to signal test failures
50+
exit_code=$?
51+
set -e
52+
53+
if [[ $exit_code -eq 64 ]]; then # special exit code to signal test failures
54+
has_errors=1
55+
create_annotation=1
4956
annotation_style="error"
5057
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_FAIL_BUILD_ON_ERROR:-false}" =~ (true|on|1) ]]; then
58+
echo "--- :boom: Build will fail due to errors being found"
5159
fail_build=1
5260
fi
61+
elif [[ $exit_code -ne 0 ]]; then
62+
echo "--- :boom: Error when processing JUnit tests"
63+
exit $exit_code
5364
fi
5465

55-
set -e
56-
5766
cat "$annotation_path"
5867

59-
if grep -q "<details>" "$annotation_path"; then
68+
if [ $has_errors -eq 0 ]; then
69+
# done in nested if to simplify outer conditions
70+
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_ALWAYS_ANNOTATE:-false}" =~ (true|on|1) ]]; then
71+
echo "Will create annotation anyways"
72+
create_annotation=1
73+
fi
74+
elif ! check_size; then
75+
echo "--- :warning: Failures too large to annotate"
76+
77+
# creating a simplified version of the annotation
78+
mv "${annotation_path}" "${annotation_path}2"
79+
head -4 "${annotation_path}2" >"${annotation_path}"
80+
# || true is to avoid issues if no summary is found
81+
grep '<summary>' "${annotation_path}2" >>"${annotation_path}" || true
82+
6083
if ! check_size; then
61-
echo "--- :warning: Failures too large to annotate"
62-
msg="The failures are too large to create a build annotation. Please inspect the failed JUnit artifacts manually."
63-
echo "$msg"
84+
echo "The failures are too large to create a build annotation. Please inspect the failed JUnit artifacts manually."
85+
create_annotation=0
6486
else
65-
echo "--- :buildkite: Creating annotation"
66-
args=(
67-
--context "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_CONTEXT:-junit}"
68-
--style "$annotation_style"
69-
)
70-
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_APPEND:-false}" =~ (true|on|1) ]]; then
71-
args+=( --append )
72-
fi
73-
# shellcheck disable=SC2002
74-
cat "$annotation_path" | buildkite-agent annotate "${args[@]}"
87+
echo "The failures are too large to create complete annotation, using a simplified annotation"
7588
fi
7689
fi
7790

78-
if ((fail_build)); then
79-
echo "--- :boom: Failing build due to error"
80-
exit 1
81-
else
82-
exit 0
91+
if [ $create_annotation -ne 0 ]; then
92+
echo "--- :buildkite: Creating annotation"
93+
args=(
94+
--context "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_CONTEXT:-junit}"
95+
--style "$annotation_style"
96+
)
97+
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_APPEND:-false}" =~ (true|on|1) ]]; then
98+
args+=( --append )
99+
fi
100+
# shellcheck disable=SC2002
101+
cat "$annotation_path" | buildkite-agent annotate "${args[@]}"
83102
fi
103+
104+
exit $fail_build

plugin.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ configuration:
77
properties:
88
directory:
99
type: string
10-
job-uuid-file-pattern:
10+
always-annotate:
11+
type: boolean
12+
context:
1113
type: string
1214
failure-format:
1315
type: string
@@ -16,7 +18,7 @@ configuration:
1618
- file
1719
fail-build-on-error:
1820
type: boolean
19-
context:
21+
job-uuid-file-pattern:
2022
type: string
2123
report-slowest:
2224
type: integer

renovate.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": [
3-
"config:base"
3+
"config:base",
4+
":disableDependencyDashboard"
45
],
56
"bundler": {
67
"enabled": true

ruby/bin/annotate

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ junits_dir = ARGV[0]
1111
abort("Usage: annotate <junits-dir>") unless junits_dir
1212
abort("#{junits_dir} does not exist") unless Dir.exist?(junits_dir)
1313

14-
job_pattern = ENV['BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN']
14+
job_pattern = ENV['BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_JOB_UUID_FILE_PATTERN']
1515
job_pattern = '-(.*).xml' if !job_pattern || job_pattern.empty?
1616

17-
failure_format = ENV['BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT']
17+
failure_format = ENV['BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_FAILURE_FORMAT']
1818
failure_format = 'classname' if !failure_format || failure_format.empty?
1919

20-
report_slowest = ENV['BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST'].to_i
20+
report_slowest = ENV['BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_REPORT_SLOWEST'].to_i
2121

2222
class Failure < Struct.new(:name, :unit_name, :body, :job, :type, :message)
2323
end
@@ -74,41 +74,33 @@ junit_report_files.sort.each do |file|
7474
end
7575

7676
STDERR.puts "--- ✍️ Preparing annotation"
77-
STDERR.puts "#{testcases} testcases found"
78-
79-
if failures.any?
80-
STDERR.puts "There #{failures.length == 1 ? "is 1 failure/error" : "are #{failures.length} failures/errors" } 😭"
81-
82-
failures_count = failures.select {|f| f.type == :failure }.length
83-
errors_count = failures.select {|f| f.type == :error }.length
84-
puts [
85-
failures_count == 0 ? nil : (failures_count == 1 ? "1 failure" : "#{failures_count} failures"),
86-
errors_count === 0 ? nil : (errors_count == 1 ? "1 error" : "#{errors_count} errors"),
87-
].compact.join(" and ") + ":\n\n"
88-
89-
failures.each do |failure|
90-
puts "<details>"
91-
puts "<summary><code>#{failure.name} in #{failure.unit_name}</code></summary>\n\n"
92-
if failure.message
93-
puts "<p>#{failure.message.chomp.strip}</p>\n\n"
94-
end
95-
if failure.body
96-
puts "<pre><code>#{CGI.escapeHTML(failure.body.chomp.strip)}</code></pre>\n\n"
97-
end
98-
if failure.job
99-
puts "in <a href=\"##{failure.job}\">Job ##{failure.job}</a>"
100-
end
101-
puts "</details>"
102-
puts "" unless failure == failures.last
103-
end
10477

105-
else
106-
STDERR.puts "There were no failures/errors 🙌"
78+
failures_count = failures.select {|f| f.type == :failure }.length
79+
errors_count = failures.select {|f| f.type == :error }.length
80+
81+
puts "Failures: #{failures_count}"
82+
puts "Errors: #{errors_count}"
83+
puts "Total tests: #{testcases}"
84+
85+
failures.each do |failure|
86+
puts ""
87+
puts "<details>"
88+
puts "<summary><code>#{failure.name} in #{failure.unit_name}</code></summary>\n\n"
89+
if failure.message
90+
puts "<p>#{failure.message.chomp.strip}</p>\n\n"
91+
end
92+
if failure.body
93+
puts "<pre><code>#{CGI.escapeHTML(failure.body.chomp.strip)}</code></pre>\n\n"
94+
end
95+
if failure.job
96+
puts "in <a href=\"##{failure.job}\">Job ##{failure.job}</a>"
97+
end
98+
puts "</details>"
10799
end
108100

109101
if report_slowest > 0
110102
STDERR.puts "Reporting slowest tests ⏱"
111-
103+
puts ""
112104
puts "<details>"
113105
puts "<summary>#{report_slowest} slowest tests</summary>\n\n"
114106
puts "<table>"

0 commit comments

Comments
 (0)