Skip to content

Commit 89ae51d

Browse files
author
jordanbreen28
committed
(CAT-1618) - Add code coverage back to ci
1 parent cc5074c commit 89ae51d

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
- "main"
77
workflow_dispatch:
88

9+
env:
10+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
11+
912
jobs:
1013

1114
spec:
@@ -19,6 +22,7 @@ jobs:
1922
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main"
2023
secrets: "inherit"
2124
with:
25+
rake_task: "spec:coverage"
2226
ruby_version: ${{ matrix.ruby_version }}
2327

2428
acceptance:

Gemfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ group :test do
1010
gem 'json'
1111

1212
gem 'rspec-json_expectations', '~> 1.4'
13-
14-
gem 'simplecov', :require => false if ENV['COVERAGE'] == 'yes'
13+
gem 'simplecov', :require => false
14+
gem 'simplecov-console', :require => false
15+
gem 'codecov', :require => false
1516
end
1617

1718
group :acceptance do

Rakefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ rescue LoadError
2727
# Gem not present
2828
end
2929

30+
namespace :spec do
31+
desc 'Run RSpec code examples with coverage collection'
32+
task :coverage do
33+
ENV['COVERAGE'] = 'yes'
34+
Rake::Task['spec'].execute
35+
end
36+
end
37+
3038
RSpec::Core::RakeTask.new(:spec) do |t|
3139
t.exclude_pattern = 'spec/acceptance/**/*_spec.rb'
3240
end

spec/spec_helper.rb

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
# Disable GitHub Actions reporting since it breaks the test suite
22
ENV.delete('GITHUB_ACTION')
33

4-
if ENV['COVERAGE'] == 'yes' && RUBY_VERSION.start_with?('2.7.')
5-
require 'simplecov'
6-
SimpleCov.start do
7-
add_filter('/spec/')
8-
add_filter('/vendor/')
9-
add_group('Checks', 'lib/puppet-lint/plugins')
4+
if ENV['COVERAGE'] == 'yes'
5+
begin
6+
require 'simplecov'
7+
require 'simplecov-console'
8+
SimpleCov.formatters = [
9+
SimpleCov::Formatter::HTMLFormatter,
10+
SimpleCov::Formatter::Console,
11+
]
12+
if ENV['CI'] == 'true'
13+
require 'codecov'
14+
SimpleCov.formatters << SimpleCov::Formatter::Codecov
15+
end
16+
17+
SimpleCov.start do
18+
add_filter('/spec/')
19+
add_filter('/vendor/')
20+
add_group('Checks', 'lib/puppet-lint/plugins')
21+
end
22+
rescue LoadError
23+
raise 'Add the simplecov, simplecov-console, codecov gems to Gemfile to enable this task'
1024
end
1125
end
1226

0 commit comments

Comments
 (0)