diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1e19aba..861be1de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,12 +8,7 @@ on: jobs: test: - name: "rspec (ruby:${{ matrix.ruby }}" - - strategy: - fail-fast: false - matrix: - ruby: [ "3.0", "3.1", "3.2" ] + name: "rspec (ruby:${{ matrix.ruby }})" runs-on: ubuntu-latest @@ -28,6 +23,11 @@ jobs: --health-timeout 5s --health-retries 5 + strategy: + fail-fast: false + matrix: + ruby: [ ruby-3.0, ruby-3.1, ruby-3.2 ] + steps: - uses: actions/checkout@v4 @@ -36,10 +36,14 @@ jobs: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - name: RSpec - run: scripts/ci-rspec + - run: bundle exec rake test + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - rubocop: + lint: runs-on: ubuntu-latest steps: @@ -47,7 +51,7 @@ jobs: - uses: ruby/setup-ruby@v1 with: - ruby-version: "3.2" + ruby-version: ruby-3.2 bundler-cache: true - - run: bundle exec rubocop + - run: bundle exec rake lint diff --git a/.rspec b/.rspec index d3ec40e0..283edea7 100644 --- a/.rspec +++ b/.rspec @@ -1,5 +1,2 @@ ---backtrace ---color ---format=documentation ---order random +--require simplecov --require spec_helper diff --git a/.simplecov b/.simplecov new file mode 100644 index 00000000..193cb89e --- /dev/null +++ b/.simplecov @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +SimpleCov.start do + gemfile = File.basename(ENV.fetch("BUNDLE_GEMFILE", "Gemfile"), ".gemfile").strip + gemfile = nil if gemfile.empty? || gemfile.casecmp?("gems.rb") || gemfile.casecmp?("Gemfile") + + command_name ["#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}", gemfile].compact.join("/") + + enable_coverage :branch + + if ENV["CI"] + require "simplecov-cobertura" + formatter SimpleCov::Formatter::CoberturaFormatter + else + formatter SimpleCov::Formatter::MultiFormatter.new([ + SimpleCov::Formatter::SimpleFormatter, + SimpleCov::Formatter::HTMLFormatter + ]) + end + + add_filter "/demo/" + add_filter "/gemfiles/" + add_filter "/spec/" + add_filter "/vendor/" +end diff --git a/Gemfile b/Gemfile index 0589cf19..36d44f05 100644 --- a/Gemfile +++ b/Gemfile @@ -15,7 +15,10 @@ group :test do gem "rack-test" gem "rspec" + gem "simplecov" + gem "simplecov-cobertura" + gem "timecop" gem "rubocop", require: false diff --git a/Rakefile b/Rakefile index ba007163..f8aa96de 100644 --- a/Rakefile +++ b/Rakefile @@ -1,9 +1,30 @@ # frozen_string_literal: true -require "appraisal" require "bundler/gem_tasks" -require "rspec/core/rake_task" -RSpec::Core::RakeTask.new +desc "Run tests" +task :test do + rm_rf "coverage" + rm_rf "gemfiles" -task default: ENV["APPRAISAL_INITIALIZED"] ? %i[spec] : %i[appraisal rubocop] + Bundler.with_unbundled_env do + sh "bundle exec appraisal generate" + + # XXX: `bundle exec appraisal install` fails on ruby-3.2 + Dir["gemfiles/*.gemfile"].each do |gemfile| + sh({ "BUNDLE_GEMFILE" => gemfile }, "bundle lock") + sh({ "BUNDLE_GEMFILE" => gemfile }, "bundle check") do |ok| + sh({ "BUNDLE_GEMFILE" => gemfile }, "bundle install") unless ok + end + end + + sh "bundle exec appraisal rspec --force-colour" + end +end + +desc "Lint codebase" +task :lint do + sh "bundle exec rubocop --color" +end + +task default: %i[test lint] diff --git a/scripts/ci-rspec b/scripts/ci-rspec deleted file mode 100755 index 1aedbca0..00000000 --- a/scripts/ci-rspec +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -set -Eeuxo pipefail - -rm -f ./Gemfile.lock -bundle install - -rm -f ./gemfiles/*.gemfile ./gemfiles/*.gemfile.lock -bundle exec appraisal generate - -# XXX: `bundle exec appraisal install` fails on CI with ruby-3.2 -for BUNDLE_GEMFILE in gemfiles/*.gemfile; do - export BUNDLE_GEMFILE - bundle check || bundle install -done - -bundle exec appraisal rspec diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 80c1093f..cb34b713 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require_relative "support/simplecov" if ENV["CI"] || ENV["COVERAGE"] require_relative "support/sidekiq" require_relative "support/timecop" diff --git a/spec/support/simplecov.rb b/spec/support/simplecov.rb deleted file mode 100644 index ca4f6f67..00000000 --- a/spec/support/simplecov.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -require "simplecov" - -SimpleCov.start do - command_name "BUNDLE_GEMFILE=#{ENV.fetch('BUNDLE_GEMFILE')}" - - enable_coverage :branch - - add_filter "/gemfiles/" - add_filter "/spec/" - add_filter "/vendor/" -end