Skip to content

Commit

Permalink
"(CAT-1618) - Add code coverage to ci"
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbreen28 committed Jan 15, 2024
1 parent 0548891 commit 41ee7ab
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ on:
- "main"
workflow_dispatch:

env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

jobs:

spec:
strategy:
fail-fast: false
Expand All @@ -18,4 +22,5 @@ jobs:
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main"
secrets: "inherit"
with:
ruby_version: ${{ matrix.ruby_version }}
rake_task: "spec:coverage"
ruby_version: ${{ matrix.ruby_version }}
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ group :test do

gem 'codecov'
gem 'simplecov'
gem 'simplecov-console'
end

group :development do
Expand Down
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@ require 'yard'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec

namespace :spec do
desc 'Run RSpec code examples with coverage collection'
task :coverage do
ENV['COVERAGE'] = 'yes'
Rake::Task['spec'].execute
end
end

YARD::Rake::YardocTask.new do |t|
end
39 changes: 18 additions & 21 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,29 @@
require 'ostruct'

if ENV['COVERAGE'] == 'yes'
require 'simplecov'

if ENV['CI'] == 'true'
require 'codecov'
SimpleCov.formatter = SimpleCov::Formatter::Codecov
else
begin
require 'simplecov'
require 'simplecov-console'
SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console
]
end
SimpleCov.start do
track_files 'lib/**/*.rb'

add_filter '/spec'
if ENV['CI'] == 'true'
require 'codecov'
SimpleCov.formatters << SimpleCov::Formatter::Codecov
end

# do not track vendored files
add_filter '/vendor'
add_filter '/.vendor'
SimpleCov.start do
track_files 'lib/**/*.rb'

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

Expand Down

0 comments on commit 41ee7ab

Please sign in to comment.