diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92293f1d..e9260f9f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,9 @@ on: - "main" workflow_dispatch: +env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + jobs: spec: @@ -19,6 +22,7 @@ jobs: uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main" secrets: "inherit" with: + rake_task: "spec:coverage" ruby_version: ${{ matrix.ruby_version }} acceptance: diff --git a/Gemfile b/Gemfile index 0459d781..ef8bda50 100644 --- a/Gemfile +++ b/Gemfile @@ -10,8 +10,9 @@ group :test do gem 'json' gem 'rspec-json_expectations', '~> 1.4' - - gem 'simplecov', :require => false if ENV['COVERAGE'] == 'yes' + gem 'simplecov', :require => false + gem 'simplecov-console', :require => false + gem 'codecov', :require => false end group :acceptance do diff --git a/Rakefile b/Rakefile index ba8f1e23..a9668f35 100644 --- a/Rakefile +++ b/Rakefile @@ -27,6 +27,14 @@ rescue LoadError # Gem not present end +namespace :spec do + desc 'Run RSpec code examples with coverage collection' + task :coverage do + ENV['COVERAGE'] = 'yes' + Rake::Task['spec'].execute + end +end + RSpec::Core::RakeTask.new(:spec) do |t| t.exclude_pattern = 'spec/acceptance/**/*_spec.rb' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 65d4a432..4b628218 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,8 +1,18 @@ # Disable GitHub Actions reporting since it breaks the test suite ENV.delete('GITHUB_ACTION') -if ENV['COVERAGE'] == 'yes' && RUBY_VERSION.start_with?('2.7.') +if ENV['COVERAGE'] == 'yes' require 'simplecov' + require 'simplecov-console' + SimpleCov.formatters = [ + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::Console, + ] + if ENV['CI'] == 'true' + require 'codecov' + SimpleCov.formatters << SimpleCov::Formatter::Codecov + end + SimpleCov.start do add_filter('/spec/') add_filter('/vendor/')