Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdksync - "(CAT-1618) - Add code coverage to ci" #540

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .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:
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