-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathreport
executable file
·87 lines (71 loc) · 2.15 KB
/
report
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env ruby
# frozen_string_literal: true
require "csv"
require "yaml"
def linkify_pr(text, repo)
"[##{text}](#{File.join(repo, "pull", text)})"
end
def linkify_sha(ref, repo)
"[`#{ref[0...7]}`](#{File.join(repo, "commit", ref)})"
end
def linkify_flamegraph(site)
site = site.split("/").last
"[🔥️](https://utterson.pathawks.com/#{ENV["REF"]}/#{site}.svg)"
end
def linkify_site(site)
"[#{site.split("/").last}](#{site})"
end
def markdown_header
repo_url = ENV.fetch("HTML_URL", "https://github.com/jekyll/jekyll")
ref = ENV["REF"]
pr = ENV["PR"]
frontmatter = {
"PR" => pr,
"REF" => ref,
"title" => "Performance Check",
"permalink" => "/#{ref}.html",
}
<<~HEADER
#{frontmatter.to_yaml}---
The following report was generated for PR #{linkify_pr(pr, repo_url)},
on commit #{linkify_sha(ref, repo_url)}
HEADER
end
begin
results = CSV.table("results.csv")
rescue Errno::ENOENT
puts <<~MSG
Cannot open file results.csv
You must run ./bench before running ./report
MSG
exit 1
end
puts markdown_header if ENV.key?("REF") && ENV.key?("PR")
puts "| ref | build time in seconds |"
puts "|:-----------------------------------------|----------------------:|"
summed_results = {}
site_results = {}
results.each do |row|
summed_results[row[0]] = 0.0 unless summed_results.key?(row[0])
site_results[row[2]] ||= {
:flamegraph => linkify_flamegraph(row[2]),
:site => linkify_site(row[2]),
:time => 0.0,
}
summed_results[row[0]] += row[1]
site_results[row[2]][:time] += row[1] if row[0] == "##{ENV["PR"]}"
end
summed_results.each do |ref, time|
ref = "`#{ref}`" unless ref =~ %r!\A(?:[0-9a-f]+|#\d+)\Z!
puts format("| %-40s | %21.2f |", ref, time)
end
if ENV.key?("REF") && ENV.key?("PR")
puts <<~HEADER
Below is a table with the total build time for each site (summed total of all builds against this commit)
| | site | build time in seconds |
|--|:-----|----------------------:|
HEADER
site_results.values.each do |data|
puts format "| %<flamegraph>s | %<site>s | %<time>.2f |", data
end
end