Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- main

env:
ruby_version: 3.4
CI: 1

jobs:
test:
Expand All @@ -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'`
Expand All @@ -53,6 +51,10 @@ jobs:
include-hidden-files: true

coverage:
permissions:
id-token: write
pages: write
checks: write
needs: test
runs-on: ubuntu-latest

Expand All @@ -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
Expand All @@ -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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea/
Gemfile.lock
*.gem
spec/hpack-test-case
spec/hpack-test-case
/coverage/
2 changes: 1 addition & 1 deletion .simplecov
Original file line number Diff line number Diff line change
Expand Up @@ -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}" }
8 changes: 7 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
46 changes: 44 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
return unless ENV.key?("CI")
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

Expand Down
9 changes: 6 additions & 3 deletions example/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
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"
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"
Expand Down
2 changes: 2 additions & 0 deletions example/server.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

ENV["COVERAGE_DIR"] ||= "coverage/#{RUBY_ENGINE}-#{RUBY_VERSION}-h2spec-test"

require_relative "helper"

options = { port: 8080 }
Expand Down
7 changes: 5 additions & 2 deletions spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

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
SimpleCov.start do
merging true
finalize_merge false
end
end

RSpec.configure(&:disable_monkey_patching!)
Expand Down
2 changes: 2 additions & 0 deletions spec/hpack_test_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

ENV["COVERAGE_DIR"] ||= "coverage/#{RUBY_ENGINE}-#{RUBY_VERSION}-hpack"

require "helper"
require "json"

Expand Down
Loading