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 f8a41a7 commit 35a8080
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
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
18 changes: 7 additions & 11 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,

Check failure on line 10 in spec/spec_helper.rb

View workflow job for this annotation

GitHub Actions / spec (windows-latest ruby 2.7 | puppet ~> 7.0) / spec

Style/TrailingCommaInArrayLiteral: Avoid comma after the last item of an array.

Check failure on line 10 in spec/spec_helper.rb

View workflow job for this annotation

GitHub Actions / spec (ubuntu-latest ruby 2.7 | puppet ~> 7.0) / spec

Style/TrailingCommaInArrayLiteral: Avoid comma after the last item of an array.

Check failure on line 10 in spec/spec_helper.rb

View workflow job for this annotation

GitHub Actions / spec (ubuntu-latest ruby 3.2 | puppet ~> 8.0) / spec

Style/TrailingCommaInArrayLiteral: Avoid comma after the last item of an array.

Check failure on line 10 in spec/spec_helper.rb

View workflow job for this annotation

GitHub Actions / spec (windows-latest ruby 3.2 | puppet ~> 8.0) / spec

Style/TrailingCommaInArrayLiteral: Avoid comma after the last item of an array.
SimpleCov::Formatter::Codecov
]

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

0 comments on commit 35a8080

Please sign in to comment.