From d8cc6ef0d44215323178ad899b38e6c12e609316 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Mon, 10 Oct 2022 21:37:46 +0100 Subject: [PATCH 1/2] (MAINT) Update CI with matrix and acceptance This commit prepares the CI workflow so that it can consume the new ci and acceptance workflows for gems. It also implements a matrix that is passed in to the rake task as the MATRIX_TARGET environment variable. --- .github/workflows/ci.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f815a524..1e26261c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: "ci" on: push: branches: - - "maint" + - "main" pull_request: branches: - "main" @@ -12,6 +12,19 @@ on: workflow_dispatch: jobs: - ci: + + spec: uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main" secrets: "inherit" + + acceptance: + needs: "spec" + strategy: + matrix: + puppet: + - "puppet6" + - "puppet7" + uses: "puppetlabs/cat-github-actions/.github/workflows/gem_acceptance.yml@main" + secrets: "inherit" + with: + target: ${{ matrix.target }} From 2ef43c57bd6b20bc48a99fdd3cc64d292024d762 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Wed, 12 Oct 2022 12:55:20 +0100 Subject: [PATCH 2/2] (MAINT) Add acceptance test task This commit completes the acceptance test implementation by adding a new Rake task. This task is a parent task that calls subtasks that use litmus for testing. --- Gemfile | 34 +++++++++++------- Rakefile | 80 ++++++++++++++++++------------------------ puppet-strings.gemspec | 5 ++- 3 files changed, 58 insertions(+), 61 deletions(-) diff --git a/Gemfile b/Gemfile index 7451d7a06..c468631d8 100644 --- a/Gemfile +++ b/Gemfile @@ -14,15 +14,29 @@ else gem 'puppet', :require => false end -group :test do +group :development do gem 'codecov' + + gem 'json_spec', '~> 1.1', '>= 1.1.5' + + gem 'mdl' gem 'mocha' + + gem 'pry', require: false + gem 'pry-byebug', require: false + gem 'pry-stack_explorer', require: false gem 'puppetlabs_spec_helper' - gem 'serverspec' - gem 'simplecov-console' + + gem 'rake', '~> 10.0' gem 'rspec', '~> 3.1' - gem 'json_spec', '~> 1.1', '>= 1.1.5' - gem 'mdl' + gem 'rspec-its', '~> 1.0' + gem 'rubocop', '~> 1.6.1', require: false + gem 'rubocop-rspec', '~> 2.0.1', require: false + gem 'rubocop-performance', '~> 1.9.1', require: false + + gem 'serverspec' + gem 'simplecov-console', require: false if ENV['COVERAGE'] == 'yes' + gem 'simplecov', require: false if ENV['COVERAGE'] == 'yes' end group :acceptance do @@ -30,16 +44,10 @@ group :acceptance do gem 'net-ssh' end -group :development do - gem 'github_changelog_generator' - gem 'pry' - gem 'pry-byebug' +group :release do + gem 'github_changelog_generator', require: false end -gem 'rubocop', '~> 1.6.1' -gem 'rubocop-rspec', '~> 2.0.1' -gem 'rubocop-performance', '~> 1.9.1' - # Evaluate Gemfile.local if it exists if File.exists? "#{__FILE__}.local" eval(File.read("#{__FILE__}.local"), binding) diff --git a/Rakefile b/Rakefile index 9d3c05ec1..aa00696ee 100644 --- a/Rakefile +++ b/Rakefile @@ -1,46 +1,16 @@ # frozen_string_literal: true -if Bundler.rubygems.find_name('puppet_litmus').any? - require 'puppet_litmus/rake_tasks' - - # This is a _really_ horrible monkey-patch to fix up https://github.com/puppetlabs/bolt/issues/1614 - # Based on resolution https://github.com/puppetlabs/bolt/pull/1620 - # This can be removed once this is fixed, released into Bolt and into Litmus - require 'bolt_spec/run' - module BoltSpec - module Run - class BoltRunner - class << self - alias_method :original_with_runner, :with_runner - end - - def self.with_runner(config_data, inventory_data) - original_with_runner(deep_duplicate_object(config_data), deep_duplicate_object(inventory_data)) { |runner| yield runner } - end - - # From https://github.com/puppetlabs/pdk/blob/main/lib/pdk/util.rb - # Workaround for https://github.com/puppetlabs/bolt/issues/1614 - def self.deep_duplicate_object(object) - if object.is_a?(Array) - object.map { |item| deep_duplicate_object(item) } - elsif object.is_a?(Hash) - hash = object.dup - hash.each_pair { |key, value| hash[key] = deep_duplicate_object(value) } - hash - else - object - end - end - end - end - end -end - -require 'puppetlabs_spec_helper/tasks/fixtures' require 'bundler/gem_tasks' require 'puppet-lint/tasks/puppet-lint' - require 'rspec/core/rake_task' +require 'puppetlabs_spec_helper/tasks/fixtures' + +begin + require 'puppet_litmus/rake_tasks' +rescue LoadError + # Gem not present +end + RSpec::Core::RakeTask.new(:spec) do |t| t.exclude_pattern = "spec/acceptance/**/*.rb" end @@ -138,13 +108,6 @@ namespace :litmus do end end -task(:rubocop) do - require 'rubocop' - cli = RuboCop::CLI.new - result = cli.run(%w(-D -f s)) - abort unless result == RuboCop::CLI::STATUS_SUCCESS -end - #### CHANGELOG #### begin require 'github_changelog_generator/task' @@ -177,3 +140,30 @@ rescue LoadError raise 'Install github_changelog_generator to get access to automatic changelog generation' end end + +desc 'Run acceptance tests' +task :acceptance do + + begin + if ENV['MATRIX_TARGET'] + agent_version = ENV['MATRIX_TARGET'].chomp + else + agent_version = 'puppet7' + end + + Rake::Task['litmus:provision'].invoke('docker', 'litmusimage/centos:7') + + Rake::Task['litmus:install_agent'].invoke(agent_version.to_s) + + Rake::Task['litmus:install_modules_from_directory'].invoke('./spec/fixtures/acceptance/modules') + + Rake::Task['litmus:install_gems'].invoke + + Rake::Task['litmus:acceptance:parallel'].invoke + + rescue StandardError => e + puts e.message + raise e + end + +end diff --git a/puppet-strings.gemspec b/puppet-strings.gemspec index be932d0e0..25f3f5bac 100644 --- a/puppet-strings.gemspec +++ b/puppet-strings.gemspec @@ -12,7 +12,6 @@ Gem::Specification.new do |s| s.summary = 'Puppet documentation via YARD' s.email = 'info@puppet.com' s.homepage = 'https://github.com/puppetlabs/puppet-strings' - s.description = s.summary s.required_ruby_version = '>= 2.5.0' s.extra_rdoc_files = [ @@ -25,6 +24,6 @@ Gem::Specification.new do |s| s.files = Dir['CHANGELOG.md', 'README.md', 'LICENSE', 'lib/**/*', 'exe/**/*'] s.add_runtime_dependency 'yard', '~> 0.9.5' - s.add_runtime_dependency 'rgen' - s.requirements << 'puppet, >= 5.0.0' + s.add_runtime_dependency 'rgen', '~> 0.9.0' + s.requirements << 'puppet, >= 6.0.0' end