Skip to content

Commit

Permalink
Merge pull request #423 from puppetlabs/pdksync_"cat-1618-add_code_cov"
Browse files Browse the repository at this point in the history
pdksync - "(CAT-1618) - Add code coverage to ci"
  • Loading branch information
LukasAud authored Jan 15, 2024
2 parents 7aeddea + 1ca42a0 commit dbc63ab
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ on:
- "main"
workflow_dispatch:

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

jobs:

spec:
strategy:
fail-fast: false
matrix:
ruby_version:
- '2.7'
- '3.2'
name: "spec (ruby ${{ matrix.ruby_version }})"
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main"
secrets: "inherit"
with:
rake_task: "spec:coverage"
ruby_version: ${{ matrix.ruby_version }}

acceptance:
Expand Down
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ RSpec::Core::RakeTask.new(:spec) do |t|
t.exclude_pattern = "spec/acceptance/**/*.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/**/*.rb"
end
Expand Down
38 changes: 23 additions & 15 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
# frozen_string_literal: true

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

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

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

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

# do not track vendored files
add_filter '/vendor'
add_filter '/.vendor'
add_filter 'lib/puppetlabs_spec_helper/version.rb'

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'
end
end

Expand Down

0 comments on commit dbc63ab

Please sign in to comment.