Skip to content

Commit

Permalink
Jd updates (#3)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
juandiegopalomino and toote authored Oct 18, 2022
1 parent c866d54 commit 4babc44
Show file tree
Hide file tree
Showing 9 changed files with 416 additions and 179 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ The local directory holding the JUnit XML files.

Example: `tmp/junit-*.xml`

### `always-annotate` (optional, boolean)

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

### `job-uuid-file-pattern` (optional)
Default: `-(.*).xml`

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ services:
volumes:
- ".:/plugin"
plugin:
image: buildkite/plugin-tester:latest@sha256:476a1024936901889147f53d2a3d8e71e99d76404972d583825514f5608083dc
image: buildkite/plugin-tester:v3.0.1
volumes:
- ".:/plugin"
depends_on:
- ruby
ruby:
image: ruby:3.1-alpine@sha256:0b91e98c4613c2287bb7274a1584ea141b68960fb6b0edd7fe32127dc888d1a0
image: ruby:3.1-alpine@sha256:c5acbb8bcc57cc3cb8da7f28077ec23c9c05217f26bd4e156d7b87df6dcf0c00
command: rake
working_dir: /src
volumes:
Expand Down
65 changes: 43 additions & 22 deletions hooks/post-command
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ annotation_dir="$(pwd)/$(mktemp -d "junit-annotate-plugin-annotation-tmp.XXXXXXX
annotation_path="${annotation_dir}/annotation.md"
annotation_style="info"
fail_build=0
has_errors=0
create_annotation=0

function cleanup {
rm -rf "${annotation_dir}"
Expand Down Expand Up @@ -45,39 +47,58 @@ docker \
ruby:2.7-alpine ruby /src/bin/annotate /junits \
> "$annotation_path"

if [[ $? -eq 64 ]]; then # special exit code to signal test failures
exit_code=$?
set -e

if [[ $exit_code -eq 64 ]]; then # special exit code to signal test failures
has_errors=1
create_annotation=1
annotation_style="error"
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_FAIL_BUILD_ON_ERROR:-false}" =~ (true|on|1) ]]; then
echo "--- :boom: Build will fail due to errors being found"
fail_build=1
fi
elif [[ $exit_code -ne 0 ]]; then
echo "--- :boom: Error when processing JUnit tests"
exit $exit_code
fi

set -e

cat "$annotation_path"

if grep -q "<details>" "$annotation_path"; then
if [ $has_errors -eq 0 ]; then
# done in nested if to simplify outer conditions
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_ALWAYS_ANNOTATE:-false}" =~ (true|on|1) ]]; then
echo "Will create annotation anyways"
create_annotation=1
fi
elif ! check_size; then
echo "--- :warning: Failures too large to annotate"

# creating a simplified version of the annotation
mv "${annotation_path}" "${annotation_path}2"
head -4 "${annotation_path}2" >"${annotation_path}"
# || true is to avoid issues if no summary is found
grep '<summary>' "${annotation_path}2" >>"${annotation_path}" || true

if ! check_size; then
echo "--- :warning: Failures too large to annotate"
msg="The failures are too large to create a build annotation. Please inspect the failed JUnit artifacts manually."
echo "$msg"
echo "The failures are too large to create a build annotation. Please inspect the failed JUnit artifacts manually."
create_annotation=0
else
echo "--- :buildkite: Creating annotation"
args=(
--context "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_CONTEXT:-junit}"
--style "$annotation_style"
)
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_APPEND:-false}" =~ (true|on|1) ]]; then
args+=( --append )
fi
# shellcheck disable=SC2002
cat "$annotation_path" | buildkite-agent annotate "${args[@]}"
echo "The failures are too large to create complete annotation, using a simplified annotation"
fi
fi

if ((fail_build)); then
echo "--- :boom: Failing build due to error"
exit 1
else
exit 0
if [ $create_annotation -ne 0 ]; then
echo "--- :buildkite: Creating annotation"
args=(
--context "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_CONTEXT:-junit}"
--style "$annotation_style"
)
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_APPEND:-false}" =~ (true|on|1) ]]; then
args+=( --append )
fi
# shellcheck disable=SC2002
cat "$annotation_path" | buildkite-agent annotate "${args[@]}"
fi

exit $fail_build
6 changes: 4 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ configuration:
properties:
directory:
type: string
job-uuid-file-pattern:
always-annotate:
type: boolean
context:
type: string
failure-format:
type: string
Expand All @@ -16,7 +18,7 @@ configuration:
- file
fail-build-on-error:
type: boolean
context:
job-uuid-file-pattern:
type: string
report-slowest:
type: integer
Expand Down
3 changes: 2 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": [
"config:base"
"config:base",
":disableDependencyDashboard"
],
"bundler": {
"enabled": true
Expand Down
58 changes: 25 additions & 33 deletions ruby/bin/annotate
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ junits_dir = ARGV[0]
abort("Usage: annotate <junits-dir>") unless junits_dir
abort("#{junits_dir} does not exist") unless Dir.exist?(junits_dir)

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

failure_format = ENV['BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT']
failure_format = ENV['BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_FAILURE_FORMAT']
failure_format = 'classname' if !failure_format || failure_format.empty?

report_slowest = ENV['BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST'].to_i
report_slowest = ENV['BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_REPORT_SLOWEST'].to_i

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

STDERR.puts "--- ✍️ Preparing annotation"
STDERR.puts "#{testcases} testcases found"

if failures.any?
STDERR.puts "There #{failures.length == 1 ? "is 1 failure/error" : "are #{failures.length} failures/errors" } 😭"

failures_count = failures.select {|f| f.type == :failure }.length
errors_count = failures.select {|f| f.type == :error }.length
puts [
failures_count == 0 ? nil : (failures_count == 1 ? "1 failure" : "#{failures_count} failures"),
errors_count === 0 ? nil : (errors_count == 1 ? "1 error" : "#{errors_count} errors"),
].compact.join(" and ") + ":\n\n"

failures.each do |failure|
puts "<details>"
puts "<summary><code>#{failure.name} in #{failure.unit_name}</code></summary>\n\n"
if failure.message
puts "<p>#{failure.message.chomp.strip}</p>\n\n"
end
if failure.body
puts "<pre><code>#{CGI.escapeHTML(failure.body.chomp.strip)}</code></pre>\n\n"
end
if failure.job
puts "in <a href=\"##{failure.job}\">Job ##{failure.job}</a>"
end
puts "</details>"
puts "" unless failure == failures.last
end

else
STDERR.puts "There were no failures/errors 🙌"
failures_count = failures.select {|f| f.type == :failure }.length
errors_count = failures.select {|f| f.type == :error }.length

puts "Failures: #{failures_count}"
puts "Errors: #{errors_count}"
puts "Total tests: #{testcases}"

failures.each do |failure|
puts ""
puts "<details>"
puts "<summary><code>#{failure.name} in #{failure.unit_name}</code></summary>\n\n"
if failure.message
puts "<p>#{failure.message.chomp.strip}</p>\n\n"
end
if failure.body
puts "<pre><code>#{CGI.escapeHTML(failure.body.chomp.strip)}</code></pre>\n\n"
end
if failure.job
puts "in <a href=\"##{failure.job}\">Job ##{failure.job}</a>"
end
puts "</details>"
end

if report_slowest > 0
STDERR.puts "Reporting slowest tests ⏱"

puts ""
puts "<details>"
puts "<summary>#{report_slowest} slowest tests</summary>\n\n"
puts "<table>"
Expand Down
Loading

0 comments on commit 4babc44

Please sign in to comment.