Skip to content

Commit

Permalink
Merge pull request #108 from gocardless/ruby3
Browse files Browse the repository at this point in the history
Add ruby 3 support + drop support for 2.4 + 2.5
  • Loading branch information
JoeSouthan authored Aug 25, 2021
2 parents 39400a7 + a58800d commit b662448
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 116 deletions.
137 changes: 49 additions & 88 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,103 +1,64 @@
version: 2
---
version: 2.1

references:
steps: &steps
- checkout

- type: shell
name: Write RAILS_VERSION to a file so we can use it for caching purposes
command: echo "$RAILS_VERSION" > ~/RAILS_VERSION.txt

- type: cache-restore
key: coach-bundler-{{ checksum "coach.gemspec" }}-{{ checksum "~/RAILS_VERSION.txt" }}

- run: gem install bundler -v 1.11.2

- run: bundle install --path vendor/bundle
bundle_install: &bundle_install
run:
name: Bundle
command: |
gem install bundler --no-document && \
bundle config set no-cache 'true' && \
bundle config set jobs '4' && \
bundle config set retry '3' && \
bundle install
- type: cache-save
key: coach-bundler-{{ checksum "coach.gemspec" }}-{{ checksum "~/RAILS_VERSION.txt" }}
cache_bundle: &cache_bundle
save_cache:
key: bundle-<< parameters.ruby_version >>-<< parameters.rails_version >>-{{ checksum "coach.gemspec" }}-{{ checksum "Gemfile" }}
paths:
- vendor/bundle

- type: shell
command: |
bundle exec rspec --profile 10 \
--format RspecJunitFormatter \
--out /tmp/test-results/rspec.xml \
--format progress \
spec
- type: store_test_results
path: /tmp/test-results
restore_bundle: &restore_bundle
restore_cache:
key: bundle-<< parameters.ruby_version >>-<< parameters.rails_version >>-{{ checksum "coach.gemspec" }}-{{ checksum "Gemfile" }}

- run: bundle exec rubocop
jobs:
build-ruby24-rails515:
docker:
- image: ruby:2.4
environment:
- RAILS_VERSION=5.1.5
steps: *steps
build-ruby24-rails4210:
docker:
- image: ruby:2.4
environment:
- RAILS_VERSION=4.2.10
steps: *steps
build-ruby25-rails515:
docker:
- image: ruby:2.5
environment:
- RAILS_VERSION=5.1.5
steps: *steps
build-ruby25-rails4210:
docker:
- image: ruby:2.5
environment:
- RAILS_VERSION=4.2.10
steps: *steps
build-ruby26-rails515:
docker:
- image: ruby:2.6
environment:
- RAILS_VERSION=5.1.5
steps: *steps
build-ruby27-rails515:
docker:
- image: ruby:2.7
environment:
- RAILS_VERSION=5.1.5
steps: *steps
build-ruby27-rails604:
docker:
- image: ruby:2.7
environment:
- RAILS_VERSION=6.0.4
steps: *steps
build-ruby27-rails614:
rspec:
working_directory: /mnt/ramdisk
parameters:
ruby_version:
type: string
rails_version:
type: string
docker:
- image: ruby:2.7
- image: cimg/ruby:<< parameters.ruby_version >>
environment:
- RAILS_VERSION=6.1.4
steps: *steps
build-ruby30-rails614:
docker:
- image: ruby:3.0
environment:
- RAILS_VERSION=6.1.4
steps: *steps
CIRCLE_TEST_REPORTS: /tmp/circle_artifacts/
steps:
- add_ssh_keys
- checkout
- *restore_bundle
- *bundle_install
- *cache_bundle
- run:
name: Run specs
command: |
bundle exec rspec $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings) --profile --format progress --format RspecJunitFormatter -o /tmp/circle_artifacts/rspec.xml
- run:
name: "Rubocop"
command: bundle exec rubocop --extra-details --display-style-guide --parallel --force-exclusion
- store_artifacts:
path: /tmp/circle_artifacts/
- store_test_results:
path: /tmp/circle_artifacts/

workflows:
version: 2
tests:
jobs:
- build-ruby24-rails515
- build-ruby24-rails4210
- build-ruby25-rails515
- build-ruby25-rails4210
- build-ruby26-rails515
- build-ruby27-rails515
- build-ruby27-rails604
- build-ruby27-rails614
- build-ruby30-rails614
- rspec:
matrix:
parameters:
ruby_version: ["2.6", "2.7", "3.0"]
rails_version: ["5.2.6", "6.0.4", "6.1.4"]

