From dc06cb66a568ee17ac2f3eb74f23b8e60fd4975c Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Wed, 11 Nov 2026 09:54:10 +0000 Subject: [PATCH 1/3] rake task: do not return from rake block --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 1d32bda0..1089d46e 100644 --- a/Rakefile +++ b/Rakefile @@ -38,7 +38,7 @@ end namespace :coverage do desc "Aggregates coverage reports" task :report do - return unless ENV.key?("CI") + next unless ENV.key?("CI") require "simplecov" From 4142fe361ff06edfec69f4b5494d95d102b9a4ed Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Wed, 11 Nov 2026 10:01:53 +0000 Subject: [PATCH 2/3] only run simplecov for ruby 3.2 or higher so that one doesn't have to maintain two separate configs, and targets simplecov v1 only --- Gemfile | 8 +++++++- example/helper.rb | 2 +- spec/helper.rb | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 8bc2d789..eaffe6ff 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,13 @@ end group :test do gem "rspec" - gem "simplecov", require: false +end + +if RUBY_VERSION >= "3.2.0" + group :coverage do + gem "repo-small-badge", require: false + gem "simplecov", ">= 1.0.0", require: false + end end group :types do diff --git a/example/helper.rb b/example/helper.rb index ac1c727e..4230635a 100644 --- a/example/helper.rb +++ b/example/helper.rb @@ -8,7 +8,7 @@ require "uri" # This will enable coverage within the CI environment -if ENV.key?("CI") +if ENV.key?("CI") && RUBY_VERSION >= "3.2.0" require "simplecov" SimpleCov.command_name "#{RUBY_ENGINE}-#{RUBY_VERSION}-h2spec" SimpleCov.coverage_dir "coverage/#{RUBY_ENGINE}-#{RUBY_VERSION}-h2spec" diff --git a/spec/helper.rb b/spec/helper.rb index 413acb9b..acc2a7da 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -2,7 +2,7 @@ GC.auto_compact = true if GC.respond_to?(:auto_compact=) -if ENV.key?("CI") +if ENV.key?("CI") && RUBY_VERSION >= "3.2.0" require "simplecov" SimpleCov.start end From 2c15c1277bc56ba841fe99a07618a3fc8d89549e Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Wed, 11 Nov 2026 10:05:09 +0000 Subject: [PATCH 3/3] create coverage badge, upload with coverage, expose in readme --- .github/workflows/ci.yml | 31 ++++++++++++++++++++-------- .gitignore | 3 ++- .simplecov | 2 +- README.md | 1 + Rakefile | 44 +++++++++++++++++++++++++++++++++++++++- example/helper.rb | 7 +++++-- example/server.rb | 2 ++ spec/helper.rb | 5 ++++- spec/hpack_test_spec.rb | 2 ++ 9 files changed, 83 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6aef42cf..612df52c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: - main env: - ruby_version: 3.4 + CI: 1 jobs: test: @@ -29,8 +29,6 @@ jobs: bundler-cache: true - name: Tests - env: - CI: 1 run: | RUBY_VERSION=`ruby -e 'puts RUBY_VERSION'` RUBY_PLATFORM=`ruby -e 'puts RUBY_PLATFORM'` @@ -53,6 +51,10 @@ jobs: include-hidden-files: true coverage: + permissions: + id-token: write + pages: write + checks: write needs: test runs-on: ubuntu-latest @@ -62,7 +64,7 @@ jobs: - name: Setup Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 3.3 + ruby-version: 4.0 bundler-cache: true - name: Download coverage results @@ -73,12 +75,25 @@ jobs: - name: coverage env: - CI: 1 + COVERAGE_DIR: coverage/merged run: | - find coverage -name "*resultset.json" -exec sed -i 's?${{ github.workspace }}?'`pwd`'?' {} \; bundle exec rake coverage:report - - uses: srozen/simplecov-check-action@support-simplecov-1 - if: ${{ github.repository == 'igrigorik/http-2' }} + - name: Upload simplecov results + id: deployment + uses: actions/upload-pages-artifact@v3 + with: + path: coverage + if: github.ref == 'refs/heads/main' + + - name: Deploy to GitHub Pages + uses: actions/deploy-pages@v4 + if: github.ref == 'refs/heads/main' + + - name: Check coverage + uses: srozen/simplecov-check-action@support-simplecov-1 with: github_token: ${{ secrets.GITHUB_TOKEN }} + coverage_path: 'coverage/merged/.last_run.json' + coverage_json_path: 'coverage/merged/coverage.json' + minimum_suite_coverage: 93 diff --git a/.gitignore b/.gitignore index 90227d58..977d68e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea/ Gemfile.lock *.gem -spec/hpack-test-case \ No newline at end of file +spec/hpack-test-case +/coverage/ \ No newline at end of file diff --git a/.simplecov b/.simplecov index f9f5a727..c71b246e 100644 --- a/.simplecov +++ b/.simplecov @@ -5,4 +5,4 @@ SimpleCov.skip "vendor/" SimpleCov.skip "spec/" SimpleCov.skip "lib/http/2/base64" SimpleCov.command_name "#{RUBY_ENGINE}-#{RUBY_VERSION}" -SimpleCov.coverage_dir "coverage/#{RUBY_ENGINE}-#{RUBY_VERSION}" +SimpleCov.coverage_dir ENV.fetch("COVERAGE_DIR") { "coverage/#{RUBY_ENGINE}-#{RUBY_VERSION}" } diff --git a/README.md b/README.md index 4d5874fe..6cea5b3e 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Gem Version](https://badge.fury.io/rb/http-2.svg)](http://rubygems.org/gems/http-2) [![Build status](https://github.com/igrigorik/http-2/actions/workflows/ci.yml/badge.svg)](https://github.com/igrigorik/http-2) +[![coverage report](https://igrigorik.github.io/http-2/merged/badge_total.svg)](https://igrigorik.github.io/http-2/merged/#_AllFiles) Pure Ruby, framework and transport agnostic, implementation of HTTP/2 protocol and HPACK header compression with support for: diff --git a/Rakefile b/Rakefile index 1089d46e..42e95f65 100644 --- a/Rakefile +++ b/Rakefile @@ -15,6 +15,7 @@ RSpec::Core::RakeTask.new(:spec) do |t| end RSpec::Core::RakeTask.new(:hpack) do |t| + ENV["RUBYOPT"] = nil # disable RBS, without this the time to run these balloons to >10m! t.pattern = "./spec/hpack_test_spec.rb" end @@ -35,15 +36,56 @@ RDoc::Task.new do |rdoc| rdoc.rdoc_files.add %w[README.md CHANGELOG.md lib/**/*.rb] end +class BadgeFormatter + def initialize(output = nil) + @output = output || $stdout + end + + def format(result) + min_thresholds = SimpleCov.minimum_coverage + covered_percent = result.source_files.covered_percent.round(0) + color = + if min_thresholds.any? + if SimpleCov::CoverageViolations.minimum_overall(result, SimpleCov.minimum_coverage).any? + "#ff0000" + else + "#ffffcc" # green + end + else + "#808080" + end + image = RepoSmallBadge::Image.new( + { + output_path: SimpleCov.coverage_dir, + value_color: color + } + ) + image.badge("total", "total", "#{covered_percent}%") + end +end + namespace :coverage do desc "Aggregates coverage reports" task :report do next unless ENV.key?("CI") require "simplecov" + require "repo_small_badge" puts Dir["coverage/**/.resultset.json"].inspect - SimpleCov.collate Dir["coverage/**/.resultset.json"] + SimpleCov.collate(Dir["coverage/**/.resultset.json"]) do + skip ".bundle/" + skip "vendor/" + skip "spec/" + skip "lib/http/2/base64" + minimum_coverage 93 + formatter SimpleCov::Formatter::MultiFormatter.new( + [ + SimpleCov::Formatter::HTMLFormatter, + BadgeFormatter + ] + ) + end end end diff --git a/example/helper.rb b/example/helper.rb index 4230635a..eb22cc2f 100644 --- a/example/helper.rb +++ b/example/helper.rb @@ -10,8 +10,11 @@ # This will enable coverage within the CI environment if ENV.key?("CI") && RUBY_VERSION >= "3.2.0" require "simplecov" - SimpleCov.command_name "#{RUBY_ENGINE}-#{RUBY_VERSION}-h2spec" - SimpleCov.coverage_dir "coverage/#{RUBY_ENGINE}-#{RUBY_VERSION}-h2spec" + SimpleCov.start do + coverage_dir ENV.fetch("COVERAGE_DIR") { "coverage/#{RUBY_ENGINE}-#{RUBY_VERSION}-h2spec" } + merging true + finalize_merge false + end end require "http/2" diff --git a/example/server.rb b/example/server.rb index f47ae5c6..9a1d51dd 100644 --- a/example/server.rb +++ b/example/server.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +ENV["COVERAGE_DIR"] ||= "coverage/#{RUBY_ENGINE}-#{RUBY_VERSION}-h2spec-test" + require_relative "helper" options = { port: 8080 } diff --git a/spec/helper.rb b/spec/helper.rb index acc2a7da..a3f6a279 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -4,7 +4,10 @@ if ENV.key?("CI") && RUBY_VERSION >= "3.2.0" require "simplecov" - SimpleCov.start + SimpleCov.start do + merging true + finalize_merge false + end end RSpec.configure(&:disable_monkey_patching!) diff --git a/spec/hpack_test_spec.rb b/spec/hpack_test_spec.rb index f1a6dbe4..51679107 100644 --- a/spec/hpack_test_spec.rb +++ b/spec/hpack_test_spec.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +ENV["COVERAGE_DIR"] ||= "coverage/#{RUBY_ENGINE}-#{RUBY_VERSION}-hpack" + require "helper" require "json"