diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index feec48d3..615148b5 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_gem_version }} runs_on: ${{ matrix.runs_on }} diff --git a/Gemfile b/Gemfile index 5cf8c0a3..4cea4dd9 100644 --- a/Gemfile +++ b/Gemfile @@ -43,6 +43,7 @@ group :development do gem 'serverspec' gem 'simplecov', require: false gem 'simplecov-console', require: false + gem 'codecov', require: false gem 'redcarpet' end diff --git a/Rakefile b/Rakefile index 9a7c6f9c..0e55d365 100644 --- a/Rakefile +++ b/Rakefile @@ -15,6 +15,15 @@ RSpec::Core::RakeTask.new(:spec) do |t| t.exclude_pattern = "spec/acceptance/**/*.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/unit/**/*.rb" end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fc3c86fe..67402308 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,19 +1,22 @@ # frozen_string_literal: true if ENV['COVERAGE'] == 'yes' - require 'codecov' require 'simplecov' require 'simplecov-console' 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 'lib/puppet-strings/version.rb' add_filter '/spec' end end