Skip to content

Commit

Permalink
ci: Add codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
ixti committed Dec 12, 2023
1 parent 378b66e commit de57ddd
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 50 deletions.
26 changes: 15 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -36,18 +36,22 @@ 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:
- uses: actions/checkout@v4

- 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
5 changes: 1 addition & 4 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
--backtrace
--color
--format=documentation
--order random
--require simplecov
--require spec_helper
25 changes: 25 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ group :test do
gem "rack-test"

gem "rspec"

gem "simplecov"
gem "simplecov-cobertura"

gem "timecop"

gem "rubocop", require: false
Expand Down
29 changes: 25 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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]
17 changes: 0 additions & 17 deletions scripts/ci-rspec

This file was deleted.

1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
13 changes: 0 additions & 13 deletions spec/support/simplecov.rb

This file was deleted.

0 comments on commit de57ddd

Please sign in to comment.