-
Notifications
You must be signed in to change notification settings - Fork 34
/
ci_recorder.rake
54 lines (42 loc) · 1.31 KB
/
ci_recorder.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true
require "tempfile"
require "json"
require "active_support/core_ext/hash"
require "rake"
require_relative "../deprecation_toolkit/read_write_helper"
class CIRecorder
include Rake::DSL
include DeprecationToolkit::ReadWriteHelper
def initialize
namespace(:deprecation_toolkit) do
desc("Parse a file generated with the CIOutputHelper and generate deprecations out of it")
task(:record_from_ci_output) do
raw_file = ENV.fetch("FILEPATH")
deprecations = extract_deprecations_output(raw_file) do |file|
parse_file(file)
end
generate_deprecations_file(deprecations)
end
end
end
private
def extract_deprecations_output(file)
tmp_file = Tempfile.new
shell_command = "cat #{file} | sed -n -e 's/^.* \\[DeprecationToolkit\\] \\(.*\\)/\\1/p' > #{tmp_file.path}"
raise "Couldn't extract deprecations from output" unless system(shell_command)
yield(tmp_file)
ensure
tmp_file.delete
end
def parse_file(file)
file.each.with_object({}) do |line, hash|
hash.deep_merge!(JSON.parse(line))
end
end
def generate_deprecations_file(deprecations_to_record)
deprecations_to_record.each do |filename, deprecations|
write(Pathname(filename), deprecations)
end
end
end
CIRecorder.new