Skip to content

Commit

Permalink
(CAT-1618) - Add code coverage back to ci
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbreen28 committed Jan 15, 2024
1 parent cc5074c commit 89ae51d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 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:
Expand All @@ -19,6 +22,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 }}

acceptance:
Expand Down
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ group :test do
gem 'json'

gem 'rspec-json_expectations', '~> 1.4'

gem 'simplecov', :require => false if ENV['COVERAGE'] == 'yes'
gem 'simplecov', :require => false
gem 'simplecov-console', :require => false
gem 'codecov', :require => false
end

group :acceptance do
Expand Down
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ rescue LoadError
# Gem not present
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(:spec) do |t|
t.exclude_pattern = 'spec/acceptance/**/*_spec.rb'
end
Expand Down
26 changes: 20 additions & 6 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
# Disable GitHub Actions reporting since it breaks the test suite
ENV.delete('GITHUB_ACTION')

if ENV['COVERAGE'] == 'yes' && RUBY_VERSION.start_with?('2.7.')
require 'simplecov'
SimpleCov.start do
add_filter('/spec/')
add_filter('/vendor/')
add_group('Checks', 'lib/puppet-lint/plugins')
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
add_filter('/spec/')
add_filter('/vendor/')
add_group('Checks', 'lib/puppet-lint/plugins')
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 89ae51d

Please sign in to comment.