Skip to content

Commit

Permalink
"(CAT-1618) - Add code coverage to ci"
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbreen28 committed Jan 15, 2024
1 parent 9983741 commit a587d85
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- "main"
workflow_dispatch:

env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

jobs:
spec:
strategy:
Expand All @@ -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 }}
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,11 @@ end
RuboCop::RakeTask.new(:rubocop) do |task|
task.options = %w[-D -S -E]
end

namespace :spec do
desc 'Run RSpec code examples with coverage collection'
task :coverage do
ENV['COVERAGE'] = 'yes'
Rake::Task['test'].invoke
end
end
31 changes: 23 additions & 8 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
# frozen_string_literal: true

if ENV['COVERAGE']
require 'simplecov'
require 'coveralls'

SimpleCov.formatter = Coveralls::SimpleCov::Formatter if ENV['COVERAGE'] == 'yes'

SimpleCov.start do
add_filter %r{^/spec/}
add_filter %r{^/vendor/}
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
add_filter %r{^/spec/}
add_filter %r{^/vendor/}

add_filter '/docs'
add_filter 'lib/rspec-puppet/version.rb'
end
rescue LoadError
raise 'Add the simplecov, simplecov-console, codecov gems to Gemfile to enable this task'
end
end

Expand Down
27 changes: 21 additions & 6 deletions spec/spec_helper_unit.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
# frozen_string_literal: true

if ENV['COVERAGE']
require 'coveralls'
require 'simplecov'
begin
require 'simplecov'
require 'simplecov-console'

SimpleCov.formatter = Coveralls::SimpleCov::Formatter if ENV['COVERAGE'] == 'yes'
SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console
]

SimpleCov.start do
add_filter %r{^/spec/}
add_filter %r{^/vendor/}
if ENV['CI'] == 'true'
require 'codecov'
SimpleCov.formatters << SimpleCov::Formatter::Codecov
end

SimpleCov.start do
add_filter %r{^/spec/}
add_filter %r{^/vendor/}

add_filter '/docs'
add_filter 'lib/rspec-puppet/version.rb'
end
rescue LoadError
raise 'Add the simplecov, simplecov-console, codecov gems to Gemfile to enable this task'
end
end

Expand Down

0 comments on commit a587d85

Please sign in to comment.