Skip to content

(maint) - Make codecov gem support optional - changes to spec:simplecov rake task #424

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

Merged
merged 2 commits into from
Jan 22, 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
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Setting ownership to the tooling team and Tim
* @puppetlabs/tooling @bastelfreak
* @puppetlabs/devx @bastelfreak
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ end
group :development do
gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION'])

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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ You can enable it, set the following environment variable:s

``SIMPLECOV=yes``

Remember to add the simplecov-console and codecov gems to your `Gemfile`. If you run `spec:simplecov` on Travis-CI or any of the other supported CI services, reports gets automatically uploaded to https://codecov.io/ .
Remember to add the simplecov-console gem to your `Gemfile`. If you run `spec:simplecov` on Travis-CI or any of the other supported CI services, reports get generated which can then be uploaded to [codecov.io](https://codecov.io) with the recommended [codecov uploader](https://docs.codecov.com/docs/codecov-uploader).

Some Notes for Windows Users
============================
Expand Down
51 changes: 29 additions & 22 deletions lib/puppetlabs_spec_helper/module_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,42 @@ def verify_contents(subject, title, expected_lines)
module_path = File.join(fixture_path, 'modules')

module_path = [module_path, env_module_path].join(File::PATH_SEPARATOR) if env_module_path

if ENV['SIMPLECOV'] == 'yes'
begin
require 'simplecov'
require 'simplecov-console'
rescue LoadError
raise 'Add the simplecov and simplecov-console gems to Gemfile to enable this task'
end

SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console
]

begin
require 'codecov'
SimpleCov.formatters << SimpleCov::Formatter::Codecov
rescue LoadError
# continue without codecov, we could warn here but we want to avoid its use if possible
end

SimpleCov.start do
track_files 'lib/**/*.rb'
add_filter '/spec'

SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console,
SimpleCov::Formatter::Codecov
]
SimpleCov.start do
track_files 'lib/**/*.rb'
add_filter '/spec'

# do not track vendored files
add_filter '/vendor'
add_filter '/.vendor'

# 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}")
end
# do not track vendored files
add_filter '/vendor'
add_filter '/.vendor'

# 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}")
end
rescue LoadError
raise 'Add the simplecov, simplecov-console, codecov gems to Gemfile to enable this task'
end
end

Expand Down
38 changes: 20 additions & 18 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,32 @@
begin
require 'simplecov'
require 'simplecov-console'
rescue LoadError
raise 'Add the simplecov and simplecov-console gems to Gemfile to enable this task'
end

SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console
]
SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console
]

if ENV['CI'] == 'true'
require 'codecov'
SimpleCov.formatters << SimpleCov::Formatter::Codecov
end
begin
require 'codecov'
SimpleCov.formatters << SimpleCov::Formatter::Codecov
rescue LoadError
# continue without codecov, we could warn here but we want to avoid if possible
end

SimpleCov.start do
track_files 'lib/**/*.rb'
SimpleCov.start do
track_files 'lib/**/*.rb'

add_filter 'lib/puppetlabs_spec_helper/version.rb'
add_filter 'lib/puppetlabs_spec_helper/version.rb'

add_filter '/spec'
add_filter '/spec'

# do not track vendored files
add_filter '/vendor'
add_filter '/.vendor'
end
rescue LoadError
raise 'Add the simplecov, simplecov-console, codecov gems to Gemfile to enable this task'
# do not track vendored files
add_filter '/vendor'
add_filter '/.vendor'
end
end

Expand Down