diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24e19cdf..47c2d5a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,11 @@ on: - "main" workflow_dispatch: +env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + jobs: + spec: strategy: fail-fast: false @@ -18,4 +22,5 @@ jobs: uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main" secrets: "inherit" with: - ruby_version: ${{ matrix.ruby_version }} + rake_task: "spec:coverage" + ruby_version: ${{ matrix.ruby_version }} \ No newline at end of file diff --git a/Gemfile b/Gemfile index 670d1fe7..af760edb 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,7 @@ group :test do gem 'codecov' gem 'simplecov' + gem 'simplecov-console' end group :development do diff --git a/Rakefile b/Rakefile index 5bb50ccb..f443aea7 100644 --- a/Rakefile +++ b/Rakefile @@ -7,5 +7,13 @@ require 'yard' RSpec::Core::RakeTask.new(:spec) task :default => :spec +namespace :spec do + desc 'Run RSpec code examples with coverage collection' + task :coverage do + ENV['COVERAGE'] = 'yes' + Rake::Task['spec'].execute + end +end + YARD::Rake::YardocTask.new do |t| end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ca5afaa5..417c9223 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,32 +5,29 @@ require 'ostruct' if ENV['COVERAGE'] == 'yes' - require 'simplecov' - - if ENV['CI'] == 'true' - require 'codecov' - SimpleCov.formatter = SimpleCov::Formatter::Codecov - else + begin + require 'simplecov' + require 'simplecov-console' SimpleCov.formatters = [ - SimpleCov::Formatter::HTMLFormatter + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::Console, ] - end - SimpleCov.start do - track_files 'lib/**/*.rb' - - add_filter '/spec' + if ENV['CI'] == 'true' + require 'codecov' + SimpleCov.formatters << SimpleCov::Formatter::Codecov + end - # do not track vendored files - add_filter '/vendor' - add_filter '/.vendor' + SimpleCov.start do + track_files 'lib/**/*.rb' - # do not track gitignored files - # this adds about 4 seconds to the coverage check - # this could definitely be optimized - add_filter do |f| - # system returns true if exit status is 0, which with git-check-ignore means file is ignored - system("git check-ignore --quiet #{f.filename}") + add_filter '/spec' + add_filter 'lib/puppet_litmus/version.rb' + # do not track vendored files + add_filter '/vendor' + add_filter '/.vendor' end + rescue LoadError + raise 'Add the simplecov, simplecov-console, and codecov gems to Gemfile to enable this task' end end