Skip to content

Commit dbc63ab

Browse files
authored
Merge pull request #423 from puppetlabs/pdksync_"cat-1618-add_code_cov"
pdksync - "(CAT-1618) - Add code coverage to ci"
2 parents 7aeddea + 1ca42a0 commit dbc63ab

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

.github/workflows/ci.yml

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

9+
env:
10+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
11+
912
jobs:
13+
1014
spec:
1115
strategy:
1216
fail-fast: false
1317
matrix:
1418
ruby_version:
1519
- '2.7'
1620
- '3.2'
21+
name: "spec (ruby ${{ matrix.ruby_version }})"
1722
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main"
1823
secrets: "inherit"
1924
with:
25+
rake_task: "spec:coverage"
2026
ruby_version: ${{ matrix.ruby_version }}
2127

2228
acceptance:

Rakefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ RSpec::Core::RakeTask.new(:spec) do |t|
77
t.exclude_pattern = "spec/acceptance/**/*.rb"
88
end
99

10+
namespace :spec do
11+
desc 'Run RSpec code examples with coverage collection'
12+
task :coverage do
13+
ENV['COVERAGE'] = 'yes'
14+
Rake::Task['spec'].execute
15+
end
16+
end
17+
1018
RSpec::Core::RakeTask.new(:acceptance) do |t|
1119
t.pattern = "spec/acceptance/**/*.rb"
1220
end

spec/spec_helper.rb

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
# frozen_string_literal: true
22

33
if ENV['COVERAGE'] == 'yes'
4-
require 'simplecov'
5-
require 'simplecov-console'
6-
require 'codecov'
4+
begin
5+
require 'simplecov'
6+
require 'simplecov-console'
77

8-
SimpleCov.formatters = [
9-
SimpleCov::Formatter::HTMLFormatter,
10-
SimpleCov::Formatter::Console,
11-
SimpleCov::Formatter::Codecov
12-
]
13-
SimpleCov.start do
14-
track_files 'lib/**/*.rb'
8+
SimpleCov.formatters = [
9+
SimpleCov::Formatter::HTMLFormatter,
10+
SimpleCov::Formatter::Console
11+
]
1512

16-
add_filter 'lib/puppetlabs_spec_helper/version.rb'
13+
if ENV['CI'] == 'true'
14+
require 'codecov'
15+
SimpleCov.formatters << SimpleCov::Formatter::Codecov
16+
end
1717

18-
add_filter '/spec'
18+
SimpleCov.start do
19+
track_files 'lib/**/*.rb'
1920

20-
# do not track vendored files
21-
add_filter '/vendor'
22-
add_filter '/.vendor'
21+
add_filter 'lib/puppetlabs_spec_helper/version.rb'
22+
23+
add_filter '/spec'
24+
25+
# do not track vendored files
26+
add_filter '/vendor'
27+
add_filter '/.vendor'
28+
end
29+
rescue LoadError
30+
raise 'Add the simplecov, simplecov-console, codecov gems to Gemfile to enable this task'
2331
end
2432
end
2533

0 commit comments

Comments
 (0)