From 4c5280e52706a3a3b40150b7cf0f063197d7e545 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Mon, 15 Jan 2024 13:59:02 +0000 Subject: [PATCH 1/2] "(CAT-1618) - Add code coverage to ci" --- .github/workflows/ci.yml | 4 ++++ Gemfile | 1 + Rakefile | 9 +++++++++ spec/spec_helper.rb | 11 +++++++---- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index feec48d3..615148b5 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: strategy: @@ -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_gem_version }} runs_on: ${{ matrix.runs_on }} diff --git a/Gemfile b/Gemfile index 5cf8c0a3..4cea4dd9 100644 --- a/Gemfile +++ b/Gemfile @@ -43,6 +43,7 @@ group :development do gem 'serverspec' gem 'simplecov', require: false gem 'simplecov-console', require: false + gem 'codecov', require: false gem 'redcarpet' end diff --git a/Rakefile b/Rakefile index 9a7c6f9c..0e55d365 100644 --- a/Rakefile +++ b/Rakefile @@ -15,6 +15,15 @@ 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/unit/**/*.rb" end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fc3c86fe..67402308 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,19 +1,22 @@ # frozen_string_literal: true if ENV['COVERAGE'] == 'yes' - require 'codecov' require 'simplecov' require 'simplecov-console' 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 'lib/puppet-strings/version.rb' add_filter '/spec' end end From 7a4e59618dec0988a0c4b50344b86f3ccc92c79d Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Mon, 15 Jan 2024 15:35:33 +0000 Subject: [PATCH 2/2] (maint) - Update puppet 8 gem version --- .github/workflows/ci.yml | 2 +- .github/workflows/nightly.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 615148b5..8b23ac07 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ 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' runs_on: - "ubuntu-latest" - "windows-latest" diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index b7af4460..f8aae476 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -17,7 +17,7 @@ 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' runs_on: - "ubuntu-latest" - "windows-latest"