Skip to content

Commit

Permalink
Switch to GH-Actions (#634)
Browse files Browse the repository at this point in the history
* Switch to GitHub Actions

* Use GitHub Actions for CI
* Update Coveralls integration: generate lcov report with SimpleCov and
  send it after the test suite using coveralls GitHub Actions plugin
* Update and cleanup RSpec config
* Cleanup Rakefile
* Remove active_model dependency (certificate_authority was fixed)

PS: GH Actions syntax is ugly.
  Should we switch to Cirlce CI or GitLab CI? XD

Resolves: #633

* Disable SSL related specs

Specs are failing due to some misconfiguration caused by new OpenSSL.
TODO: #627

* Remove windows and macos from test matrix

We were not testing those on Travis-CI, thus to simplify migration I've
deicded to disable those. Once everything is fixed and stabilized we
will add those too.

* Bump min version of CA and rspec

Just to make sure we're using expected ones

* Make stubbed client in spec more predictable

- use stub_const
- consistently normalize URIs

* Add OpenSSL requirement details for jRuby

/cc @tarcieri Probably we should just add dependency on gem itself?

* Revert "Add OpenSSL requirement details for jRuby"

This reverts commit f8dfb38.

* Fix jRuby regression introduced in #632

jRuby is using outdated openssl gem bundled in, which don't have
validate_hostname getter on SSLContext.

* Fix jRuby coverage abilities
  • Loading branch information
ixti committed Dec 28, 2020
1 parent e0af615 commit 9bb0136
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 126 deletions.
1 change: 0 additions & 1 deletion .coveralls.yml

This file was deleted.

83 changes: 83 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,83 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
ruby: [ ruby-2.4, ruby-2.5, ruby-2.6, ruby-2.7, jruby-9.2.11 ]
os: [ ubuntu-latest ]

steps:
- uses: actions/checkout@v2

- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}

- uses: actions/cache@v1
with:
path: vendor/bundle
key: bundle-use-ruby-${{ matrix.os }}-${{ matrix.ruby }}-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: bundle-use-ruby-${{ matrix.os }}-${{ matrix.ruby }}-

- name: bundle install
run: |
bundle config set path "vendor/bundle"
bundle config set without "development"
bundle install --jobs 4
- name: bundle exec rspec
env:
JRUBY_OPTS: --debug
run: bundle exec rspec --format progress --force-colour

- name: Prepare Coveralls test coverage report
uses: coverallsapp/github-action@v1.1.2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: "${{ matrix.ruby }} @${{ matrix.os }}"
path-to-lcov: ./coverage/lcov/lcov.info
parallel: true

coveralls:
needs: test
runs-on: ubuntu-latest
steps:
- name: Finalize Coveralls test coverage report
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true

lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.4

- uses: actions/cache@v1
with:
path: vendor/bundle
key: bundle-use-ruby-lint-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: bundle-use-ruby-lint-

- name: bundle install
run: |
bundle config set path "vendor/bundle"
bundle config set without "development"
bundle install --jobs 4
- run: bundle exec rubocop --color
- run: bundle exec rake verify_measurements
16 changes: 6 additions & 10 deletions .gitignore
@@ -1,19 +1,15 @@
*.gem
.bundle
.config
.rvmrc
.ruby-version
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage

.bundle
.ruby-version
doc
lib/bundler/man
measurement
coverage
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
spec/examples.txt
tmp
Gemfile.lock
4 changes: 0 additions & 4 deletions .rspec
@@ -1,5 +1 @@
--backtrace
--color
--format=documentation
--order random
--require spec_helper
37 changes: 0 additions & 37 deletions .travis.yml

This file was deleted.

17 changes: 9 additions & 8 deletions Gemfile
Expand Up @@ -10,22 +10,23 @@ group :development do
gem "nokogiri", :require => false
gem "pry", :require => false

platform :ruby_20 do
gem "pry-debugger", :require => false
gem "pry-stack_explorer", :require => false
# RSpec formatter
gem "fuubar", :require => false

platform :mri do
gem "pry-byebug"
end
end

group :test do
gem "activemodel", :require => false # Used by certificate_authority
gem "certificate_authority", :require => false
gem "certificate_authority", "~> 1.0", :require => false

gem "backports"

gem "coveralls", :require => false
gem "simplecov", ">= 0.9"
gem "simplecov", :require => false
gem "simplecov-lcov", :require => false

gem "rspec", "~> 3.0"
gem "rspec", "~> 3.10"
gem "rspec-its"

gem "rubocop", "= 0.68.1"
Expand Down
10 changes: 1 addition & 9 deletions Rakefile
Expand Up @@ -61,12 +61,4 @@ task :generate_status_codes do
end
end

if ENV["CI"].nil?
task :default => %i[spec rubocop verify_measurements]
else
case ENV["SUITE"]
when "rubocop" then task :default => :rubocop
when "yardstick" then task :default => :verify_measurements
else task :default => :spec
end
end
task :default => %i[spec rubocop verify_measurements]
3 changes: 2 additions & 1 deletion lib/http/timeout/null.rb
Expand Up @@ -36,8 +36,9 @@ def start_tls(host, ssl_socket_class, ssl_context)
connect_ssl

