diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9265bcf..8d64d29 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: strategy: @@ -18,7 +21,7 @@ jobs: - ruby-version: '2.7' puppet_gem_version: '~> 7.0' - ruby_version: '3.2' - puppet_gem_version: 'https://github.com/puppetlabs/puppet' # puppet8' + puppet_gem_version: '~> 8.0' # puppet8' runs_on: - "ubuntu-latest" - "windows-latest" @@ -26,6 +29,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 }} puppet_gem_version: ${{ matrix.puppet_gem_version }} runs_on: ${{ matrix.runs_on }} diff --git a/Rakefile b/Rakefile index f589475..4236dd2 100644 --- a/Rakefile +++ b/Rakefile @@ -7,6 +7,15 @@ RSpec::Core::RakeTask.new(:spec) do |t| t.pattern = 'spec/unit/**/*_spec.rb' 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(:acceptance) do |t| t.pattern = 'spec/acceptance/**/*_spec.rb' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e61678d..945b898 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,16 +1,20 @@ # frozen_string_literal: true -if ENV['SIMPLECOV'] == 'yes' +if ENV['COVERAGE'] == 'yes' begin require 'simplecov' require 'simplecov-console' - require 'codecov' SimpleCov.formatters = [ SimpleCov::Formatter::HTMLFormatter, - SimpleCov::Formatter::Console, - SimpleCov::Formatter::Codecov + SimpleCov::Formatter::Console ] + + if ENV['CI'] == 'true' + require 'codecov' + SimpleCov.formatters << SimpleCov::Formatter::Codecov + end + SimpleCov.start do track_files 'lib/**/*.rb' add_filter '/spec' @@ -21,14 +25,6 @@ # do not track version file, as it is loaded before simplecov initialises and therefore is never gonna be tracked correctly add_filter 'lib/puppet/modulebuilder/version.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}") - end end rescue LoadError raise 'Add the simplecov, simplecov-console, codecov gems to Gemfile to enable this task'