Skip to content

Commit 4c5280e

Browse files
committed
"(CAT-1618) - Add code coverage to ci"
1 parent 1707d5b commit 4c5280e

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

.github/workflows/ci.yml

+4
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
spec:
1114
strategy:
@@ -26,6 +29,7 @@ jobs:
2629
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main"
2730
secrets: "inherit"
2831
with:
32+
rake_task: "spec:coverage"
2933
ruby_version: ${{ matrix.ruby_version }}
3034
puppet_gem_version: ${{ matrix.puppet_gem_version }}
3135
runs_on: ${{ matrix.runs_on }}

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ group :development do
4343
gem 'serverspec'
4444
gem 'simplecov', require: false
4545
gem 'simplecov-console', require: false
46+
gem 'codecov', require: false
4647

4748
gem 'redcarpet'
4849
end

Rakefile

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ RSpec::Core::RakeTask.new(:spec) do |t|
1515
t.exclude_pattern = "spec/acceptance/**/*.rb"
1616
end
1717

18+
namespace :spec do
19+
desc 'Run RSpec code examples with coverage collection'
20+
task :coverage do
21+
ENV['COVERAGE'] = 'yes'
22+
Rake::Task['spec'].execute
23+
end
24+
end
25+
26+
1827
RSpec::Core::RakeTask.new(:acceptance) do |t|
1928
t.pattern = "spec/unit/**/*.rb"
2029
end

spec/spec_helper.rb

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
# frozen_string_literal: true
22

33
if ENV['COVERAGE'] == 'yes'
4-
require 'codecov'
54
require 'simplecov'
65
require 'simplecov-console'
76

87
SimpleCov.formatters = [
98
SimpleCov::Formatter::HTMLFormatter,
10-
SimpleCov::Formatter::Console,
11-
SimpleCov::Formatter::Codecov
9+
SimpleCov::Formatter::Console
1210
]
1311

12+
if ENV['CI'] == 'true'
13+
require 'codecov'
14+
SimpleCov.formatters << SimpleCov::Formatter::Codecov
15+
end
16+
1417
SimpleCov.start do
1518
track_files 'lib/**/*.rb'
16-
19+
add_filter 'lib/puppet-strings/version.rb'
1720
add_filter '/spec'
1821
end
1922
end

0 commit comments

Comments
 (0)