Skip to content

Commit 3344ed3

Browse files
authored
Merge pull request #540 from puppetlabs/pdksync_"cat-1618-add_code_cov"
pdksync - "(CAT-1618) - Add code coverage to ci"
2 parents 0548891 + 44c53af commit 3344ed3

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ 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
@@ -18,4 +22,5 @@ jobs:
1822
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main"
1923
secrets: "inherit"
2024
with:
25+
rake_task: "spec:coverage"
2126
ruby_version: ${{ matrix.ruby_version }}

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ group :test do
1414

1515
gem 'codecov'
1616
gem 'simplecov'
17+
gem 'simplecov-console'
1718
end
1819

1920
group :development do

Rakefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,13 @@ require 'yard'
77
RSpec::Core::RakeTask.new(:spec)
88
task :default => :spec
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
YARD::Rake::YardocTask.new do |t|
1119
end

spec/spec_helper.rb

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,29 @@
55
require 'ostruct'
66

77
if ENV['COVERAGE'] == 'yes'
8-
require 'simplecov'
9-
10-
if ENV['CI'] == 'true'
11-
require 'codecov'
12-
SimpleCov.formatter = SimpleCov::Formatter::Codecov
13-
else
8+
begin
9+
require 'simplecov'
10+
require 'simplecov-console'
1411
SimpleCov.formatters = [
15-
SimpleCov::Formatter::HTMLFormatter
12+
SimpleCov::Formatter::HTMLFormatter,
13+
SimpleCov::Formatter::Console
1614
]
17-
end
18-
SimpleCov.start do
19-
track_files 'lib/**/*.rb'
20-
21-
add_filter '/spec'
15+
if ENV['CI'] == 'true'
16+
require 'codecov'
17+
SimpleCov.formatters << SimpleCov::Formatter::Codecov
18+
end
2219

23-
# do not track vendored files
24-
add_filter '/vendor'
25-
add_filter '/.vendor'
20+
SimpleCov.start do
21+
track_files 'lib/**/*.rb'
2622

27-
# do not track gitignored files
28-
# this adds about 4 seconds to the coverage check
29-
# this could definitely be optimized
30-
add_filter do |f|
31-
# system returns true if exit status is 0, which with git-check-ignore means file is ignored
32-
system("git check-ignore --quiet #{f.filename}")
23+
add_filter '/spec'
24+
add_filter 'lib/puppet_litmus/version.rb'
25+
# do not track vendored files
26+
add_filter '/vendor'
27+
add_filter '/.vendor'
3328
end
29+
rescue LoadError
30+
raise 'Add the simplecov, simplecov-console, and codecov gems to Gemfile to enable this task'
3431
end
3532
end
3633

0 commit comments

Comments
 (0)