Skip to content

Commit

Permalink
Merge pull request #5 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 276c100 + 369c04e commit 5d49f7e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .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 @@ -26,6 +29,7 @@ jobs:
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_version }}
runs_on: ${{ matrix.runs-on }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Gemfile.lock
tmp/
vendor/
.DS_Store
coverage/

# Gem building
puppetfile-resolver*.gem
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 @@ -19,6 +19,14 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_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

task default: :spec

namespace :ssl do
Expand Down
31 changes: 31 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# frozen_string_literal: true

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

SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
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'
add_filter 'lib/puppetfile-resolver/version.rb'

add_filter '/docs'

# 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

root = File.join(__dir__,'..',)
# Add the language server into the load path
$LOAD_PATH.unshift(File.join(root,'lib'))
Expand Down

0 comments on commit 5d49f7e

Please sign in to comment.