Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add codecov #2

Merged
merged 1 commit into from
Dec 5, 2023
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
40 changes: 32 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ on:
pull_request:
branches: [ main ]

env:
BUNDLE_WITHOUT: "development"
JRUBY_OPTS: "--dev --debug"

jobs:
test:
name: "rspec (ruby:${{ matrix.ruby }})"
Expand Down Expand Up @@ -40,8 +36,37 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: RSpec
run: scripts/ci-rspec
- run: bundle exec rake test

- name: "Upload coverage results"
uses: actions/upload-artifact@v3
with:
name: coverage-${{ matrix.ruby }}
path: coverage/.resultset.json

test-coverage:
runs-on: ubuntu-latest
needs: test

steps:
- uses: actions/checkout@v4

- uses: ruby/setup-ruby@v1
with:
ruby-version: ruby-3.2
bundler-cache: true

- name: "Download coverage results"
uses: actions/download-artifact@v3
with:
path: coverage

- run: bundle exec rake test:coverage

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

lint:
runs-on: ubuntu-latest
Expand All @@ -54,5 +79,4 @@ jobs:
ruby-version: ruby-3.2
bundler-cache: true

- name: Rubocop
run: bundle exec rubocop --format progress --color
- run: bundle exec rake lint
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
--require simplecov
--require spec_helper
24 changes: 24 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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"]
formatter SimpleCov::Formatter::SimpleFormatter
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
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ group :test do

gem "rspec"
gem "rspec-parameterized"

gem "simplecov"
gem "simplecov-cobertura"

gem "rubocop", require: false
gem "rubocop-capybara", require: false
Expand Down
45 changes: 41 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
# 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

namespace :test do
desc "Generate test coverage report"
task :coverage do
require "simplecov"

SimpleCov.collate Dir["coverage/**/.resultset.json"] do
if ENV["CI"]
require "simplecov-cobertura"
formatter SimpleCov::Formatter::CoberturaFormatter
else
formatter SimpleCov::Formatter::HTMLFormatter
end
end
end
end

desc "Lint codebase"
task :lint do
sh "bundle exec rubocop --color"
end

task default: %i[test lint]
8 changes: 8 additions & 0 deletions rubocop/layout.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Layout/ArgumentAlignment:
Enabled: true
EnforcedStyle: with_fixed_indentation

Layout/EmptyLinesAroundAttributeAccessor:
Enabled: true

Layout/FirstArrayElementIndentation:
Enabled: true
EnforcedStyle: consistent

Layout/FirstHashElementIndentation:
Enabled: true
EnforcedStyle: consistent
Expand Down
4 changes: 4 additions & 0 deletions rubocop/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ RSpec/MultipleExpectations:

RSpec/NamedSubject:
Enabled: false

RSpec/BeNil:
Enabled: true
EnforcedStyle: be
2 changes: 1 addition & 1 deletion rubocop/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Style/RegexpLiteral:

Style/RescueStandardError:
Enabled: true
EnforcedStyle: implicit
EnforcedStyle: explicit

Style/SingleArgumentDig:
Enabled: true
Expand Down
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 "rspec-parameterized"
Expand Down
13 changes: 0 additions & 13 deletions spec/support/simplecov.rb

This file was deleted.