diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c23a50..feab8eb 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: @@ -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_version }} runs_on: ${{ matrix.runs-on }} diff --git a/.gitignore b/.gitignore index e0f6eaa..b948a15 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ Gemfile.lock tmp/ vendor/ .DS_Store +coverage/ # Gem building puppetfile-resolver*.gem diff --git a/Gemfile b/Gemfile index 670d1fe..af760ed 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 ced09f1..e006f8f 100644 --- a/Rakefile +++ b/Rakefile @@ -19,6 +19,14 @@ RSpec::Core::RakeTask.new(:spec) do |spec| spec.pattern = FileList['spec/**/*_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 + task default: :spec namespace :ssl do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9a85b9a..65bb79f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,36 @@ # frozen_string_literal: true +if ENV['COVERAGE'] == 'yes' + begin + 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 + track_files 'lib/**/*.rb' + add_filter '/spec' + add_filter 'lib/puppetfile-resolver/version.rb' + + add_filter '/docs' + + # do not track vendored files + add_filter '/vendor' + add_filter '/.vendor' + end + rescue LoadError + raise 'Add the simplecov, simplecov-console, codecov gems to Gemfile to enable this task' + end +end + root = File.join(__dir__,'..',) # Add the language server into the load path $LOAD_PATH.unshift(File.join(root,'lib'))