File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed
Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ RUBY_IMAGE="${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_RUBY_IMAGE:-ruby:3.1-alpine@sha256
1313
1414artifacts_dir=" $( pwd) /$( mktemp -d " junit-annotate-plugin-artifacts-tmp.XXXXXXXXXX" ) "
1515annotation_dir=" $( pwd) /$( mktemp -d " junit-annotate-plugin-annotation-tmp.XXXXXXXXXX" ) "
16+ failures_file_path=" ./failures_artifacts_names.txt"
1617annotation_path=" ${annotation_dir} /annotation.md"
1718annotation_style=" info"
1819fail_build=0
@@ -39,6 +40,25 @@ if ! buildkite-agent artifact download "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFA
3940 exit " ${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILED_DOWNLOAD_EXIT_CODE:- 2} "
4041fi
4142
43+ echo " --- :junit: Building the failures file"
44+
45+ if [[ " ${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_RUN_IN_DOCKER:- true} " =~ " true" ]]; then
46+ docker \
47+ --log-level " error" \
48+ run \
49+ --rm \
50+ --volume " $artifacts_dir :/junits" \
51+ --volume " $PLUGIN_DIR /ruby:/src" \
52+ --env " BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN:- } " \
53+ --env " BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT:- } " \
54+ " ${RUBY_IMAGE} " ruby /src/bin/buildfailuresfile /junits \
55+ > " $failures_file_path "
56+ else
57+ ruby " ${PLUGIN_DIR} /ruby/bin/buildfailuresfile" " ${artifacts_dir} " > " $failures_file_path "
58+ fi
59+
60+ buildkite-agent artifact upload " ${failures_file_path} "
61+
4262echo " --- :junit: Processing the junits"
4363
4464set +e
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env ruby
2+
3+ require 'rexml/document'
4+ require 'rexml/element'
5+ require 'set'
6+
7+ junits_dir = ARGV [ 0 ]
8+ abort ( "Usage: annotate <junits-dir>" ) unless junits_dir
9+ abort ( "#{ junits_dir } does not exist" ) unless Dir . exist? ( junits_dir )
10+
11+ job_pattern = ENV [ 'BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN' ]
12+ job_pattern = '-(.*).xml' if !job_pattern || job_pattern . empty?
13+
14+ failure_format = ENV [ 'BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT' ]
15+ failure_format = 'classname' if !failure_format || failure_format . empty?
16+
17+ class Failure < Struct . new ( :unit_name )
18+ end
19+
20+ junit_report_files = Dir . glob ( File . join ( junits_dir , "**" , "*" ) , File ::FNM_DOTMATCH )
21+ testcases = 0
22+ tests = Set . new
23+
24+ junit_report_files . sort . each do |file |
25+ next if File . directory? ( file )
26+
27+ job = File . basename ( file ) [ /#{ job_pattern } / , 1 ]
28+ xml = File . read ( file )
29+ doc = REXML ::Document . new ( xml )
30+
31+ REXML ::XPath . each ( doc , '//testsuite/testcase' ) do |testcase |
32+ testcases += 1
33+ unit_name = testcase . attributes [ failure_format ] . to_s
34+ testcase . elements . each ( "failure | error | skipped" ) do |elem |
35+ tests . add ( unit_name )
36+ end
37+ end
38+ end
39+
40+ tests . each do |elem |
41+ puts "*#{ elem } *"
42+ end
You can’t perform that action at this time.
0 commit comments