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" #67

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
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- "main"
workflow_dispatch:

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

jobs:
spec:
strategy:
Expand All @@ -18,14 +21,15 @@ jobs:
- ruby-version: '2.7'
puppet_gem_version: '~> 7.0'
- ruby_version: '3.2'
puppet_gem_version: 'https://github.com/puppetlabs/puppet' # puppet8'
puppet_gem_version: '~> 8.0' # puppet8'
runs_on:
- "ubuntu-latest"
- "windows-latest"
name: "spec (${{ matrix.runs_on }} ruby ${{ matrix.ruby_version }} | puppet ${{matrix.puppet_gem_version}})"
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main"
secrets: "inherit"
with:
rake_task: "spec:coverage"
ruby_version: ${{ matrix.ruby_version }}
puppet_gem_version: ${{ matrix.puppet_gem_version }}
runs_on: ${{ matrix.runs_on }}
Expand Down
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = 'spec/unit/**/*_spec.rb'
end

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


RSpec::Core::RakeTask.new(:acceptance) do |t|
t.pattern = 'spec/acceptance/**/*_spec.rb'
end
Expand Down
20 changes: 8 additions & 12 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# frozen_string_literal: true

if ENV['SIMPLECOV'] == 'yes'
if ENV['COVERAGE'] == 'yes'
begin
require 'simplecov'
require 'simplecov-console'
require 'codecov'

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

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

SimpleCov.start do
track_files 'lib/**/*.rb'
add_filter '/spec'
Expand All @@ -21,14 +25,6 @@

# do not track version file, as it is loaded before simplecov initialises and therefore is never gonna be tracked correctly
add_filter 'lib/puppet/modulebuilder/version.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}")
end
end
rescue LoadError
raise 'Add the simplecov, simplecov-console, codecov gems to Gemfile to enable this task'
Expand Down