Skip to content

Commit bdcda35

Browse files
committed
fix matrix reports generation
1 parent 3a7f84f commit bdcda35

File tree

5 files changed

+70
-83
lines changed

5 files changed

+70
-83
lines changed

.github/workflows/benchmarks.yml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,15 @@ jobs:
3333
run: bundle install
3434
- name: Run benchmarks
3535
run: bundle exec rake
36-
- name: Generate HTML files for each benchmark
36+
- name: Generate index.html for current Ruby version
3737
run: |
38-
for v in $(ls reports); do
39-
mkdir -p html_reports/$v
40-
for f in $(ls reports/$v/*.txt); do
41-
ruby scripts/generate_benchmarks_html.rb "$f" "html_reports/$v/$(basename $f .txt).html"
42-
done
43-
done
44-
- name: Upload HTML reports as artifacts
38+
v=${{ matrix.ruby-version }}
39+
ruby scripts/merge_html_reports.rb $v
40+
- name: Upload index.html as artifact
4541
uses: actions/upload-artifact@v4
4642
with:
4743
name: html-reports
48-
path: html_reports/**/*
44+
path: reports/${{ matrix.ruby-version }}/index.html
4945

5046
publish:
5147
needs: rake
@@ -59,9 +55,9 @@ jobs:
5955
with:
6056
name: html-reports
6157
path: all_html_reports
62-
- name: Merge all HTML files into one
58+
- name: Generate listing page for all versions
6359
run: |
64-
ruby scripts/merge_html_reports.rb all_html_reports merged_benchmarks.html
60+
ruby scripts/generate_listing_page.rb all_html_reports index.html
6561
touch .nojekyll
6662
- name: Prepare gh-pages branch
6763
run: |
@@ -70,10 +66,11 @@ jobs:
7066
git fetch origin gh-pages || git checkout --orphan gh-pages
7167
git checkout gh-pages || git checkout --orphan gh-pages
7268
rm -rf *
73-
cp merged_benchmarks.html ./
69+
cp all_html_reports/*/index.html ./
70+
cp index.html ./
7471
touch .nojekyll
75-
- name: Commit and push merged HTML page
72+
- name: Commit and push HTML pages
7673
run: |
7774
git add .
78-
git commit -m "Update merged benchmark HTML [ci skip]" || echo "No changes to commit"
75+
git commit -m "Update benchmark HTML pages [ci skip]" || echo "No changes to commit"
7976
git push origin gh-pages

Rakefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
task :generate_versions_html do
2-
ruby_script = File.expand_path('scripts/generate_versions_html.rb', Dir.pwd)
3-
sh "ruby #{ruby_script}"
4-
end
51
desc "run benchmark in current ruby"
62
task :run_benchmark do
73
require 'fileutils'

scripts/generate_listing_page.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# scripts/generate_listing_page.rb
2+
# Generates an index.html listing all Ruby version benchmark pages found in the given directory.
3+
4+
require 'pathname'
5+
require 'find'
6+
7+
dir = ARGV[0] || 'all_html_reports'
8+
output = ARGV[1] || 'index.html'
9+
10+
version_pages = []
11+
Find.find(dir) do |path|
12+
if path =~ /\/index\.html$/
13+
version = Pathname(path).each_filename.to_a[-2]
14+
version_pages << [version, File.basename(path)]
15+
end
16+
end
17+
18+
version_pages.sort_by! { |v, _| v }
19+
20+
links = version_pages.map do |version, file|
21+
"<li><a href=\"#{version}/index.html\">Ruby #{version}</a></li>"
22+
end
23+
24+
page = <<-HTML
25+
<!DOCTYPE html>
26+
<html lang="en">
27+
<head>
28+
<meta charset="UTF-8">
29+
<title>Ruby Benchmarks Index</title>
30+
<style>
31+
body { font-family: Arial, sans-serif; margin: 2em; }
32+
ul { font-size: 1.2em; }
33+
</style>
34+
</head>
35+
<body>
36+
<h1>Ruby Benchmarks Index</h1>
37+
<ul>
38+
#{links.join("\n ")}
39+
</ul>
40+
</body>
41+
</html>
42+
HTML
43+
44+
File.write(output, page)
45+
puts "Listing page written to #{output}"

scripts/generate_versions_html.rb

Lines changed: 0 additions & 54 deletions
This file was deleted.

scripts/merge_html_reports.rb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,29 @@
44
require 'find'
55
require 'pathname'
66

7-
input_dir = ARGV[0] || 'all_html_reports'
8-
output = ARGV[1] || 'merged_benchmarks.html'
97

10-
html_files = []
11-
Find.find(input_dir) do |path|
12-
html_files << path if path =~ /\.html$/
13-
end
8+
# Usage: ruby scripts/merge_html_reports.rb <ruby_version>
9+
version = ARGV[0] or abort("Usage: ruby scripts/merge_html_reports.rb <ruby_version>")
10+
input_dir = File.join('reports', version)
11+
12+
output = File.join(input_dir, 'index.html')
13+
require 'fileutils'
14+
FileUtils.mkdir_p(input_dir)
15+
16+
txt_files = Dir[File.join(input_dir, '*.txt')].sort
1417

15-
blocks = html_files.sort.map do |file|
16-
name = Pathname(file).each_filename.to_a[-2..-1].join(' / ')
18+
blocks = txt_files.map do |file|
19+
name = File.basename(file, '.txt')
1720
content = File.read(file)
18-
"<details><summary>#{name}</summary>\n#{content}\n</details>"
21+
"<details><summary>#{name}</summary>\n<pre>#{content}</pre>\n</details>"
1922
end
2023

2124
page = <<-HTML
2225
<!DOCTYPE html>
2326
<html lang="en">
2427
<head>
2528
<meta charset="UTF-8">
26-
<title>All Ruby Benchmarks</title>
29+
<title>Ruby Benchmarks for #{version}</title>
2730
<style>
2831
body { font-family: Arial, sans-serif; margin: 2em; }
2932
details { margin-bottom: 1em; }
@@ -32,7 +35,7 @@
3235
</style>
3336
</head>
3437
<body>
35-
<h1>All Ruby Benchmarks</h1>
38+
<h1>Ruby Benchmarks for #{version}</h1>
3639
#{blocks.join("\n\n")}
3740
</body>
3841
</html>

0 commit comments

Comments
 (0)