rspec-buildkite 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/rspec/buildkite/annotation_formatter.rb +85 -83
- data/lib/rspec/buildkite/version.rb +1 -1
- metadata +1 -1
- metadata.gz.sig +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1ae58f6a8295488ba436c3fbcf75fd6394b4a131f907fc6d98ba40af42cdc5b
|
4
|
+
data.tar.gz: 5426da063d471f51897dea21f8a58d6561da3e9bcea549e30b5f72abfe7886b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5dde4aba7b9eab1521dfc2e1b0c481457f559f86a8452dfc049f8d2ec811f14273ec67c26ce62cb1422d21ab667be26bedc80a7b77b647ca89553ea65a3fe23
|
7
|
+
data.tar.gz: 4d5d5c9fdde9a0129c4a40e83a2e69db0c4d76e33f2bd6a118b1667ab337342329945185a9820aa7693ccba2eea6fbb9be229db565f9bf8961ed105b4a61c72f
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
@@ -2,108 +2,110 @@ require "thread"
|
|
2
2
|
|
3
3
|
require "rspec/core"
|
4
4
|
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
|
13
|
-
|
5
|
+
module RSpec::Buildkite
|
6
|
+
# Create a Buildkite annotation for RSpec failures
|
7
|
+
#
|
8
|
+
# Help folks fix their builds as soon as possible when failures crop up by
|
9
|
+
# calling out failures in an annotation, even while the build is still running.
|
10
|
+
#
|
11
|
+
# Uses a background Thread so we don't block the build.
|
12
|
+
#
|
13
|
+
class AnnotationFormatter
|
14
|
+
RSpec::Core::Formatters.register self, :example_failed
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def initialize(output)
|
17
|
+
# We don't actually use this, but keep a reference anyway
|
18
|
+
@output = output
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
# Only setup if we're actually running on Buildkite
|
21
|
+
if ENV["BUILDKITE"]
|
22
|
+
@queue = Queue.new
|
23
|
+
@thread = Thread.new(&method(:thread))
|
24
|
+
at_exit { @queue.push(:close); @thread.join }
|
25
|
+
end
|
24
26
|
end
|
25
|
-
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def example_failed(notification)
|
29
|
+
@queue.push(notification) if @queue
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
+
private
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
def thread
|
35
|
+
while notification = @queue.pop
|
36
|
+
break if notification == :close
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
if notification
|
39
|
+
system "buildkite-agent", "annotate",
|
40
|
+
"--context", "rspec",
|
41
|
+
"--style", "error",
|
42
|
+
"--append",
|
43
|
+
format_failure(notification),
|
44
|
+
out: :close # only display errors
|
45
|
+
end
|
44
46
|
end
|
47
|
+
rescue
|
48
|
+
puts "Warning: Couldn't create Buildkite annotations:"
|
49
|
+
puts " " << $!.to_s, " " << $!.backtrace.join("\n ")
|
45
50
|
end
|
46
|
-
rescue
|
47
|
-
puts "Warning: Couldn't create Buildkite annotations:"
|
48
|
-
puts " " << $!.to_s, " " << $!.backtrace.join("\n ")
|
49
|
-
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
def format_failure(notification)
|
53
|
+
build_url = ENV["BUILDKITE_BUILD_URL"].to_s
|
54
|
+
job_id = ENV["BUILDKITE_JOB_ID"].to_s
|
55
|
+
job_url = "#{build_url}##{job_id}"
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
57
|
+
"<details>\n" <<
|
58
|
+
"<summary>#{notification.description.encode(:xml => :text)}</summary>\n\n" <<
|
59
|
+
"<code><pre>#{recolorize(notification.colorized_message_lines.join("\n").encode(:xml => :text))}</pre></code>\n\n" <<
|
60
|
+
%{in <a href=#{job_url.encode(:xml => :attr)}>Job ##{job_id.encode(:xml => :text)}</a>\n} <<
|
61
|
+
"</details>" <<
|
62
|
+
"\n\n\n"
|
63
|
+
end
|
63
64
|
|
64
|
-
|
65
|
+
private
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
# Re-color an ANSI-colorized string using terminal CSS classes:
|
68
|
+
# https://github.com/buildkite/terminal/blob/05a77905c468b9150cac41298fdb8a0735024d42/style.go#L34
|
69
|
+
def recolorize(string)
|
70
|
+
level = 0
|
71
|
+
string.gsub(/\e\[(\d+(?:;\d+)*)m/) do
|
72
|
+
"".tap do |buffer|
|
73
|
+
codes = $1.split(";").map(&:to_i)
|
73
74
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
75
|
+
classes = []
|
76
|
+
while code = codes.shift
|
77
|
+
case code
|
78
|
+
when 0
|
79
|
+
classes.clear
|
80
|
+
buffer << ("</span>" * level)
|
81
|
+
level = 0
|
82
|
+
when 1..5, 9, 30..37, 90..97
|
83
|
+
classes << "term-fg#{code}"
|
84
|
+
when 40..47, 100..107
|
85
|
+
classes << "term-bg#{code}"
|
86
|
+
when 38
|
87
|
+
if codes[0] == 5
|
88
|
+
codes.shift
|
89
|
+
if codes[0]
|
90
|
+
classes << "term-fgx#{codes.shift}"
|
91
|
+
end
|
90
92
|
end
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
93
|
+
when 48
|
94
|
+
if codes[0] == 5
|
95
|
+
codes.shift
|
96
|
+
if codes[0]
|
97
|
+
classes << "term-bgx#{codes.shift}"
|
98
|
+
end
|
97
99
|
end
|
98
100
|
end
|
99
101
|
end
|
100
|
-
end
|
101
102
|
|
102
|
-
|
103
|
-
|
104
|
-
|
103
|
+
if classes.any?
|
104
|
+
level += 1
|
105
|
+
buffer << %{<span class=#{classes.map { |klass| klass }.join(" ").encode(:xml => :attr)}>}
|
106
|
+
end
|
105
107
|
end
|
106
|
-
end
|
107
|
-
end
|
108
|
+
end << ("</span>" * level)
|
109
|
+
end
|
108
110
|
end
|
109
111
|
end
|
metadata
CHANGED
metadata.gz.sig
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
��v���
|
2
|
+
����㉆=+}y��+>'����E�l�v��Άu5-�!*,��wC��1(&������P�=�7�Q�a�d�N�Đ�6t��_��<>�e�'���"5� ���
|