return unless ssl_context.verify_mode == OpenSSL::SSL::VERIFY_PEER
return unless ssl_context.respond_to?(:verify_hostname) && ssl_context.verify_hostname

@socket.post_connection_check(host) if ssl_context.verify_hostname
@socket.post_connection_check(host)
end

# Read from the socket
Expand Down
71 changes: 38 additions & 33 deletions spec/lib/http/client_spec.rb
Expand Up @@ -8,46 +8,50 @@
RSpec.describe HTTP::Client do
run_server(:dummy) { DummyServer.new }

StubbedClient = Class.new(HTTP::Client) do
def perform(request, options)
stubbed = stubs[request.uri]
stubbed ? stubbed.call(request) : super(request, options)
end

def stubs
@stubs ||= {}
end
before do
stubbed_client = Class.new(HTTP::Client) do
def perform(request, options)
stubbed = stubs[HTTP::URI::NORMALIZER.call(request.uri).to_s]
stubbed ? stubbed.call(request) : super(request, options)
end

def stub(stubs)
@stubs = stubs.each_with_object({}) do |(k, v), o|
o[HTTP::URI.parse k] = v
def stubs
@stubs ||= {}
end

self
def stub(stubs)
@stubs = stubs.each_with_object({}) do |(k, v), o|
o[HTTP::URI::NORMALIZER.call(k).to_s] = v
end

self
end
end
end

def redirect_response(location, status = 302)
lambda do |request|
HTTP::Response.new(
:status => status,
:version => "1.1",
:headers => {"Location" => location},
:body => "",
:request => request
)
def redirect_response(location, status = 302)
lambda do |request|
HTTP::Response.new(
:status => status,
:version => "1.1",
:headers => {"Location" => location},
:body => "",
:request => request
)
end
end
end

def simple_response(body, status = 200)
lambda do |request|
HTTP::Response.new(
:status => status,
:version => "1.1",
:body => body,
:request => request
)
def simple_response(body, status = 200)
lambda do |request|
HTTP::Response.new(
:status => status,
:version => "1.1",
:body => body,
:request => request
)
end
end

stub_const("StubbedClient", stubbed_client)
end

describe "following redirects" do
Expand Down Expand Up @@ -350,7 +354,8 @@ def on_error(request, error)
let(:client) { described_class.new(options.merge(extra_options)) }
end

describe "working with SSL" do
# TODO: https://github.com/httprb/http/issues/627
xdescribe "working with SSL" do
run_server(:dummy_ssl) { DummyServer.new(:ssl => true) }

let(:extra_options) { {} }
Expand Down
6 changes: 4 additions & 2 deletions spec/lib/http_spec.rb
Expand Up @@ -95,7 +95,8 @@
expect(response.to_s).to match(/<!doctype html>/)
end

context "ssl" do
# TODO: htt:s://github.com/httprb/http/issues/627
xcontext "ssl" do
it "responds with the endpoint's body" do
response = ssl_client.via(proxy.addr, proxy.port).get dummy_ssl.endpoint
expect(response.to_s).to match(/<!doctype html>/)
Expand Down Expand Up @@ -131,7 +132,8 @@
expect(response.status).to eq(407)
end

context "ssl" do
# TODO: htt:s://github.com/httprb/http/issues/627
xcontext "ssl" do
it "responds with the endpoint's body" do
response = ssl_client.via(proxy.addr, proxy.port, "username", "password").get dummy_ssl.endpoint
expect(response.to_s).to match(/<!doctype html>/)
Expand Down
42 changes: 21 additions & 21 deletions spec/spec_helper.rb
@@ -1,19 +1,7 @@
# frozen_string_literal: true

require "simplecov"
require "coveralls"

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
)

SimpleCov.start do
add_filter "/spec/"
minimum_coverage 80
end
require_relative "./support/simplecov"
require_relative "./support/fuubar" unless ENV["CI"]

require "http"
require "rspec/its"
Expand All @@ -40,6 +28,13 @@
mocks.verify_partial_doubles = true
end

# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
# have no way to turn it off -- the option exists only for backwards
# compatibility in RSpec 3). It causes shared context metadata to be
# inherited by the metadata hash of host groups and examples, rather than
# triggering implicit auto-inclusion in groups with matching metadata.
config.shared_context_metadata_behavior = :apply_to_host_groups

# These two settings work together to allow you to limit a spec run
# to individual examples or groups you care about by tagging them with
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
Expand All @@ -48,17 +43,22 @@
config.filter_run_excluding :flaky if defined?(JRUBY_VERSION) && ENV["CI"]
config.run_all_when_everything_filtered = true

# Limits the available syntax to the non-monkey patched syntax that is recommended.
# For more details, see:
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
config.disable_monkey_patching!

# This setting enables warnings. It's recommended, but in some cases may
# be too noisy due to issues in dependencies.
config.warnings = 0 == ENV["GUARD_RSPEC"].to_i

# Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options. We recommend
# you configure your source control system to ignore this file.
config.example_status_persistence_file_path = "spec/examples.txt"

# Limits the available syntax to the non-monkey patched syntax that is
# recommended. For more details, see:
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
config.disable_monkey_patching!

# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
Expand Down

0 comments on commit 9bb0136

Please sign in to comment.