Skip to content

Commit 4599bc1

Browse files
committed
Add a simple tool to parse errors and failures output to add tags
* Convenient to transform a CI log into tags, without needing to run the specs locally and to build the Ruby interpreter.
1 parent 2ee5661 commit 4599bc1

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tool/tag_from_output.rb

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Adds tags based on error and failures output (e.g., from a CI log),
2+
# without running any spec code.
3+
4+
tags_dir = %w[
5+
spec/tags
6+
spec/tags/ruby
7+
].find { |dir| Dir.exist?("#{dir}/language") }
8+
abort 'Could not find tags directory' unless tags_dir
9+
10+
output = ARGF.readlines
11+
# Remove leading "[exec] " from JRuby logs
12+
output = output.map { |line| line.sub(/^\[exec\] /, '') }
13+
14+
NUMBER = /^\d+\)$/
15+
ERROR_OR_FAILED = / (ERROR|FAILED)$/
16+
SPEC_FILE = /^(\/.+_spec\.rb)\:\d+/
17+
18+
failures = output.slice_before(NUMBER).select { |number, error_line, *rest|
19+
number =~ NUMBER and error_line =~ ERROR_OR_FAILED
20+
}.each { |number, error_line, *rest|
21+
description = error_line.match(ERROR_OR_FAILED).pre_match
22+
23+
spec_file = rest.find { |line| line =~ SPEC_FILE }
24+
spec_file = spec_file[SPEC_FILE, 1]
25+
prefix = spec_file.index('spec/ruby')
26+
spec_file = spec_file[prefix..-1]
27+
28+
tags_file = spec_file.sub('spec/ruby/', "#{tags_dir}/").sub(/_spec\.rb$/, '_tags.txt')
29+
30+
dir = File.dirname(tags_file)
31+
Dir.mkdir(dir) unless Dir.exist?(dir)
32+
33+
tag_line = "fails:#{description}"
34+
unless File.exist?(tags_file) and File.readlines(tags_file, chomp: true).include?(tag_line)
35+
File.open(tags_file, 'a') do |f|
36+
f.puts tag_line
37+
end
38+
end
39+
}

0 commit comments

Comments
 (0)