7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2

updates:
- package-ecosystem: bundler
directory: "/"
schedule:
interval: "daily"
5 changes: 4 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ inherit_gem:
gc_ruboconfig: rubocop.yml

AllCops:
TargetRubyVersion: 2.4
TargetRubyVersion: 3.0

Metrics/MethodLength:
Max: 15
Expand All @@ -26,3 +26,6 @@ Naming/MethodParameterName:
# These are some custom names that we want to allow, since they aren't
# uncommunicative - they're actually rather meaningful!
- as

Gemspec/RequiredRubyVersion:
Enabled: False
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0.2
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

# Unreleased

# 3.0.0 / 2021-09-09

* [#105](https://github.com/gocardless/coach/pull/105) Add support for module/class names to be
passed to `Handler.new` and `Router#draw` to allow routes to be defined without loading the routes
constants, which makes using Zeitwerk much easier.

* Add Ruby 3 support

## Breaking changes

* Remove Ruby 2.4 and 2.5 support

# 2.3.0 / 2020-04-29

* [#90](https://github.com/gocardless/coach/pull/90) Instrument status `0` instead of `500` when Coach::Handler catches an exception
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ To get started, just add Coach to your `Gemfile`, and then run `bundle`:
gem 'coach'
```

Coach works with Ruby versions 2.4 and onwards.
Coach works with Ruby versions 2.6 and onwards.

## Coach by example

Expand Down
8 changes: 3 additions & 5 deletions coach.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
spec.homepage = "https://github.com/gocardless/coach"
spec.email = %w[[email protected]]
spec.license = "MIT"
spec.required_ruby_version = ">= 2.4"
spec.required_ruby_version = ">= 2.6"

spec.files = `git ls-files -z`.split("\x0")
spec.test_files = spec.files.grep(%r{^spec/})
Expand All @@ -23,12 +23,10 @@ Gem::Specification.new do |spec|
spec.add_dependency "activesupport", ">= 4.2"
spec.add_dependency "commander", "~> 4.5"

spec.add_development_dependency "gc_ruboconfig", "= 2.18.0"
spec.add_development_dependency "gc_ruboconfig", "~> 2.18.0"
spec.add_development_dependency "pry", "~> 0.10"
spec.add_development_dependency "rspec", "~> 3.2"
spec.add_development_dependency "rspec-its", "~> 1.2"
spec.add_development_dependency "rspec_junit_formatter", "~> 0.4.0"
# 1.12 removed support for Ruby 2.4, which we still support. We can remove this pin
# when we drop support for Ruby 2.4.
spec.add_development_dependency "rubocop", "< 1.12"
spec.add_development_dependency "rubocop", "~> 1.12"
end
38 changes: 18 additions & 20 deletions lib/coach/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,24 @@ def call(env)

publish("start_handler.coach", event.dup)
instrument("finish_handler.coach", event) do
begin
response = chain.instrument.call
rescue StandardError => e
raise
ensure
# We want to populate the response and metadata fields after the middleware
# chain has completed so that the end of the instrumentation can see them. The
# simplest way to do this is pass the event by reference to ActiveSupport, then
# modify the hash to contain this detail before the instrumentation completes.
#
# This way, the last finish_handler.coach event will have all the details.
status = response.try(:first) || STATUS_CODE_FOR_EXCEPTIONS
event.merge!(
response: {
status: status,
exception: e,
}.compact,
metadata: context.fetch(:_metadata, {}),
)
end
response = chain.instrument.call
rescue StandardError => e
raise
ensure
# We want to populate the response and metadata fields after the middleware
# chain has completed so that the end of the instrumentation can see them. The
# simplest way to do this is pass the event by reference to ActiveSupport, then
# modify the hash to contain this detail before the instrumentation completes.
#
# This way, the last finish_handler.coach event will have all the details.
status = response.try(:first) || STATUS_CODE_FOR_EXCEPTIONS
event.merge!(
response: {
status: status,
exception: e,
}.compact,
metadata: context.fetch(:_metadata, {}),
)
end
end
# rubocop:enable Metrics/MethodLength
Expand Down
2 changes: 1 addition & 1 deletion lib/coach/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Coach
VERSION = "2.3.0"
VERSION = "3.0.0"
end

0 comments on commit b662448

Please sign in to comment.