From 6d69ffb7b6badfd59981acd799f6b37ab9e67543 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Mon, 8 Jan 2024 16:44:22 +0000 Subject: [PATCH 1/2] (CAT-1618) - Add code coverage to gem_ci --- .github/workflows/ci.yml | 4 ++++ spec/spec_helper.rb | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b155d088f..cf8915161 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,9 @@ on: - "main" workflow_dispatch: +env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + jobs: spec: @@ -19,6 +22,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 }} acceptance: diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 420996b33..5e0b99ac9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,13 +1,17 @@ if ENV.fetch('COVERAGE', nil) == 'yes' - require 'codecov' require 'simplecov' require 'simplecov-console' SimpleCov.formatters = [ SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::Console, - SimpleCov::Formatter::Codecov ] + + if ENV['CI'] == 'true' + require 'codecov' + SimpleCov.formatters << SimpleCov::Formatter::Codecov + end + SimpleCov.start do track_files 'lib/**/*.rb' From 7c9591ec2247518d54ad27ca996c98add4cecb43 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Mon, 8 Jan 2024 16:44:40 +0000 Subject: [PATCH 2/2] (CAT-1618) - Remove unncessary filter for code cov Remove the filter for gitignored files. Code coverage will update as per the diff, which naturally does not include files in .gitignore --- spec/spec_helper.rb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5e0b99ac9..b2ab1a886 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,7 +4,7 @@ SimpleCov.formatters = [ SimpleCov::Formatter::HTMLFormatter, - SimpleCov::Formatter::Console, + SimpleCov::Formatter::Console ] if ENV['CI'] == 'true' @@ -23,14 +23,6 @@ add_filter '/.vendor' add_filter '/docs' add_filter '/lib/pdk/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 end