From 78cda820876dcb56f60db22b393c3c40a067186c Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:46:15 +0100 Subject: [PATCH 01/25] (CONT-881) Update dependencies --- .github/workflows/ci.yml | 41 ++++---- .github/workflows/nightly.yml | 41 ++++---- .rubocop.yml | 188 +++------------------------------- Gemfile | 53 ++++------ Rakefile | 33 ------ 5 files changed, 80 insertions(+), 276 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c0f7d70..feec48d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,42 +7,47 @@ on: workflow_dispatch: jobs: - spec: strategy: fail-fast: false matrix: ruby_version: - - '2.5' - - '2.7' - puppet_gem_version: - - '~> 6.0' - - '~> 7.0' - name: "spec (ruby ${{ matrix.ruby_version }} | ${{ matrix.puppet_gem_version }})" + - "2.7" + - "3.2" + include: + - ruby-version: '2.7' + puppet_gem_version: '~> 7.0' + - ruby_version: '3.2' + puppet_gem_version: 'https://github.com/puppetlabs/puppet' # puppet8' + runs_on: + - "ubuntu-latest" + - "windows-latest" + name: "spec (${{ matrix.runs_on }} ruby ${{ matrix.ruby_version }} | puppet ${{matrix.puppet_gem_version}})" uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main" secrets: "inherit" with: ruby_version: ${{ matrix.ruby_version }} + puppet_gem_version: ${{ matrix.puppet_gem_version }} + runs_on: ${{ matrix.runs_on }} acceptance: needs: "spec" strategy: - fail-fast: false matrix: - os: - - "ubuntu-latest" - - "windows-latest" ruby_version: - - "2.5" - "2.7" - puppet_gem_version: - - '~> 6.0' - - '~> 7.0' - name: "acceptance (${{ matrix.os }} ruby ${{ matrix.ruby_version }} |${{ matrix.puppet_gem_version }})" + - "3.2" + include: + - ruby-version: '2.7' + puppet_gem_version: '~> 7.0' + - ruby_version: '3.2' + puppet_gem_version: 'https://github.com/puppetlabs/puppet' # puppet8' + runs_on: + - "ubuntu-latest" + - "windows-latest" uses: "puppetlabs/cat-github-actions/.github/workflows/gem_acceptance.yml@main" secrets: "inherit" with: ruby_version: ${{ matrix.ruby_version }} - rake_task: 'acceptance' puppet_version: ${{ matrix.puppet_gem_version }} - runs_on: ${{ matrix.os }} + runs_on: ${{ matrix.runs_on }} diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index dcef4ef..b7af446 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -6,42 +6,47 @@ on: workflow_dispatch: jobs: - spec: strategy: fail-fast: false matrix: ruby_version: - - '2.5' - - '2.7' - puppet_gem_version: - - '~> 6.0' - - '~> 7.0' - name: "spec (ruby ${{ matrix.ruby_version }} | ${{ matrix.puppet_gem_version }})" + - "2.7" + - "3.2" + include: + - ruby-version: '2.7' + puppet_gem_version: '~> 7.0' + - ruby_version: '3.2' + puppet_gem_version: 'https://github.com/puppetlabs/puppet' # puppet8' + runs_on: + - "ubuntu-latest" + - "windows-latest" + name: "spec (${{ matrix.runs_on }} ruby ${{ matrix.ruby_version }} | puppet ${{matrix.puppet_gem_version}})" uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main" secrets: "inherit" with: ruby_version: ${{ matrix.ruby_version }} + puppet_gem_version: ${{ matrix.puppet_gem_version }} + runs_on: ${{ matrix.runs_on }} acceptance: needs: "spec" strategy: - fail-fast: false matrix: - os: - - "ubuntu-latest" - - "windows-latest" ruby_version: - - "2.5" - "2.7" - puppet_gem_version: - - '~> 6.0' - - '~> 7.0' - name: "acceptance (${{ matrix.os }} ruby ${{ matrix.ruby_version }} |${{ matrix.puppet_gem_version }})" + - "3.2" + include: + - ruby-version: '2.7' + puppet_gem_version: '~> 7.0' + - ruby_version: '3.2' + puppet_gem_version: 'https://github.com/puppetlabs/puppet' # puppet8' + runs_on: + - "ubuntu-latest" + - "windows-latest" uses: "puppetlabs/cat-github-actions/.github/workflows/gem_acceptance.yml@main" secrets: "inherit" with: ruby_version: ${{ matrix.ruby_version }} - rake_task: 'acceptance' puppet_version: ${{ matrix.puppet_gem_version }} - runs_on: ${{ matrix.os }} + runs_on: ${{ matrix.runs_on }} diff --git a/.rubocop.yml b/.rubocop.yml index a63a887..2ccc89f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,183 +1,19 @@ -require: rubocop-rspec +inherit_from: .rubocop_todo.yml + +require: + - rubocop-performance + - rubocop-rspec AllCops: - TargetRubyVersion: 2.5 Exclude: - # binstubs, and other utilities - - bin/**/* - - vendor/**/* - - vendor/**/.* - # package testing gems - - package-testing/vendor/**/* - - package-testing/vendor/**/.* - # Any thing in test fixtures + - Gemfile + - Rakefile - spec/fixtures/**/* + - vendor/bundle/**/* + NewCops: enable + SuggestExtensions: false + TargetRubyVersion: '2.7' -# Metrics, excludes complexity and sizing metrics for now, as ruby's defaults are very strict -Metrics/AbcSize: - Enabled: False - -Metrics/BlockLength: - Description: rspec uses long describe blocks, so allow long blocks under spec/ - Enabled: False - Exclude: - - 'spec/**/*.rb' - -Metrics/ClassLength: - Enabled: False - -Metrics/CyclomaticComplexity: - Enabled: False - -Layout/LineLength: - Description: People have wide screens, use them. - Max: 200 - -Metrics/MethodLength: - Enabled: False - -Metrics/ModuleLength: - Enabled: False - -Metrics/ParameterLists: - Enabled: False - -Metrics/PerceivedComplexity: - Enabled: False - -# RSpec cops -RSpec/BeforeAfterAll: - Description: Beware of using after(:all) as it may cause state to leak between tests. A necessary evil in acceptance testing. - Exclude: - - 'spec/acceptance/**/*.rb' - - 'package-testing/spec/package/**/*.rb' - -RSpec/DescribeClass: - Description: This cop does not account for rspec-puppet, and beaker-rspec usage. - Enabled: False - -RSpec/HookArgument: - Description: Prefer explicit :each argument, matching existing module's style - EnforcedStyle: each - -RSpec/NestedGroups: - Description: Nested groups can lead to cleaner tests with less duplication - Max: 10 - -RSpec/ExampleLength: - Description: Forcing short examples leads to the creation of one-time use let() helpers - Enabled: False - -RSpec/MessageSpies: - EnforcedStyle: receive - -RSpec/ScatteredSetup: - Enabled: False - -# This is fine -RSpec/ImplicitSubject: - Enabled: false - -# Set a reasonble max level -RSpec/MultipleExpectations: - Max: 10 - -# Nested contexts don't comply -RSpec/ContextWording: - Enabled: false - -# This is allowed -RSpec/SubjectStub: - Enabled: false - -# Doesn't help readability -RSpec/PredicateMatcher: - Enabled: false - -# Style Cops -Style/AsciiComments: - Description: Names, non-english speaking communities. - Enabled: False - -Style/BlockDelimiters: - Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to be consistent then. - EnforcedStyle: braces_for_chaining - +# Disabled Style/ClassAndModuleChildren: - Description: Compact style reduces the required amount of indentation. - EnforcedStyle: compact - -Style/EmptyElse: - Description: Enforce against empty else clauses, but allow `nil` for clarity. - EnforcedStyle: empty - -Style/FormatString: - Description: Following the main puppet project's style, prefer the % format format. - EnforcedStyle: percent - -Style/FormatStringToken: - Description: Following the main puppet project's style, prefer the simpler template tokens over annotated ones. - EnforcedStyle: template - -Style/IfUnlessModifier: - Description: Post-fix `if` modifiers are hard to parse for newcomers. We don't want to encourage them. Post-fix `unless` modifiers could be nice in some cases, but the Cop doesn't differentiate. - Enabled: false - -Style/Lambda: - Description: Prefer the keyword for easier discoverability. - EnforcedStyle: literal - -Style/MethodCalledOnDoEndBlock: - Enabled: true - -Style/RegexpLiteral: - Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 - EnforcedStyle: percent_r - -Style/SymbolProc: - Description: SymbolProc notation is not discoverable Enabled: false - -Style/TernaryParentheses: - Description: Checks for use of parentheses around ternary conditions. Enforce parentheses on complex expressions for better readability, but seriously consider breaking it up. - EnforcedStyle: require_parentheses_when_complex - -Style/TrailingCommaInArguments: - Description: Prefer always trailing comma on multiline argument lists. This makes diffs, and re-ordering nicer. - EnforcedStyleForMultiline: comma - -Style/TrailingCommaInArrayLiteral: - Description: Prefer always trailing comma on multiline literals. This makes diffs, and re-ordering nicer. - EnforcedStyleForMultiline: comma - -Style/TrailingCommaInHashLiteral: - Description: Prefer always trailing comma on multiline literals. This makes diffs, and re-ordering nicer. - EnforcedStyleForMultiline: comma - -Style/SymbolArray: - Description: Using percent style obscures symbolic intent of array's contents. - Enabled: true - EnforcedStyle: brackets - -Style/HashEachMethods: - Enabled: true - -Style/HashTransformKeys: - Enabled: true - -Style/HashTransformValues: - Enabled: true - -# Enforce LF line endings, even when on Windows -Layout/EndOfLine: - EnforcedStyle: lf - -# new as of rubocop 0.81 -Lint/RaiseException: - Enabled: true - -Lint/StructNewOverride: - Enabled: true - -RSpec/MultipleMemoizedHelpers: - Max: 14 diff --git a/Gemfile b/Gemfile index c9985da..12f8a4a 100644 --- a/Gemfile +++ b/Gemfile @@ -5,40 +5,31 @@ source 'https://rubygems.org' # Specify your gem's dependencies in puppet-modulebuilder.gemspec gemspec -group :development do - ruby_version = Gem::Version.new(RUBY_VERSION) - - gem 'rake', '~> 12.0' - gem 'rspec', '~> 3.0' - - gem 'rubocop', '= 1.6.1', require: false - gem 'rubocop-performance', '= 1.9.1', require: false - gem 'rubocop-rspec', '= 2.0.1', require: false +def location_for(place_or_version, fake_version = nil) + git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} + file_url_regex = %r{\Afile:\/\/(?.*)} + + if place_or_version && (git_url = place_or_version.match(git_url_regex)) + [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact + elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) + ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] + else + [place_or_version, { require: false }] + end +end - gem 'codecov', '~> 0.1' - gem 'github_changelog_generator', '~> 1.15', require: false - gem 'simplecov', '~> 0.18' - gem 'simplecov-console', '~> 0.6' +group :development do + gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION']) - puppet_version = if ruby_version >= Gem::Version.new('2.7.0') - '~> 7.0' - elsif ruby_version >= Gem::Version.new('2.5.0') - '~> 6.0' - else - '~> 5.0' - end + gem 'rake' + gem 'rspec', '~> 3.1' - gem 'puppet', puppet_version -end + gem 'rubocop', '~> 1.48', require: false + gem 'rubocop-performance', '~> 1.16', require: false + gem 'rubocop-rspec', '~> 2.19', require: false -# Evaluate Gemfile.local and ~/.gemfile if they exist -extra_gemfiles = [ - "#{__FILE__}.local", - File.join(Dir.home, '.gemfile'), -] + gem 'codecov' + gem 'simplecov' + gem 'simplecov-console' -extra_gemfiles.each do |gemfile| - if File.file?(gemfile) && File.readable?(gemfile) - eval(File.read(gemfile), binding) # rubocop:disable Security/Eval - end end diff --git a/Rakefile b/Rakefile index 9477c4a..f589475 100644 --- a/Rakefile +++ b/Rakefile @@ -2,18 +2,6 @@ require 'bundler/gem_tasks' require 'rspec/core/rake_task' -begin - # make rubocop optional to deal with ruby 2.1 - require 'rubocop/rake_task' - - RuboCop::RakeTask.new(:rubocop) do |task| - task.options = %w[-D -S -E] - end - - task default: [:rubocop] -rescue LoadError => e - puts "Can't load 'rubocop/rake_task': #{e.inspect}" -end RSpec::Core::RakeTask.new(:spec) do |t| t.pattern = 'spec/unit/**/*_spec.rb' @@ -24,24 +12,3 @@ RSpec::Core::RakeTask.new(:acceptance) do |t| end task default: [:spec, :acceptance] - -if Bundler.rubygems.find_name('github_changelog_generator').any? - require 'github_changelog_generator/task' - GitHubChangelogGenerator::RakeTask.new :changelog do |config| - config.user = 'puppetlabs' - config.project = 'puppet-modulebuilder' - require 'puppet/modulebuilder/version' - config.future_release = "v#{Puppet::Modulebuilder::VERSION}" - config.exclude_labels = ['maintenance'] - config.header = <<-HEADER - # Change log - - All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org). - HEADER - .gsub(%r{^ *}, '') - - config.add_pr_wo_labels = true - config.issues = false - config.merge_prefix = '### UNCATEGORIZED PRS; GO LABEL THEM' - end -end From 2c50f146307a33e4ce01bd0cc14329f18584df22 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:48:05 +0100 Subject: [PATCH 02/25] (CONT-881) Correct Lint/RedundantCopDisableDirective --- lib/puppet/modulebuilder/builder.rb | 2 +- spec/acceptance/puppet/modulebuilder/builder_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/modulebuilder/builder.rb b/lib/puppet/modulebuilder/builder.rb index 93bfe1f..bd8d770 100644 --- a/lib/puppet/modulebuilder/builder.rb +++ b/lib/puppet/modulebuilder/builder.rb @@ -195,7 +195,7 @@ def validate_path_encoding!(path) return unless path =~ %r{[^\x00-\x7F]} raise ArgumentError, "'%{path}' can only include ASCII characters in its path or " \ - 'filename in order to be compatible with a wide range of hosts.' % { path: path } + 'filename in order to be compatible with a wide range of hosts.' % { path: path } end # Creates a gzip compressed tarball of the build directory. diff --git a/spec/acceptance/puppet/modulebuilder/builder_spec.rb b/spec/acceptance/puppet/modulebuilder/builder_spec.rb index 919a218..9f15253 100644 --- a/spec/acceptance/puppet/modulebuilder/builder_spec.rb +++ b/spec/acceptance/puppet/modulebuilder/builder_spec.rb @@ -81,7 +81,7 @@ FileUtils.rm_rf(extract_path) if Dir.exist?(extract_path) end - it 'expands the expected paths' do # rubocop:disable RSpec/MultipleExpectations This is expected + it 'expands the expected paths' do # This is expected # No development directories expect('/spec/*').to be_an_empty_glob expect('/.vscode/*').to be_an_empty_glob From 9af9047fd184ee24ee620089b76684c75355a288 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:48:42 +0100 Subject: [PATCH 03/25] (CONT-881) Correct Lint/NonAtomicFileOperation --- spec/acceptance/puppet/modulebuilder/builder_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/acceptance/puppet/modulebuilder/builder_spec.rb b/spec/acceptance/puppet/modulebuilder/builder_spec.rb index 9f15253..1902290 100644 --- a/spec/acceptance/puppet/modulebuilder/builder_spec.rb +++ b/spec/acceptance/puppet/modulebuilder/builder_spec.rb @@ -21,7 +21,7 @@ end after(:each) do - FileUtils.rm_rf(tmp_dir) if Dir.exist?(tmp_dir) + FileUtils.rm_rf(tmp_dir) end end @@ -78,7 +78,7 @@ end after(:each) do - FileUtils.rm_rf(extract_path) if Dir.exist?(extract_path) + FileUtils.rm_rf(extract_path) end it 'expands the expected paths' do # This is expected From a1737ffbd26d5ed5ee40cb940ce4d0e5b7e9e0cd Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:49:18 +0100 Subject: [PATCH 04/25] (CONT-881) Correct Lint/RedundantCopDisableDirective --- lib/puppet/modulebuilder/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/modulebuilder/version.rb b/lib/puppet/modulebuilder/version.rb index bb5649b..0dc90ac 100644 --- a/lib/puppet/modulebuilder/version.rb +++ b/lib/puppet/modulebuilder/version.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Puppet # rubocop:disable Style/ClassAndModuleChildren +module Puppet module Modulebuilder VERSION = '0.3.0' end From 5ee2e78f1087fff96220bbd4c98b913155d571c4 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:50:16 +0100 Subject: [PATCH 05/25] (CONT-881) Correct Performance/RegexpMatch --- lib/puppet/modulebuilder/builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/modulebuilder/builder.rb b/lib/puppet/modulebuilder/builder.rb index bd8d770..68d67bc 100644 --- a/lib/puppet/modulebuilder/builder.rb +++ b/lib/puppet/modulebuilder/builder.rb @@ -192,7 +192,7 @@ def ignore_file # # @return [nil] def validate_path_encoding!(path) - return unless path =~ %r{[^\x00-\x7F]} + return unless %r{[^\x00-\x7F]}.match?(path) raise ArgumentError, "'%{path}' can only include ASCII characters in its path or " \ 'filename in order to be compatible with a wide range of hosts.' % { path: path } From 2134d9df783282dd4290c427d3f3a63ab433be46 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:50:46 +0100 Subject: [PATCH 06/25] (CONT-881) Correct RSpec/BeNil --- spec/unit/puppet/modulebuilder_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/puppet/modulebuilder_spec.rb b/spec/unit/puppet/modulebuilder_spec.rb index f07a410..f87efb2 100644 --- a/spec/unit/puppet/modulebuilder_spec.rb +++ b/spec/unit/puppet/modulebuilder_spec.rb @@ -2,6 +2,6 @@ RSpec.describe Puppet::Modulebuilder do it 'has a version number' do - expect(Puppet::Modulebuilder::VERSION).not_to be nil + expect(Puppet::Modulebuilder::VERSION).not_to be_nil end end From e5fe66d5b7abc4a1fa174c95f98e472ebc8a4ffc Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:51:19 +0100 Subject: [PATCH 07/25] (CONT-881) Correct RSpec/HookArgument --- .../puppet/modulebuilder/builder_spec.rb | 8 +++--- .../unit/puppet/modulebuilder/builder_spec.rb | 28 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/spec/acceptance/puppet/modulebuilder/builder_spec.rb b/spec/acceptance/puppet/modulebuilder/builder_spec.rb index 1902290..eda4cd8 100644 --- a/spec/acceptance/puppet/modulebuilder/builder_spec.rb +++ b/spec/acceptance/puppet/modulebuilder/builder_spec.rb @@ -11,7 +11,7 @@ let(:module_source_actual) { File.join(tmp_dir, 'module') } let(:output_dir) { File.join(tmp_dir, 'pkg') } - before(:each) do + before do # Copy the module to the temporary directory FileUtils.cp_r(File.join(FIXTURES_DIR, 'module'), tmp_dir) @@ -20,7 +20,7 @@ FileUtils.ln_s(module_source_actual, module_source) end - after(:each) do + after do FileUtils.rm_rf(tmp_dir) end end @@ -65,7 +65,7 @@ end end - before(:each) do + before do # Force the module to be built... built_tarball = tarball_name @@ -77,7 +77,7 @@ raise 'Failed to install the module using Puppet. Missing extract directory' if extracted_module_path.nil? end - after(:each) do + after do FileUtils.rm_rf(extract_path) end diff --git a/spec/unit/puppet/modulebuilder/builder_spec.rb b/spec/unit/puppet/modulebuilder/builder_spec.rb index b7ee5ee..3c845e9 100644 --- a/spec/unit/puppet/modulebuilder/builder_spec.rb +++ b/spec/unit/puppet/modulebuilder/builder_spec.rb @@ -11,7 +11,7 @@ let(:logger) { nil } let(:root_dir) { Gem.win_platform? ? 'C:/' : '/' } - before(:each) do + before do # Mock that the module source exists allow(builder).to receive(:file_directory?).with(module_source).and_return(true) allow(builder).to receive(:file_readable?).with(module_source).and_return(true) @@ -19,7 +19,7 @@ end shared_context 'with mock metadata' do |metadata_content| - before(:each) do + before do content = metadata_content.nil? ? "{\"name\": \"my-module\",\n\"version\": \"0.1.0\"}" : metadata_content allow(builder).to receive(:file_exists?).with(%r{metadata\.json}).and_return(true) allow(builder).to receive(:file_readable?).with(%r{metadata\.json}).and_return(true) @@ -98,7 +98,7 @@ describe '#stage_module_in_build_dir' do let(:module_source) { File.join(root_dir, 'tmp', 'my-module') } - before(:each) do + before do require 'pathspec' allow(builder).to receive(:ignored_files).and_return(PathSpec.new("/spec/\n")) require 'find' @@ -109,7 +109,7 @@ allow(builder).to receive(:copy_mtime).with(module_source) end - after(:each) do + after do builder.stage_module_in_build_dir end @@ -146,7 +146,7 @@ let(:path_in_build_dir) { File.join(module_source, 'pkg', release_name, 'test') } let(:release_name) { 'my-module-0.0.1' } - before(:each) do + before do builder.release_name = release_name end @@ -156,7 +156,7 @@ File.join(module_source, relative_path).force_encoding(Encoding.find('filesystem')).encode('utf-8', invalid: :replace) end - before(:each) do + before do allow(builder).to receive(:file_directory?).with(path).and_return(true) allow(builder).to receive(:file_symlink?).with(path).and_return(false) allow(builder).to receive(:fileutils_cp).with(path, anything, anything).and_return(true) @@ -174,7 +174,7 @@ end context 'when the path is a directory' do - before(:each) do + before do allow(builder).to receive(:file_directory?).with(path_to_stage).and_return(true) allow(builder).to receive(:file_stat).with(path_to_stage).and_return(instance_double(File::Stat, mode: 0o100755)) end @@ -186,7 +186,7 @@ end context 'when the path is a symlink' do - before(:each) do + before do allow(builder).to receive(:file_directory?).with(path_to_stage).and_return(false) allow(builder).to receive(:file_symlink?).with(path_to_stage).and_return(true) end @@ -200,7 +200,7 @@ end context 'when the path is a regular file' do - before(:each) do + before do allow(builder).to receive(:file_directory?).with(path_to_stage).and_return(false) allow(builder).to receive(:file_symlink?).with(path_to_stage).and_return(false) end @@ -279,7 +279,7 @@ end let(:module_source) { File.join(root_dir, 'tmp', 'my-module') } - before(:each) do + before do require 'pathspec' allow(builder).to receive(:ignored_files).and_return(PathSpec.new(ignore_patterns.join("\n"))) end @@ -310,7 +310,7 @@ end let(:available_files) { [] } - before(:each) do + before do available_files.each do |file| file_path = File.join(module_source, file) @@ -360,13 +360,13 @@ let(:module_source) { File.join(root_dir, 'tmp', 'my-module') } - before(:each) do + before do require 'pathspec' allow(File).to receive(:realdirpath) { |path| path } end context 'when no ignore file is present in the module' do - before(:each) do + before do allow(builder).to receive(:ignore_file).and_return(nil) end @@ -378,7 +378,7 @@ end context 'when an ignore file is present in the module' do - before(:each) do + before do ignore_file_path = File.join(module_source, '.pdkignore') ignore_file_content = "/vendor/\n" From 6bfcd40f2e89017fe06282d669dc7cdb57a8d8ea Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:52:05 +0100 Subject: [PATCH 08/25] (CONT-881) Correct RSpec/ImplicitSubject --- spec/unit/puppet/modulebuilder/builder_spec.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/unit/puppet/modulebuilder/builder_spec.rb b/spec/unit/puppet/modulebuilder/builder_spec.rb index 3c845e9..902fe59 100644 --- a/spec/unit/puppet/modulebuilder/builder_spec.rb +++ b/spec/unit/puppet/modulebuilder/builder_spec.rb @@ -334,21 +334,21 @@ let(:available_files) { ['.gitignore'] } it 'returns the path to the .gitignore file' do - is_expected.to eq(File.join(module_source, '.gitignore')) + expect(subject).to eq(File.join(module_source, '.gitignore')) end context 'and .pmtignore is present' do let(:available_files) { ['.gitignore', '.pmtignore'] } it 'returns the path to the .pmtignore file' do - is_expected.to eq(File.join(module_source, '.pmtignore')) + expect(subject).to eq(File.join(module_source, '.pmtignore')) end context 'and .pdkignore is present' do let(:available_files) { possible_files } it 'returns the path to the .pdkignore file' do - is_expected.to eq(File.join(module_source, '.pdkignore')) + expect(subject).to eq(File.join(module_source, '.pdkignore')) end end end @@ -371,9 +371,9 @@ end it 'returns a PathSpec object with the target dir' do - is_expected.to be_a(PathSpec) - is_expected.not_to be_empty - is_expected.to match('pkg/') + expect(subject).to be_a(PathSpec) + expect(subject).not_to be_empty + expect(subject).to match('pkg/') end end @@ -387,8 +387,8 @@ end it 'returns a PathSpec object populated by the ignore file' do - is_expected.to be_a(PathSpec) - is_expected.to have_attributes(specs: array_including(an_instance_of(PathSpec::GitIgnoreSpec))) + expect(subject).to be_a(PathSpec) + expect(subject).to have_attributes(specs: array_including(an_instance_of(PathSpec::GitIgnoreSpec))) end end end From c023d36a914e2506cb359d0b5f867a15de42a4ba Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:52:38 +0100 Subject: [PATCH 09/25] (CONT-881) Correct RSpec/NamedSubject --- spec/unit/puppet/modulebuilder/builder_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/unit/puppet/modulebuilder/builder_spec.rb b/spec/unit/puppet/modulebuilder/builder_spec.rb index 902fe59..34857a3 100644 --- a/spec/unit/puppet/modulebuilder/builder_spec.rb +++ b/spec/unit/puppet/modulebuilder/builder_spec.rb @@ -285,15 +285,15 @@ end it 'returns false for paths not matched by the patterns' do - expect(builder.ignored_path?(File.join(module_source, 'bar'))).to be_falsey + expect(builder).not_to be_ignored_path(File.join(module_source, 'bar')) end it 'returns true for paths matched by the patterns' do - expect(builder.ignored_path?(File.join(module_source, 'foo'))).to be_truthy + expect(builder).to be_ignored_path(File.join(module_source, 'foo')) end it 'returns true for children of ignored parent directories' do - expect(builder.ignored_path?(File.join(module_source, 'vendor', 'test'))).to be_truthy + expect(builder).to be_ignored_path(File.join(module_source, 'vendor', 'test')) end end From 674e7b447466c6920b0cfbd4b82a6cc5141fa83b Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:53:06 +0100 Subject: [PATCH 10/25] (CONT-881) Correct RSpec/NamedSubject --- spec/unit/puppet/modulebuilder/builder_spec.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/unit/puppet/modulebuilder/builder_spec.rb b/spec/unit/puppet/modulebuilder/builder_spec.rb index 34857a3..d849a6d 100644 --- a/spec/unit/puppet/modulebuilder/builder_spec.rb +++ b/spec/unit/puppet/modulebuilder/builder_spec.rb @@ -163,9 +163,9 @@ end it do - expect { + expect do builder.stage_path(path) - }.to raise_error(ArgumentError, %r{can only include ASCII characters}) + end.to raise_error(ArgumentError, %r{can only include ASCII characters}) end end @@ -214,9 +214,9 @@ let(:path_to_stage) { File.join(module_source, File.join(*['thing'] * 300)) } it do - expect { + expect do builder.stage_path(path_to_stage) - }.to raise_error(RuntimeError, %r{longer than 256.*Rename the file or exclude it from the package}) + end.to raise_error(RuntimeError, %r{longer than 256.*Rename the file or exclude it from the package}) end end end @@ -255,17 +255,17 @@ describe '#validate_path_encoding!' do context 'when passed a path containing only ASCII characters' do it do - expect { + expect do builder.validate_path_encoding!(File.join('path', 'to', 'file')) - }.not_to raise_error + end.not_to raise_error end end context 'when passed a path containing non-ASCII characters' do it do - expect { + expect do builder.validate_path_encoding!(File.join('path', "\330\271to", 'file')) - }.to raise_error(ArgumentError, %r{can only include ASCII characters}) + end.to raise_error(ArgumentError, %r{can only include ASCII characters}) end end end From 924470481f97563c770f257946387d166c57d87d Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:54:00 +0100 Subject: [PATCH 11/25] (CONT-881) Correct Layout/LineEndStringConcatenationIndentation --- lib/puppet/modulebuilder/builder.rb | 37 ++++++++++++----------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/lib/puppet/modulebuilder/builder.rb b/lib/puppet/modulebuilder/builder.rb index 68d67bc..5e125d9 100644 --- a/lib/puppet/modulebuilder/builder.rb +++ b/lib/puppet/modulebuilder/builder.rb @@ -19,7 +19,7 @@ class Builder attr_reader :destination, :logger def initialize(source, destination = nil, logger = nil) - raise ArgumentError, 'logger is expected to be nil or a Logger. Got %{klass}' % { klass: logger.class } unless logger.nil? || logger.is_a?(Logger) + raise ArgumentError, format('logger is expected to be nil or a Logger. Got %{klass}', klass: logger.class) unless logger.nil? || logger.is_a?(Logger) @source_validated = false @source = source @@ -119,7 +119,7 @@ def stage_path(path) fileutils_cp(path, dest_path, preserve: true) end rescue ArgumentError => e - raise '%{message} Rename the file or exclude it from the package by adding it to the .pdkignore file in your module.' % { message: e.message } + raise format('%{message} Rename the file or exclude it from the package by adding it to the .pdkignore file in your module.', message: e.message) end end @@ -158,10 +158,8 @@ def warn_symlink(path) symlink_path = Pathname.new(path) module_path = Pathname.new(source) - logger.warn 'Symlinks in modules are not supported and will not be included in the package. Please investigate symlink %{from} -> %{to}.' % { - from: symlink_path.relative_path_from(module_path), - to: symlink_path.realpath.relative_path_from(module_path), - } + logger.warn format('Symlinks in modules are not supported and will not be included in the package. Please investigate symlink %{from} -> %{to}.', + from: symlink_path.relative_path_from(module_path), to: symlink_path.realpath.relative_path_from(module_path)) end # Select the most appropriate ignore file in the module directory. @@ -194,8 +192,8 @@ def ignore_file def validate_path_encoding!(path) return unless %r{[^\x00-\x7F]}.match?(path) - raise ArgumentError, "'%{path}' can only include ASCII characters in its path or " \ - 'filename in order to be compatible with a wide range of hosts.' % { path: path } + raise ArgumentError, format("'%{path}' can only include ASCII characters in its path or " \ + 'filename in order to be compatible with a wide range of hosts.', path: path) end # Creates a gzip compressed tarball of the build directory. @@ -228,10 +226,7 @@ def build_package entry_meta[:mode] = orig_mode | min_mode if entry_meta[:mode] != orig_mode - logger.debug('Updated permissions of packaged \'%{entry}\' to %{new_mode}' % { - entry: entry, - new_mode: (entry_meta[:mode] & 0o7777).to_s(8), - }) + logger.debug(format('Updated permissions of packaged \'%{entry}\' to %{new_mode}', entry: entry, new_mode: (entry_meta[:mode] & 0o7777).to_s(8))) end Minitar.pack_file(entry_meta, tar) @@ -294,18 +289,18 @@ def metadata metadata_json_path = File.join(source, 'metadata.json') unless file_exists?(metadata_json_path) - raise ArgumentError, "'%{file}' does not exist or is not a file." % { file: metadata_json_path } + raise ArgumentError, format("'%{file}' does not exist or is not a file.", file: metadata_json_path) end unless file_readable?(metadata_json_path) - raise ArgumentError, "Unable to open '%{file}' for reading." % { file: metadata_json_path } + raise ArgumentError, format("Unable to open '%{file}' for reading.", file: metadata_json_path) end require 'json' begin @metadata = JSON.parse(read_file(metadata_json_path)) rescue JSON::JSONError => e - raise ArgumentError, 'Invalid JSON in metadata.json: %{msg}' % { msg: e.message } + raise ArgumentError, format('Invalid JSON in metadata.json: %{msg}', msg: e.message) end @metadata.freeze end @@ -359,9 +354,7 @@ def release_name # @return [nil] def validate_ustar_path!(path) if path.bytesize > 256 - raise ArgumentError, "The path '%{path}' is longer than 256 bytes." % { - path: path, - } + raise ArgumentError, format("The path '%{path}' is longer than 256 bytes.", path: path) end if path.bytesize <= 100 @@ -385,9 +378,9 @@ def validate_ustar_path!(path) return unless path.bytesize > 100 || prefix.bytesize > 155 raise ArgumentError, \ - "'%{path}' could not be split at a directory separator into two " \ - 'parts, the first having a maximum length of 155 bytes and the ' \ - 'second having a maximum length of 100 bytes.' % { path: path } + format("'%{path}' could not be split at a directory separator into two " \ + 'parts, the first having a maximum length of 155 bytes and the ' \ + 'second having a maximum length of 100 bytes.', path: path) end private @@ -395,7 +388,7 @@ def validate_ustar_path!(path) # Validates that source is able to be built def validate_source! unless file_directory?(@source) && file_readable?(@source) - raise ArgumentError, "Module source '%{source}' does not exist as a directory is or is not readable" % { source: @source } + raise ArgumentError, format("Module source '%{source}' does not exist as a directory is or is not readable", source: @source) end @source_validated = true From 0cc648607d332ce07543800b5a54bac9cf91ca93 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:55:09 +0100 Subject: [PATCH 12/25] (CONT-881) Correct Style/FormatStringToken --- lib/puppet/modulebuilder/builder.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/puppet/modulebuilder/builder.rb b/lib/puppet/modulebuilder/builder.rb index 5e125d9..3b2b626 100644 --- a/lib/puppet/modulebuilder/builder.rb +++ b/lib/puppet/modulebuilder/builder.rb @@ -19,7 +19,7 @@ class Builder attr_reader :destination, :logger def initialize(source, destination = nil, logger = nil) - raise ArgumentError, format('logger is expected to be nil or a Logger. Got %{klass}', klass: logger.class) unless logger.nil? || logger.is_a?(Logger) + raise ArgumentError, format('logger is expected to be nil or a Logger. Got %s', klass: logger.class) unless logger.nil? || logger.is_a?(Logger) @source_validated = false @source = source @@ -119,7 +119,7 @@ def stage_path(path) fileutils_cp(path, dest_path, preserve: true) end rescue ArgumentError => e - raise format('%{message} Rename the file or exclude it from the package by adding it to the .pdkignore file in your module.', message: e.message) + raise format('%s Rename the file or exclude it from the package by adding it to the .pdkignore file in your module.', message: e.message) end end @@ -158,7 +158,7 @@ def warn_symlink(path) symlink_path = Pathname.new(path) module_path = Pathname.new(source) - logger.warn format('Symlinks in modules are not supported and will not be included in the package. Please investigate symlink %{from} -> %{to}.', + logger.warn format('Symlinks in modules are not supported and will not be included in the package. Please investigate symlink %s -> %s.', from: symlink_path.relative_path_from(module_path), to: symlink_path.realpath.relative_path_from(module_path)) end @@ -192,7 +192,7 @@ def ignore_file def validate_path_encoding!(path) return unless %r{[^\x00-\x7F]}.match?(path) - raise ArgumentError, format("'%{path}' can only include ASCII characters in its path or " \ + raise ArgumentError, format("'%s' can only include ASCII characters in its path or " \ 'filename in order to be compatible with a wide range of hosts.', path: path) end @@ -226,7 +226,7 @@ def build_package entry_meta[:mode] = orig_mode | min_mode if entry_meta[:mode] != orig_mode - logger.debug(format('Updated permissions of packaged \'%{entry}\' to %{new_mode}', entry: entry, new_mode: (entry_meta[:mode] & 0o7777).to_s(8))) + logger.debug(format('Updated permissions of packaged \'%s\' to %s', entry: entry, new_mode: (entry_meta[:mode] & 0o7777).to_s(8))) end Minitar.pack_file(entry_meta, tar) @@ -289,18 +289,18 @@ def metadata metadata_json_path = File.join(source, 'metadata.json') unless file_exists?(metadata_json_path) - raise ArgumentError, format("'%{file}' does not exist or is not a file.", file: metadata_json_path) + raise ArgumentError, format("'%s' does not exist or is not a file.", file: metadata_json_path) end unless file_readable?(metadata_json_path) - raise ArgumentError, format("Unable to open '%{file}' for reading.", file: metadata_json_path) + raise ArgumentError, format("Unable to open '%s' for reading.", file: metadata_json_path) end require 'json' begin @metadata = JSON.parse(read_file(metadata_json_path)) rescue JSON::JSONError => e - raise ArgumentError, format('Invalid JSON in metadata.json: %{msg}', msg: e.message) + raise ArgumentError, format('Invalid JSON in metadata.json: %s', msg: e.message) end @metadata.freeze end @@ -354,7 +354,7 @@ def release_name # @return [nil] def validate_ustar_path!(path) if path.bytesize > 256 - raise ArgumentError, format("The path '%{path}' is longer than 256 bytes.", path: path) + raise ArgumentError, format("The path '%s' is longer than 256 bytes.", path: path) end if path.bytesize <= 100 @@ -378,7 +378,7 @@ def validate_ustar_path!(path) return unless path.bytesize > 100 || prefix.bytesize > 155 raise ArgumentError, \ - format("'%{path}' could not be split at a directory separator into two " \ + format("'%s' could not be split at a directory separator into two " \ 'parts, the first having a maximum length of 155 bytes and the ' \ 'second having a maximum length of 100 bytes.', path: path) end @@ -388,7 +388,7 @@ def validate_ustar_path!(path) # Validates that source is able to be built def validate_source! unless file_directory?(@source) && file_readable?(@source) - raise ArgumentError, format("Module source '%{source}' does not exist as a directory is or is not readable", source: @source) + raise ArgumentError, format("Module source '%s' does not exist as a directory is or is not readable", source: @source) end @source_validated = true From 5acbb4326fdfb520d1ae9a544fbf67308b355c10 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:55:46 +0100 Subject: [PATCH 13/25] (CONT-881) Correct Style/IfUnlessModifier --- lib/puppet/modulebuilder/builder.rb | 16 ++++------------ spec/unit/puppet/modulebuilder/builder_spec.rb | 4 +--- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/lib/puppet/modulebuilder/builder.rb b/lib/puppet/modulebuilder/builder.rb index 3b2b626..a81ec75 100644 --- a/lib/puppet/modulebuilder/builder.rb +++ b/lib/puppet/modulebuilder/builder.rb @@ -252,9 +252,7 @@ def ignored_files PathSpec.new(read_file(ignore_file, open_args: 'rb:UTF-8')) end - if File.realdirpath(destination).start_with?(File.realdirpath(source)) - ignored = ignored.add("\/#{File.basename(destination)}\/") - end + ignored = ignored.add("\/#{File.basename(destination)}\/") if File.realdirpath(destination).start_with?(File.realdirpath(source)) DEFAULT_IGNORED.each { |r| ignored.add(r) } @@ -288,13 +286,9 @@ def metadata metadata_json_path = File.join(source, 'metadata.json') - unless file_exists?(metadata_json_path) - raise ArgumentError, format("'%s' does not exist or is not a file.", file: metadata_json_path) - end + raise ArgumentError, format("'%s' does not exist or is not a file.", file: metadata_json_path) unless file_exists?(metadata_json_path) - unless file_readable?(metadata_json_path) - raise ArgumentError, format("Unable to open '%s' for reading.", file: metadata_json_path) - end + raise ArgumentError, format("Unable to open '%s' for reading.", file: metadata_json_path) unless file_readable?(metadata_json_path) require 'json' begin @@ -353,9 +347,7 @@ def release_name # # @return [nil] def validate_ustar_path!(path) - if path.bytesize > 256 - raise ArgumentError, format("The path '%s' is longer than 256 bytes.", path: path) - end + raise ArgumentError, format("The path '%s' is longer than 256 bytes.", path: path) if path.bytesize > 256 if path.bytesize <= 100 prefix = '' diff --git a/spec/unit/puppet/modulebuilder/builder_spec.rb b/spec/unit/puppet/modulebuilder/builder_spec.rb index d849a6d..f71237d 100644 --- a/spec/unit/puppet/modulebuilder/builder_spec.rb +++ b/spec/unit/puppet/modulebuilder/builder_spec.rb @@ -103,9 +103,7 @@ allow(builder).to receive(:ignored_files).and_return(PathSpec.new("/spec/\n")) require 'find' allow(Find).to receive(:find).with(module_source).and_yield(found_file) - if found_file != module_source - allow(builder).to receive(:file_directory?).with(found_file).and_return(false) - end + allow(builder).to receive(:file_directory?).with(found_file).and_return(false) if found_file != module_source allow(builder).to receive(:copy_mtime).with(module_source) end From cb1431b89d53d9ddb3ce5cb2ace9761d200a82bd Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:56:18 +0100 Subject: [PATCH 14/25] (CONT-881) Correct Style/RedundantStringEscape --- lib/puppet/modulebuilder/builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/modulebuilder/builder.rb b/lib/puppet/modulebuilder/builder.rb index a81ec75..280bbb2 100644 --- a/lib/puppet/modulebuilder/builder.rb +++ b/lib/puppet/modulebuilder/builder.rb @@ -252,7 +252,7 @@ def ignored_files PathSpec.new(read_file(ignore_file, open_args: 'rb:UTF-8')) end - ignored = ignored.add("\/#{File.basename(destination)}\/") if File.realdirpath(destination).start_with?(File.realdirpath(source)) + ignored = ignored.add("/#{File.basename(destination)}/") if File.realdirpath(destination).start_with?(File.realdirpath(source)) DEFAULT_IGNORED.each { |r| ignored.add(r) } From f2ac6efb1b3c3643c0cf77237d4e861820d07deb Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:57:04 +0100 Subject: [PATCH 15/25] (CONT-881) Correct Style/RegexpLiteral --- lib/puppet/modulebuilder/builder.rb | 2 +- .../unit/puppet/modulebuilder/builder_spec.rb | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/puppet/modulebuilder/builder.rb b/lib/puppet/modulebuilder/builder.rb index 280bbb2..7d7f2eb 100644 --- a/lib/puppet/modulebuilder/builder.rb +++ b/lib/puppet/modulebuilder/builder.rb @@ -190,7 +190,7 @@ def ignore_file # # @return [nil] def validate_path_encoding!(path) - return unless %r{[^\x00-\x7F]}.match?(path) + return unless /[^\x00-\x7F]/.match?(path) raise ArgumentError, format("'%s' can only include ASCII characters in its path or " \ 'filename in order to be compatible with a wide range of hosts.', path: path) diff --git a/spec/unit/puppet/modulebuilder/builder_spec.rb b/spec/unit/puppet/modulebuilder/builder_spec.rb index f71237d..5141a3a 100644 --- a/spec/unit/puppet/modulebuilder/builder_spec.rb +++ b/spec/unit/puppet/modulebuilder/builder_spec.rb @@ -21,9 +21,9 @@ shared_context 'with mock metadata' do |metadata_content| before do content = metadata_content.nil? ? "{\"name\": \"my-module\",\n\"version\": \"0.1.0\"}" : metadata_content - allow(builder).to receive(:file_exists?).with(%r{metadata\.json}).and_return(true) - allow(builder).to receive(:file_readable?).with(%r{metadata\.json}).and_return(true) - allow(builder).to receive(:read_file).with(%r{metadata\.json}).and_return(content) + allow(builder).to receive(:file_exists?).with(/metadata\.json/).and_return(true) + allow(builder).to receive(:file_readable?).with(/metadata\.json/).and_return(true) + allow(builder).to receive(:read_file).with(/metadata\.json/).and_return(content) end end @@ -31,13 +31,13 @@ context 'when the source does not exist' do it do allow(builder).to receive(:file_directory?).with(module_source).and_return(false) - expect { builder.source }.to raise_error(ArgumentError, %r{does not exist}) + expect { builder.source }.to raise_error(ArgumentError, /does not exist/) end end context 'with an invalid logger' do it do - expect { described_class.new(module_source, module_dest, [123]) }.to raise_error(ArgumentError, %r{logger is expected to}) + expect { described_class.new(module_source, module_dest, [123]) }.to raise_error(ArgumentError, /logger is expected to/) end end @@ -163,7 +163,7 @@ it do expect do builder.stage_path(path) - end.to raise_error(ArgumentError, %r{can only include ASCII characters}) + end.to raise_error(ArgumentError, /can only include ASCII characters/) end end @@ -214,7 +214,7 @@ it do expect do builder.stage_path(path_to_stage) - end.to raise_error(RuntimeError, %r{longer than 256.*Rename the file or exclude it from the package}) + end.to raise_error(RuntimeError, /longer than 256.*Rename the file or exclude it from the package/) end end end @@ -230,11 +230,11 @@ ] bad_paths = { - File.join('a' * 152, 'b' * 11, 'c' * 93) => %r{longer than 256}i, - File.join('a' * 152, 'b' * 10, 'c' * 92) => %r{could not be split}i, - File.join('a' * 162, 'b' * 10) => %r{could not be split}i, - File.join('a' * 10, 'b' * 110) => %r{could not be split}i, - 'a' * 114 => %r{could not be split}i, + File.join('a' * 152, 'b' * 11, 'c' * 93) => /longer than 256/i, + File.join('a' * 152, 'b' * 10, 'c' * 92) => /could not be split/i, + File.join('a' * 162, 'b' * 10) => /could not be split/i, + File.join('a' * 10, 'b' * 110) => /could not be split/i, + 'a' * 114 => /could not be split/i, } good_paths.each do |path| @@ -263,7 +263,7 @@ it do expect do builder.validate_path_encoding!(File.join('path', "\330\271to", 'file')) - end.to raise_error(ArgumentError, %r{can only include ASCII characters}) + end.to raise_error(ArgumentError, /can only include ASCII characters/) end end end From 7d08a46b3c8854453df55208b6eb8f184e4be446 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:57:37 +0100 Subject: [PATCH 16/25] (CONT-881) Correct Style/TrailingCommaInArrayLiteral --- lib/puppet/modulebuilder/builder.rb | 6 +++--- spec/spec_helper.rb | 2 +- spec/unit/puppet/modulebuilder/builder_spec.rb | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/puppet/modulebuilder/builder.rb b/lib/puppet/modulebuilder/builder.rb index 7d7f2eb..e5984f8 100644 --- a/lib/puppet/modulebuilder/builder.rb +++ b/lib/puppet/modulebuilder/builder.rb @@ -13,7 +13,7 @@ class Builder '/checksums.json', '/REVISION', '/spec/fixtures/modules/', - '/vendor/', + '/vendor/' ].freeze attr_reader :destination, :logger @@ -173,7 +173,7 @@ def ignore_file @ignore_file ||= [ File.join(source, '.pdkignore'), File.join(source, '.pmtignore'), - File.join(source, '.gitignore'), + File.join(source, '.gitignore') ].find { |file| file_exists?(file) && file_readable?(file) } end @@ -321,7 +321,7 @@ def package_already_exists? def release_name @release_name ||= [ metadata['name'], - metadata['version'], + metadata['version'] ].join('-') end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d590c80..e61678d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,7 +9,7 @@ SimpleCov.formatters = [ SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::Console, - SimpleCov::Formatter::Codecov, + SimpleCov::Formatter::Codecov ] SimpleCov.start do track_files 'lib/**/*.rb' diff --git a/spec/unit/puppet/modulebuilder/builder_spec.rb b/spec/unit/puppet/modulebuilder/builder_spec.rb index 5141a3a..1c86d06 100644 --- a/spec/unit/puppet/modulebuilder/builder_spec.rb +++ b/spec/unit/puppet/modulebuilder/builder_spec.rb @@ -226,7 +226,7 @@ File.join('a' * 151, *['qwer'] * 19, 'bla'), File.join('/', 'a' * 49, 'b' * 50), File.join('a' * 49, "#{'b' * 50}x"), - File.join("#{'a' * 49}x", 'b' * 50), + File.join("#{'a' * 49}x", 'b' * 50) ] bad_paths = { @@ -272,7 +272,7 @@ let(:ignore_patterns) do [ '/vendor/', - 'foo', + 'foo' ] end let(:module_source) { File.join(root_dir, 'tmp', 'my-module') } @@ -303,7 +303,7 @@ [ '.pdkignore', '.pmtignore', - '.gitignore', + '.gitignore' ] end let(:available_files) { [] } From dd4d6bc2eca24857469c7a3e480f21bdc4b202c9 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:58:10 +0100 Subject: [PATCH 17/25] (CONT-881) Correct Style/TrailingCommaInHashLiteral --- lib/puppet/modulebuilder/builder.rb | 4 ++-- spec/unit/puppet/modulebuilder/builder_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/puppet/modulebuilder/builder.rb b/lib/puppet/modulebuilder/builder.rb index e5984f8..74ea105 100644 --- a/lib/puppet/modulebuilder/builder.rb +++ b/lib/puppet/modulebuilder/builder.rb @@ -61,7 +61,7 @@ def build_dir def build_context { parent_dir: destination, - build_dir_name: release_name, + build_dir_name: release_name }.freeze end @@ -217,7 +217,7 @@ def build_package tar = Minitar::Output.new(gz) Find.find(build_context[:build_dir_name]) do |entry| entry_meta = { - name: entry, + name: entry } orig_mode = File.stat(entry).mode diff --git a/spec/unit/puppet/modulebuilder/builder_spec.rb b/spec/unit/puppet/modulebuilder/builder_spec.rb index 1c86d06..4150f60 100644 --- a/spec/unit/puppet/modulebuilder/builder_spec.rb +++ b/spec/unit/puppet/modulebuilder/builder_spec.rb @@ -234,7 +234,7 @@ File.join('a' * 152, 'b' * 10, 'c' * 92) => /could not be split/i, File.join('a' * 162, 'b' * 10) => /could not be split/i, File.join('a' * 10, 'b' * 110) => /could not be split/i, - 'a' * 114 => /could not be split/i, + 'a' * 114 => /could not be split/i } good_paths.each do |path| From 6234f122e11597ed78ed2bba9e3310ffb6610f37 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 09:59:31 +0100 Subject: [PATCH 18/25] (CONT-881) Correct Layout/LineLength --- lib/puppet/modulebuilder/builder.rb | 32 +++++++++++++++---- .../puppet/modulebuilder/builder_spec.rb | 10 ++++-- .../unit/puppet/modulebuilder/builder_spec.rb | 10 ++++-- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/lib/puppet/modulebuilder/builder.rb b/lib/puppet/modulebuilder/builder.rb index 74ea105..ebecc17 100644 --- a/lib/puppet/modulebuilder/builder.rb +++ b/lib/puppet/modulebuilder/builder.rb @@ -19,7 +19,11 @@ class Builder attr_reader :destination, :logger def initialize(source, destination = nil, logger = nil) - raise ArgumentError, format('logger is expected to be nil or a Logger. Got %s', klass: logger.class) unless logger.nil? || logger.is_a?(Logger) + unless logger.nil? || logger.is_a?(Logger) + raise ArgumentError, + format('logger is expected to be nil or a Logger. Got %s', + klass: logger.class) + end @source_validated = false @source = source @@ -119,7 +123,9 @@ def stage_path(path) fileutils_cp(path, dest_path, preserve: true) end rescue ArgumentError => e - raise format('%s Rename the file or exclude it from the package by adding it to the .pdkignore file in your module.', message: e.message) + raise format( + '%s Rename the file or exclude it from the package by adding it to the .pdkignore file in your module.', message: e.message + ) end end @@ -226,7 +232,8 @@ def build_package entry_meta[:mode] = orig_mode | min_mode if entry_meta[:mode] != orig_mode - logger.debug(format('Updated permissions of packaged \'%s\' to %s', entry: entry, new_mode: (entry_meta[:mode] & 0o7777).to_s(8))) + logger.debug(format('Updated permissions of packaged \'%s\' to %s', entry: entry, + new_mode: (entry_meta[:mode] & 0o7777).to_s(8))) end Minitar.pack_file(entry_meta, tar) @@ -252,7 +259,9 @@ def ignored_files PathSpec.new(read_file(ignore_file, open_args: 'rb:UTF-8')) end - ignored = ignored.add("/#{File.basename(destination)}/") if File.realdirpath(destination).start_with?(File.realdirpath(source)) + if File.realdirpath(destination).start_with?(File.realdirpath(source)) + ignored = ignored.add("/#{File.basename(destination)}/") + end DEFAULT_IGNORED.each { |r| ignored.add(r) } @@ -286,9 +295,17 @@ def metadata metadata_json_path = File.join(source, 'metadata.json') - raise ArgumentError, format("'%s' does not exist or is not a file.", file: metadata_json_path) unless file_exists?(metadata_json_path) + unless file_exists?(metadata_json_path) + raise ArgumentError, + format("'%s' does not exist or is not a file.", + file: metadata_json_path) + end - raise ArgumentError, format("Unable to open '%s' for reading.", file: metadata_json_path) unless file_readable?(metadata_json_path) + unless file_readable?(metadata_json_path) + raise ArgumentError, + format("Unable to open '%s' for reading.", + file: metadata_json_path) + end require 'json' begin @@ -380,7 +397,8 @@ def validate_ustar_path!(path) # Validates that source is able to be built def validate_source! unless file_directory?(@source) && file_readable?(@source) - raise ArgumentError, format("Module source '%s' does not exist as a directory is or is not readable", source: @source) + raise ArgumentError, + format("Module source '%s' does not exist as a directory is or is not readable", source: @source) end @source_validated = true diff --git a/spec/acceptance/puppet/modulebuilder/builder_spec.rb b/spec/acceptance/puppet/modulebuilder/builder_spec.rb index eda4cd8..9f8fa3d 100644 --- a/spec/acceptance/puppet/modulebuilder/builder_spec.rb +++ b/spec/acceptance/puppet/modulebuilder/builder_spec.rb @@ -39,7 +39,11 @@ context 'which is installed via Puppet' do let(:extract_path) { Dir.mktmpdir } - let(:extracted_module_path) { File.join(extract_path, Dir.entries(extract_path).reject { |p| %w[. ..].include?(p) }.first) } + let(:extracted_module_path) do + File.join(extract_path, Dir.entries(extract_path).reject do |p| + %w[. ..].include?(p) + end.first) + end RSpec::Matchers.define :be_an_empty_glob do match do |actual| @@ -73,7 +77,9 @@ require 'open3' output, status = Open3.capture2e("puppet module install --force --ignore-dependencies --target-dir #{extract_path} --verbose #{built_tarball}") - raise "Failed to install the module using Puppet. Exit code #{status.exitstatus}: #{output}" unless status.exitstatus.zero? + unless status.exitstatus.zero? + raise "Failed to install the module using Puppet. Exit code #{status.exitstatus}: #{output}" + end raise 'Failed to install the module using Puppet. Missing extract directory' if extracted_module_path.nil? end diff --git a/spec/unit/puppet/modulebuilder/builder_spec.rb b/spec/unit/puppet/modulebuilder/builder_spec.rb index 4150f60..f499b47 100644 --- a/spec/unit/puppet/modulebuilder/builder_spec.rb +++ b/spec/unit/puppet/modulebuilder/builder_spec.rb @@ -37,7 +37,9 @@ context 'with an invalid logger' do it do - expect { described_class.new(module_source, module_dest, [123]) }.to raise_error(ArgumentError, /logger is expected to/) + expect do + described_class.new(module_source, module_dest, [123]) + end.to raise_error(ArgumentError, /logger is expected to/) end end @@ -151,7 +153,8 @@ context 'when the path contains non-ASCII characters' do RSpec.shared_examples 'a failing path' do |relative_path| let(:path) do - File.join(module_source, relative_path).force_encoding(Encoding.find('filesystem')).encode('utf-8', invalid: :replace) + File.join(module_source, relative_path).force_encoding(Encoding.find('filesystem')).encode('utf-8', + invalid: :replace) end before do @@ -174,7 +177,8 @@ context 'when the path is a directory' do before do allow(builder).to receive(:file_directory?).with(path_to_stage).and_return(true) - allow(builder).to receive(:file_stat).with(path_to_stage).and_return(instance_double(File::Stat, mode: 0o100755)) + allow(builder).to receive(:file_stat).with(path_to_stage).and_return(instance_double(File::Stat, + mode: 0o100755)) end it 'creates the directory in the build directory' do From da6621d18939b934534853f27a606d050fb76285 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 10:00:10 +0100 Subject: [PATCH 19/25] (CONT-881) Add rubocop_todo --- .rubocop_todo.yml | 95 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..de8d07c --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,95 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-04-18 09:21:48 UTC using RuboCop version 1.50.2. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/RequireMFA: + Exclude: + - 'puppet-modulebuilder.gemspec' + +# Offense count: 1 +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: + Exclude: + - 'puppet-modulebuilder.gemspec' + +# Offense count: 5 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 31 + +# Offense count: 1 +# Configuration parameters: CountComments, CountAsOne. +Metrics/ClassLength: + Max: 255 + +# Offense count: 6 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +Metrics/MethodLength: + Max: 25 + +# Offense count: 1 +# Configuration parameters: MinSize. +Performance/CollectionLiteralInLoop: + Exclude: + - 'spec/acceptance/puppet/modulebuilder/builder_spec.rb' + +# Offense count: 4 +# Configuration parameters: Prefixes, AllowedPatterns. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'spec/acceptance/puppet/modulebuilder/builder_spec.rb' + - 'spec/unit/puppet/modulebuilder/builder_spec.rb' + +# Offense count: 2 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 11 + +# Offense count: 10 +# Configuration parameters: . +# SupportedStyles: have_received, receive +RSpec/MessageSpies: + EnforcedStyle: receive + +# Offense count: 6 +RSpec/MultipleExpectations: + Max: 11 + +# Offense count: 13 +# Configuration parameters: AllowSubject. +RSpec/MultipleMemoizedHelpers: + Max: 8 + +# Offense count: 8 +# Configuration parameters: EnforcedStyle, IgnoreSharedExamples. +# SupportedStyles: always, named_only +RSpec/NamedSubject: + Exclude: + - 'spec/unit/puppet/modulebuilder/builder_spec.rb' + +# Offense count: 3 +# Configuration parameters: AllowedGroups. +RSpec/NestedGroups: + Max: 5 + +# Offense count: 33 +RSpec/SubjectStub: + Exclude: + - 'spec/unit/puppet/modulebuilder/builder_spec.rb' + +# Offense count: 9 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 188 From 3e34dd01e934642360fbf807363029dc682d49a4 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 10:20:47 +0100 Subject: [PATCH 20/25] (CONT-881) Correct Style/IfUnlessModifier --- lib/puppet/modulebuilder/builder.rb | 4 +--- spec/acceptance/puppet/modulebuilder/builder_spec.rb | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/puppet/modulebuilder/builder.rb b/lib/puppet/modulebuilder/builder.rb index ebecc17..958d5e0 100644 --- a/lib/puppet/modulebuilder/builder.rb +++ b/lib/puppet/modulebuilder/builder.rb @@ -259,9 +259,7 @@ def ignored_files PathSpec.new(read_file(ignore_file, open_args: 'rb:UTF-8')) end - if File.realdirpath(destination).start_with?(File.realdirpath(source)) - ignored = ignored.add("/#{File.basename(destination)}/") - end + ignored = ignored.add("/#{File.basename(destination)}/") if File.realdirpath(destination).start_with?(File.realdirpath(source)) DEFAULT_IGNORED.each { |r| ignored.add(r) } diff --git a/spec/acceptance/puppet/modulebuilder/builder_spec.rb b/spec/acceptance/puppet/modulebuilder/builder_spec.rb index 9f8fa3d..aa59449 100644 --- a/spec/acceptance/puppet/modulebuilder/builder_spec.rb +++ b/spec/acceptance/puppet/modulebuilder/builder_spec.rb @@ -77,9 +77,7 @@ require 'open3' output, status = Open3.capture2e("puppet module install --force --ignore-dependencies --target-dir #{extract_path} --verbose #{built_tarball}") - unless status.exitstatus.zero? - raise "Failed to install the module using Puppet. Exit code #{status.exitstatus}: #{output}" - end + raise "Failed to install the module using Puppet. Exit code #{status.exitstatus}: #{output}" unless status.exitstatus.zero? raise 'Failed to install the module using Puppet. Missing extract directory' if extracted_module_path.nil? end From 74ec8226b473c1becacc2d136f88185e0d4ad45d Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 11:54:44 +0100 Subject: [PATCH 21/25] (CONT-881) Update fixtures --- .../puppet/modulebuilder/builder_spec.rb | 8 +- spec/fixtures/module/.devcontainer/Dockerfile | 6 + spec/fixtures/module/.devcontainer/README.md | 38 +++ .../module/.devcontainer/devcontainer.json | 17 ++ spec/fixtures/module/.fixtures.yml | 5 +- .../module/.github/workflows/auto_release.yml | 9 + spec/fixtures/module/.github/workflows/ci.yml | 17 ++ .../module/.github/workflows/labeller.yml | 22 ++ .../module/.github/workflows/mend.yml | 15 + .../module/.github/workflows/nightly.yml | 16 ++ .../module/.github/workflows/release.yml | 51 +--- .../module/.github/workflows/weekly.yml | 42 --- spec/fixtures/module/.gitignore | 1 + spec/fixtures/module/.gitpod.Dockerfile | 18 ++ spec/fixtures/module/.gitpod.yml | 9 + spec/fixtures/module/.pdkignore | 5 + spec/fixtures/module/.rubocop.yml | 87 ++++++ spec/fixtures/module/.rubocop_todo.yml | 28 +- spec/fixtures/module/.sync.yml | 69 ++--- spec/fixtures/module/.travis.yml | 154 ---------- spec/fixtures/module/CHANGELOG.md | 117 +++++++- spec/fixtures/module/CONTRIBUTING.md | 270 +----------------- spec/fixtures/module/Gemfile | 51 ++-- spec/fixtures/module/REFERENCE.md | 34 ++- spec/fixtures/module/Rakefile | 16 +- spec/fixtures/module/appveyor.yml | 84 ------ spec/fixtures/module/data/common.yaml | 1 + spec/fixtures/module/distelli-manifest.yml | 25 -- spec/fixtures/module/hiera.yaml | 21 ++ .../module/lib/this/is/a/nested/path/file.rb | 1 - spec/fixtures/module/locales/config.yaml | 26 -- .../module/locales/ja/puppetlabs-motd.po | 54 ---- .../module/locales/puppetlabs-motd.pot | 83 ------ spec/fixtures/module/manifests/init.pp | 35 ++- spec/fixtures/module/metadata.json | 53 ++-- spec/fixtures/module/pdk.yaml | 2 + spec/fixtures/module/provision.yaml | 91 ++++-- .../module/spec/acceptance/motd_spec.rb | 168 ++++++----- .../fixtures/module/spec/classes/motd_spec.rb | 243 ++++++++-------- spec/fixtures/module/spec/spec_helper.rb | 19 +- .../module/spec/spec_helper_acceptance.rb | 78 +---- spec/fixtures/module/templates/motd.epp | 8 +- 42 files changed, 877 insertions(+), 1220 deletions(-) create mode 100644 spec/fixtures/module/.devcontainer/Dockerfile create mode 100644 spec/fixtures/module/.devcontainer/README.md create mode 100644 spec/fixtures/module/.devcontainer/devcontainer.json create mode 100644 spec/fixtures/module/.github/workflows/auto_release.yml create mode 100644 spec/fixtures/module/.github/workflows/ci.yml create mode 100644 spec/fixtures/module/.github/workflows/labeller.yml create mode 100644 spec/fixtures/module/.github/workflows/mend.yml create mode 100644 spec/fixtures/module/.github/workflows/nightly.yml delete mode 100644 spec/fixtures/module/.github/workflows/weekly.yml create mode 100644 spec/fixtures/module/.gitpod.Dockerfile create mode 100644 spec/fixtures/module/.gitpod.yml create mode 100644 spec/fixtures/module/.rubocop.yml delete mode 100644 spec/fixtures/module/.travis.yml delete mode 100644 spec/fixtures/module/appveyor.yml create mode 100644 spec/fixtures/module/data/common.yaml delete mode 100644 spec/fixtures/module/distelli-manifest.yml create mode 100644 spec/fixtures/module/hiera.yaml delete mode 100644 spec/fixtures/module/lib/this/is/a/nested/path/file.rb delete mode 100644 spec/fixtures/module/locales/config.yaml delete mode 100644 spec/fixtures/module/locales/ja/puppetlabs-motd.po delete mode 100644 spec/fixtures/module/locales/puppetlabs-motd.pot create mode 100644 spec/fixtures/module/pdk.yaml diff --git a/spec/acceptance/puppet/modulebuilder/builder_spec.rb b/spec/acceptance/puppet/modulebuilder/builder_spec.rb index aa59449..a3ee483 100644 --- a/spec/acceptance/puppet/modulebuilder/builder_spec.rb +++ b/spec/acceptance/puppet/modulebuilder/builder_spec.rb @@ -39,11 +39,7 @@ context 'which is installed via Puppet' do let(:extract_path) { Dir.mktmpdir } - let(:extracted_module_path) do - File.join(extract_path, Dir.entries(extract_path).reject do |p| - %w[. ..].include?(p) - end.first) - end + let(:extracted_module_path) { File.join(extract_path, Dir.entries(extract_path).reject { |p| %w[. ..].include?(p) }.first) } RSpec::Matchers.define :be_an_empty_glob do match do |actual| @@ -75,7 +71,7 @@ # Use puppet to "install" it... require 'open3' - output, status = Open3.capture2e("puppet module install --force --ignore-dependencies --target-dir #{extract_path} --verbose #{built_tarball}") + output, status = Open3.capture2e("bundle exec puppet module install --force --ignore-dependencies --target-dir #{extract_path} --verbose #{built_tarball}") raise "Failed to install the module using Puppet. Exit code #{status.exitstatus}: #{output}" unless status.exitstatus.zero? raise 'Failed to install the module using Puppet. Missing extract directory' if extracted_module_path.nil? diff --git a/spec/fixtures/module/.devcontainer/Dockerfile b/spec/fixtures/module/.devcontainer/Dockerfile new file mode 100644 index 0000000..12ed4ff --- /dev/null +++ b/spec/fixtures/module/.devcontainer/Dockerfile @@ -0,0 +1,6 @@ +FROM puppet/pdk:latest + +# [Optional] Uncomment this section to install additional packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + diff --git a/spec/fixtures/module/.devcontainer/README.md b/spec/fixtures/module/.devcontainer/README.md new file mode 100644 index 0000000..a719361 --- /dev/null +++ b/spec/fixtures/module/.devcontainer/README.md @@ -0,0 +1,38 @@ +# devcontainer + + +For format details, see https://aka.ms/devcontainer.json. + +For config options, see the README at: +https://github.com/microsoft/vscode-dev-containers/tree/v0.140.1/containers/puppet + +``` json +{ + "name": "Puppet Development Kit (Community)", + "dockerFile": "Dockerfile", + + // Set *default* container specific settings.json values on container create. + "settings": { + "terminal.integrated.profiles.linux": { + "bash": { + "path": "bash", + } + } + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "puppet.puppet-vscode", + "rebornix.Ruby" + ], + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "pdk --version", +} +``` + + + diff --git a/spec/fixtures/module/.devcontainer/devcontainer.json b/spec/fixtures/module/.devcontainer/devcontainer.json new file mode 100644 index 0000000..cdd65d2 --- /dev/null +++ b/spec/fixtures/module/.devcontainer/devcontainer.json @@ -0,0 +1,17 @@ +{ + "name": "Puppet Development Kit (Community)", + "dockerFile": "Dockerfile", + + "settings": { + "terminal.integrated.profiles.linux": { + "bash": { + "path": "bash" + } + } + }, + + "extensions": [ + "puppet.puppet-vscode", + "rebornix.Ruby" + ] +} diff --git a/spec/fixtures/module/.fixtures.yml b/spec/fixtures/module/.fixtures.yml index d987080..332380a 100644 --- a/spec/fixtures/module/.fixtures.yml +++ b/spec/fixtures/module/.fixtures.yml @@ -2,9 +2,10 @@ fixtures: repositories: facts: 'https://github.com/puppetlabs/puppetlabs-facts.git' provision: 'https://github.com/puppetlabs/provision.git' - puppet_agent: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' + puppet_agent: + repo: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' + ref: v4.13.0 registry: 'https://github.com/puppetlabs/puppetlabs-registry.git' - translate: 'https://github.com/puppetlabs/puppetlabs-translate.git' stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' symlinks: motd: "#{source_dir}" diff --git a/spec/fixtures/module/.github/workflows/auto_release.yml b/spec/fixtures/module/.github/workflows/auto_release.yml new file mode 100644 index 0000000..d6270c5 --- /dev/null +++ b/spec/fixtures/module/.github/workflows/auto_release.yml @@ -0,0 +1,9 @@ +name: "Auto release" + +on: + workflow_dispatch: + +jobs: + release_prep: + uses: "puppetlabs/cat-github-actions/.github/workflows/module_release_prep.yml@main" + secrets: "inherit" diff --git a/spec/fixtures/module/.github/workflows/ci.yml b/spec/fixtures/module/.github/workflows/ci.yml new file mode 100644 index 0000000..a5738ad --- /dev/null +++ b/spec/fixtures/module/.github/workflows/ci.yml @@ -0,0 +1,17 @@ +name: "ci" + +on: + pull_request: + branches: + - "main" + workflow_dispatch: + +jobs: + Spec: + uses: "puppetlabs/cat-github-actions/.github/workflows/module_ci.yml@main" + secrets: "inherit" + + Acceptance: + needs: Spec + uses: "puppetlabs/cat-github-actions/.github/workflows/module_acceptance.yml@main" + secrets: "inherit" diff --git a/spec/fixtures/module/.github/workflows/labeller.yml b/spec/fixtures/module/.github/workflows/labeller.yml new file mode 100644 index 0000000..5434d3f --- /dev/null +++ b/spec/fixtures/module/.github/workflows/labeller.yml @@ -0,0 +1,22 @@ +name: community-labeller + +on: + issues: + types: + - opened + pull_request_target: + types: + - opened + +jobs: + label: + runs-on: ubuntu-latest + steps: + + - uses: puppetlabs/community-labeller@v0 + name: Label issues or pull requests + with: + label_name: community + label_color: '5319e7' + org_membership: puppetlabs + token: ${{ secrets.IAC_COMMUNITY_LABELER }} diff --git a/spec/fixtures/module/.github/workflows/mend.yml b/spec/fixtures/module/.github/workflows/mend.yml new file mode 100644 index 0000000..b4100a5 --- /dev/null +++ b/spec/fixtures/module/.github/workflows/mend.yml @@ -0,0 +1,15 @@ +name: "mend" + +on: + pull_request: + branches: + - "main" + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +jobs: + + mend: + uses: "puppetlabs/cat-github-actions/.github/workflows/mend_ruby.yml@main" + secrets: "inherit" diff --git a/spec/fixtures/module/.github/workflows/nightly.yml b/spec/fixtures/module/.github/workflows/nightly.yml new file mode 100644 index 0000000..1b06c47 --- /dev/null +++ b/spec/fixtures/module/.github/workflows/nightly.yml @@ -0,0 +1,16 @@ +name: "nightly" + +on: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +jobs: + Spec: + uses: "puppetlabs/cat-github-actions/.github/workflows/module_ci.yml@main" + secrets: "inherit" + + Acceptance: + needs: Spec + uses: "puppetlabs/cat-github-actions/.github/workflows/module_acceptance.yml@main" + secrets: "inherit" diff --git a/spec/fixtures/module/.github/workflows/release.yml b/spec/fixtures/module/.github/workflows/release.yml index 50993b0..0b7b8a0 100644 --- a/spec/fixtures/module/.github/workflows/release.yml +++ b/spec/fixtures/module/.github/workflows/release.yml @@ -1,46 +1,9 @@ -name: "release" - -on: - push: - branches: - - 'release' +name: "Publish module" +on: + workflow_dispatch: + jobs: - LitmusAcceptance: - env: - HONEYCOMB_WRITEKEY: 7f3c63a70eecc61d635917de46bea4e6 - HONEYCOMB_DATASET: litmus tests - runs-on: self-hosted - strategy: - matrix: - ruby_version: [2.5.x] - puppet_gem_version: [~> 6.0] - platform: [release_checks] - agent_family: ['puppet5', 'puppet6'] - - steps: - - uses: actions/checkout@v1 - - name: Litmus Parallel - uses: puppetlabs/action-litmus_parallel@main - with: - platform: ${{ matrix.platform }} - agent_family: ${{ matrix.agent_family }} - Spec: - runs-on: self-hosted - strategy: - matrix: - check: [parallel_spec, 'syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop'] - ruby_version: [2.5.x] - puppet_gem_version: [~> 5.0, ~> 6.0] - exclude: - - puppet_gem_version: ~> 5.0 - check: 'syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop' - - ruby_version: 2.5.x - puppet_gem_version: ~> 5.0 - steps: - - uses: actions/checkout@v1 - - name: Spec Tests - uses: puppetlabs/action-litmus_spec@main - with: - puppet_gem_version: ${{ matrix.puppet_gem_version }} - check: ${{ matrix.check }} + release: + uses: "puppetlabs/cat-github-actions/.github/workflows/module_release.yml@main" + secrets: "inherit" diff --git a/spec/fixtures/module/.github/workflows/weekly.yml b/spec/fixtures/module/.github/workflows/weekly.yml deleted file mode 100644 index d9ffdba..0000000 --- a/spec/fixtures/module/.github/workflows/weekly.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: "weekly" - -on: - schedule: - - cron: '0 0 * * 6' - -jobs: - LitmusAcceptance: - runs-on: self-hosted - strategy: - matrix: - ruby_version: [2.5.x] - puppet_gem_version: [~> 6.0] - platform: [release_checks] - agent_family: ['puppet5', 'puppet6'] - - steps: - - uses: actions/checkout@v1 - - name: Litmus Parallel - uses: puppetlabs/action-litmus_parallel@main - with: - platform: ${{ matrix.platform }} - agent_family: ${{ matrix.agent_family }} - Spec: - runs-on: self-hosted - strategy: - matrix: - check: [spec, 'syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop'] - ruby_version: [2.5.x] - puppet_gem_version: [~> 5.0, ~> 6.0] - exclude: - - puppet_gem_version: ~> 5.0 - check: 'syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop' - - ruby_version: 2.5.x - puppet_gem_version: ~> 5.0 - steps: - - uses: actions/checkout@v1 - - name: Spec Tests - uses: puppetlabs/action-litmus_spec@main - with: - puppet_gem_version: ${{ matrix.puppet_gem_version }} - check: ${{ matrix.check }} diff --git a/spec/fixtures/module/.gitignore b/spec/fixtures/module/.gitignore index 2767022..988dcbb 100644 --- a/spec/fixtures/module/.gitignore +++ b/spec/fixtures/module/.gitignore @@ -25,3 +25,4 @@ .project .envrc /inventory.yaml +/spec/fixtures/litmus_inventory.yaml diff --git a/spec/fixtures/module/.gitpod.Dockerfile b/spec/fixtures/module/.gitpod.Dockerfile new file mode 100644 index 0000000..0814c5e --- /dev/null +++ b/spec/fixtures/module/.gitpod.Dockerfile @@ -0,0 +1,18 @@ +FROM gitpod/workspace-full +RUN sudo wget https://apt.puppet.com/puppet-tools-release-bionic.deb && \ + wget https://apt.puppetlabs.com/puppet6-release-bionic.deb && \ + sudo dpkg -i puppet6-release-bionic.deb && \ + sudo dpkg -i puppet-tools-release-bionic.deb && \ + sudo apt-get update && \ + sudo apt-get install -y pdk zsh puppet-agent && \ + sudo apt-get clean && \ + sudo rm -rf /var/lib/apt/lists/* +RUN sudo usermod -s $(which zsh) gitpod && \ + sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" && \ + echo "plugins=(git gitignore github gem pip bundler python ruby docker docker-compose)" >> /home/gitpod/.zshrc && \ + echo 'PATH="$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/puppetlabs/bin:/opt/puppetlabs/puppet/bin"' >> /home/gitpod/.zshrc && \ + sudo /opt/puppetlabs/puppet/bin/gem install puppet-debugger hub -N && \ + mkdir -p /home/gitpod/.config/puppet && \ + /opt/puppetlabs/puppet/bin/ruby -r yaml -e "puts ({'disabled' => true}).to_yaml" > /home/gitpod/.config/puppet/analytics.yml +RUN rm -f puppet6-release-bionic.deb puppet-tools-release-bionic.deb +ENTRYPOINT /usr/bin/zsh diff --git a/spec/fixtures/module/.gitpod.yml b/spec/fixtures/module/.gitpod.yml new file mode 100644 index 0000000..9d89d9f --- /dev/null +++ b/spec/fixtures/module/.gitpod.yml @@ -0,0 +1,9 @@ +image: + file: .gitpod.Dockerfile + +tasks: + - init: pdk bundle install + +vscode: + extensions: + - puppet.puppet-vscode@1.2.0:f5iEPbmOj6FoFTOV6q8LTg== diff --git a/spec/fixtures/module/.pdkignore b/spec/fixtures/module/.pdkignore index e6215cd..c538bea 100644 --- a/spec/fixtures/module/.pdkignore +++ b/spec/fixtures/module/.pdkignore @@ -25,13 +25,16 @@ .project .envrc /inventory.yaml +/spec/fixtures/litmus_inventory.yaml /appveyor.yml +/.editorconfig /.fixtures.yml /Gemfile /.gitattributes /.gitignore /.gitlab-ci.yml /.pdkignore +/.puppet-lint.rc /Rakefile /rakelib/ /.rspec @@ -40,3 +43,5 @@ /.yardopts /spec/ /.vscode/ +/.sync.yml +/.devcontainer/ diff --git a/spec/fixtures/module/.rubocop.yml b/spec/fixtures/module/.rubocop.yml new file mode 100644 index 0000000..2367276 --- /dev/null +++ b/spec/fixtures/module/.rubocop.yml @@ -0,0 +1,87 @@ +--- +require: +- rubocop-performance +- rubocop-rspec +AllCops: + NewCops: enable + DisplayCopNames: true + ExtraDetails: true + DisplayStyleGuide: true + TargetRubyVersion: '2.7' + Include: + - "**/*.rb" + Exclude: + - bin/* + - ".vendor/**/*" + - "**/Gemfile" + - "**/Rakefile" + - pkg/**/* + - spec/fixtures/**/* + - vendor/**/* + - "**/Puppetfile" + - "**/Vagrantfile" + - "**/Guardfile" +Layout/LineLength: + Description: People have wide screens, use them. + Max: 200 +RSpec/BeforeAfterAll: + Description: Beware of using after(:all) as it may cause state to leak between tests. + A necessary evil in acceptance testing. + Exclude: + - spec/acceptance/**/*.rb +RSpec/HookArgument: + Description: Prefer explicit :each argument, matching existing module's style + EnforcedStyle: each +RSpec/DescribeSymbol: + Exclude: + - spec/unit/facter/**/*.rb +Style/BlockDelimiters: + Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to + be consistent then. + EnforcedStyle: braces_for_chaining +Style/ClassAndModuleChildren: + Description: Compact style reduces the required amount of indentation. + EnforcedStyle: compact +Style/EmptyElse: + Description: Enforce against empty else clauses, but allow `nil` for clarity. + EnforcedStyle: empty +Style/FormatString: + Description: Following the main puppet project's style, prefer the % format format. + EnforcedStyle: percent +Style/FormatStringToken: + Description: Following the main puppet project's style, prefer the simpler template + tokens over annotated ones. + EnforcedStyle: template +Style/Lambda: + Description: Prefer the keyword for easier discoverability. + EnforcedStyle: literal +Style/RegexpLiteral: + Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 + EnforcedStyle: percent_r +Style/TernaryParentheses: + Description: Checks for use of parentheses around ternary conditions. Enforce parentheses + on complex expressions for better readability, but seriously consider breaking + it up. + EnforcedStyle: require_parentheses_when_complex +Style/TrailingCommaInArguments: + Description: Prefer always trailing comma on multiline argument lists. This makes + diffs, and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/TrailingCommaInArrayLiteral: + Description: Prefer always trailing comma on multiline literals. This makes diffs, + and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/SymbolArray: + Description: Using percent style obscures symbolic intent of array's contents. + EnforcedStyle: brackets +inherit_from: ".rubocop_todo.yml" +RSpec/MessageSpies: + EnforcedStyle: receive +Style/Documentation: + Exclude: + - lib/puppet/parser/functions/**/* + - spec/**/* +Style/WordArray: + EnforcedStyle: brackets +RSpec/MultipleExpectations: + Max: 3 diff --git a/spec/fixtures/module/.rubocop_todo.yml b/spec/fixtures/module/.rubocop_todo.yml index 23d36fa..9823868 100644 --- a/spec/fixtures/module/.rubocop_todo.yml +++ b/spec/fixtures/module/.rubocop_todo.yml @@ -1,2 +1,26 @@ -GetText/DecorateString: - Enabled: false \ No newline at end of file +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-04-04 14:55:26 UTC using RuboCop version 1.48.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 2 +# Configuration parameters: IgnoredMetadata. +RSpec/DescribeClass: + Exclude: + - '**/spec/features/**/*' + - '**/spec/requests/**/*' + - '**/spec/routing/**/*' + - '**/spec/system/**/*' + - '**/spec/views/**/*' + - 'spec/acceptance/motd_spec.rb' + - 'spec/classes/motd_spec.rb' + +# Offense count: 21 +# Configuration parameters: EnforcedStyle, IgnoreSharedExamples. +# SupportedStyles: always, named_only +RSpec/NamedSubject: + Exclude: + - 'spec/classes/motd_spec.rb' diff --git a/spec/fixtures/module/.sync.yml b/spec/fixtures/module/.sync.yml index 5a848d3..3e567e6 100644 --- a/spec/fixtures/module/.sync.yml +++ b/spec/fixtures/module/.sync.yml @@ -1,60 +1,31 @@ --- +common: + service_url: https://facade-main-6f3kfepqcq-ew.a.run.app/v1/provision + ".gitlab-ci.yml": delete: true -".rubocop.yml": - default_configs: - inherit_from: ".rubocop_todo.yml" - require: - - rubocop-i18n - - rubocop-rspec -".travis.yml": - global_env: - - HONEYCOMB_WRITEKEY="7f3c63a70eecc61d635917de46bea4e6",HONEYCOMB_DATASET="litmus tests" - dist: trusty - deploy_to_forge: - enabled: false - branches: - - release - user: puppet - secure: '' - use_litmus: true - litmus: - provision_list: - - travis_deb - - travis_ub - - travis_el6 - - travis_el7 - - ---travis_el - simplecov: true - notifications: - slack: - secure: kWN4IvjB5scKS6a00jGLVgn2l0wZz6o+DC4ZyZNCxrf4LlihySJyneboPNQb6nthPwVCFh72sBxjT45Ue2JZO30dKiT7eOXGo/N2EK6NpORXEDtuIKBfuZ8ZQ+bos9hVXHmxzujnunQZemLwodDKcwEWMIEjT3QeV5NQUukOHYM= appveyor.yml: - environment: - HONEYCOMB_WRITEKEY: 7f3c63a70eecc61d635917de46bea4e6 - HONEYCOMB_DATASET: litmus tests - use_litmus: true - matrix_extras: - - RUBY_VERSION: 25-x64 - ACCEPTANCE: 'yes' - TARGET_HOST: localhost - - RUBY_VERSION: 25-x64 - ACCEPTANCE: 'yes' - TARGET_HOST: localhost - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - simplecov: true + delete: true + Gemfile: - use_litmus: true optional: ":development": - - gem: puppet-lint-i18n - gem: github_changelog_generator - git: https://github.com/skywinder/github-changelog-generator - ref: 20ee04ba1234e9e83eb2ffb5056e23d641c7a018 - condition: Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') -Rakefile: - requires: - - puppet_pot_generator/rake_tasks + version: '= 1.15.2' spec/spec_helper.rb: mock_with: ":rspec" coverage_report: true +.gitpod.Dockerfile: + unmanaged: false +.gitpod.yml: + unmanaged: false +.github/workflows/auto_release.yml: + unmanaged: false +.github/workflows/ci.yml: + unmanaged: false +.github/workflows/nightly.yml: + unmanaged: false +.github/workflows/release.yml: + unmanaged: false +.travis.yml: + delete: true diff --git a/spec/fixtures/module/.travis.yml b/spec/fixtures/module/.travis.yml deleted file mode 100644 index 61c28c9..0000000 --- a/spec/fixtures/module/.travis.yml +++ /dev/null @@ -1,154 +0,0 @@ ---- -os: linux -dist: trusty -language: ruby -cache: bundler -before_install: - - bundle -v - - rm -f Gemfile.lock - - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" - - "# See https://github.com/puppetlabs/pdk-templates/commit/705154d5c437796b821691b707156e1b056d244f for an example of how this was used" - - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" - - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' - - gem --version - - bundle -v -script: - - 'SIMPLECOV=yes bundle exec rake $CHECK' -bundler_args: --without system_tests -rvm: - - 2.5.3 -env: - global: - - HONEYCOMB_WRITEKEY="7f3c63a70eecc61d635917de46bea4e6",HONEYCOMB_DATASET="litmus tests" -stages: - - static - - spec - - acceptance -jobs: - fast_finish: true - include: - - - before_script: - - "bundle exec rake 'litmus:provision_list[travis_deb]'" - - "bundle exec rake 'litmus:install_agent[puppet5]'" - - "bundle exec rake litmus:install_module" - bundler_args: - dist: trusty - env: PLATFORMS=travis_deb_puppet5 - rvm: 2.5.3 - script: ["bundle exec rake litmus:acceptance:parallel"] - services: docker - stage: acceptance - - - before_script: - - "bundle exec rake 'litmus:provision_list[travis_ub]'" - - "bundle exec rake 'litmus:install_agent[puppet5]'" - - "bundle exec rake litmus:install_module" - bundler_args: - dist: trusty - env: PLATFORMS=travis_ub_puppet5 - rvm: 2.5.3 - script: ["bundle exec rake litmus:acceptance:parallel"] - services: docker - stage: acceptance - - - before_script: - - "bundle exec rake 'litmus:provision_list[travis_el6]'" - - "bundle exec rake 'litmus:install_agent[puppet5]'" - - "bundle exec rake litmus:install_module" - bundler_args: - dist: trusty - env: PLATFORMS=travis_el6_puppet5 - rvm: 2.5.3 - script: ["bundle exec rake litmus:acceptance:parallel"] - services: docker - stage: acceptance - - - before_script: - - "bundle exec rake 'litmus:provision_list[travis_el7]'" - - "bundle exec rake 'litmus:install_agent[puppet5]'" - - "bundle exec rake litmus:install_module" - bundler_args: - dist: trusty - env: PLATFORMS=travis_el7_puppet5 - rvm: 2.5.3 - script: ["bundle exec rake litmus:acceptance:parallel"] - services: docker - stage: acceptance - - - before_script: - - "bundle exec rake 'litmus:provision_list[travis_deb]'" - - "bundle exec rake 'litmus:install_agent[puppet6]'" - - "bundle exec rake litmus:install_module" - bundler_args: - dist: trusty - env: PLATFORMS=travis_deb_puppet6 - rvm: 2.5.3 - script: ["bundle exec rake litmus:acceptance:parallel"] - services: docker - stage: acceptance - - - before_script: - - "bundle exec rake 'litmus:provision_list[travis_ub]'" - - "bundle exec rake 'litmus:install_agent[puppet6]'" - - "bundle exec rake litmus:install_module" - bundler_args: - dist: trusty - env: PLATFORMS=travis_ub_puppet6 - rvm: 2.5.3 - script: ["bundle exec rake litmus:acceptance:parallel"] - services: docker - stage: acceptance - - - before_script: - - "bundle exec rake 'litmus:provision_list[travis_el6]'" - - "bundle exec rake 'litmus:install_agent[puppet6]'" - - "bundle exec rake litmus:install_module" - bundler_args: - dist: trusty - env: PLATFORMS=travis_el6_puppet6 - rvm: 2.5.3 - script: ["bundle exec rake litmus:acceptance:parallel"] - services: docker - stage: acceptance - - - before_script: - - "bundle exec rake 'litmus:provision_list[travis_el7]'" - - "bundle exec rake 'litmus:install_agent[puppet6]'" - - "bundle exec rake litmus:install_module" - bundler_args: - dist: trusty - env: PLATFORMS=travis_el7_puppet6 - rvm: 2.5.3 - script: ["bundle exec rake litmus:acceptance:parallel"] - services: docker - stage: acceptance - - - env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" - stage: static - - - env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec - rvm: 2.4.5 - stage: spec - - - env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec - rvm: 2.5.3 - stage: spec -branches: - only: - - main - - /^v\d/ - - release -notifications: - email: false - slack: - secure: kWN4IvjB5scKS6a00jGLVgn2l0wZz6o+DC4ZyZNCxrf4LlihySJyneboPNQb6nthPwVCFh72sBxjT45Ue2JZO30dKiT7eOXGo/N2EK6NpORXEDtuIKBfuZ8ZQ+bos9hVXHmxzujnunQZemLwodDKcwEWMIEjT3QeV5NQUukOHYM= -deploy: - provider: puppetforge - username: puppet - password: - secure: "" - on: - tags: true - all_branches: true - condition: "$DEPLOY_TO_FORGE = yes" diff --git a/spec/fixtures/module/CHANGELOG.md b/spec/fixtures/module/CHANGELOG.md index 625b53b..b49ff08 100644 --- a/spec/fixtures/module/CHANGELOG.md +++ b/spec/fixtures/module/CHANGELOG.md @@ -2,16 +2,127 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org). +## [v7.0.0](https://github.com/puppetlabs/puppetlabs-motd/tree/v7.0.0) (2023-04-05) + +[Full Changelog](https://github.com/puppetlabs/puppetlabs-motd/compare/v6.3.0...v7.0.0) + +### Changed + +- \(Cont 787\) Add Support for Puppet 8 / Drop Support for Puppet 6 [\#472](https://github.com/puppetlabs/puppetlabs-motd/pull/472) ([david22swan](https://github.com/david22swan)) + +### Fixed + +- pdksync - \(CONT-189\) Remove support for RedHat6 / OracleLinux6 / Scientific6 [\#456](https://github.com/puppetlabs/puppetlabs-motd/pull/456) ([david22swan](https://github.com/david22swan)) +- pdksync - \(CONT-130\) - Dropping Support for Debian 9 [\#450](https://github.com/puppetlabs/puppetlabs-motd/pull/450) ([jordanbreen28](https://github.com/jordanbreen28)) + +## [v6.3.0](https://github.com/puppetlabs/puppetlabs-motd/tree/v6.3.0) (2022-10-03) + +[Full Changelog](https://github.com/puppetlabs/puppetlabs-motd/compare/v6.2.0...v6.3.0) + +### Added + +- pdksync - \(GH-cat-11\) Certify Support for Ubuntu 22.04 [\#447](https://github.com/puppetlabs/puppetlabs-motd/pull/447) ([david22swan](https://github.com/david22swan)) +- pdksync - \(GH-cat-12\) Add Support for Redhat 9 [\#446](https://github.com/puppetlabs/puppetlabs-motd/pull/446) ([david22swan](https://github.com/david22swan)) + +### Fixed + +- \(MAINT\) Dropped support for Windows Server 2008 R2 and FreeBSD [\#448](https://github.com/puppetlabs/puppetlabs-motd/pull/448) ([jordanbreen28](https://github.com/jordanbreen28)) + +## [v6.2.0](https://github.com/puppetlabs/puppetlabs-motd/tree/v6.2.0) (2022-05-30) + +[Full Changelog](https://github.com/puppetlabs/puppetlabs-motd/compare/v6.1.0...v6.2.0) + +### Added + +- Update motd location for FreeBSD 13 and above [\#431](https://github.com/puppetlabs/puppetlabs-motd/pull/431) ([Scnaeg](https://github.com/Scnaeg)) +- pdksync - \(IAC-1753\) - Add Support for AlmaLinux 8 [\#428](https://github.com/puppetlabs/puppetlabs-motd/pull/428) ([david22swan](https://github.com/david22swan)) + +### Fixed + +- pdksync - \(GH-iac-334\) Remove Support for Ubuntu 16.04 [\#433](https://github.com/puppetlabs/puppetlabs-motd/pull/433) ([david22swan](https://github.com/david22swan)) +- pdksync - \(IAC-1787\) Remove Support for CentOS 6 [\#430](https://github.com/puppetlabs/puppetlabs-motd/pull/430) ([david22swan](https://github.com/david22swan)) +- pdksync - \(IAC-1598\) - Remove Support for Debian 8 [\#426](https://github.com/puppetlabs/puppetlabs-motd/pull/426) ([david22swan](https://github.com/david22swan)) + +## [v6.1.0](https://github.com/puppetlabs/puppetlabs-motd/tree/v6.1.0) (2021-08-26) + +[Full Changelog](https://github.com/puppetlabs/puppetlabs-motd/compare/v6.0.0...v6.1.0) + +### Added + +- pdksync - \(IAC-1751\) - Add Support for Rocky 8 [\#427](https://github.com/puppetlabs/puppetlabs-motd/pull/427) ([david22swan](https://github.com/david22swan)) +- pdksync - \(IAC-1709\) - Add Support for Debian 11 [\#420](https://github.com/puppetlabs/puppetlabs-motd/pull/420) ([david22swan](https://github.com/david22swan)) + +### Fixed + +- \(IAC-1741\) Allow stdlib v8.0.0 [\#421](https://github.com/puppetlabs/puppetlabs-motd/pull/421) ([david22swan](https://github.com/david22swan)) + +## [v6.0.0](https://github.com/puppetlabs/puppetlabs-motd/tree/v6.0.0) (2021-05-10) + +[Full Changelog](https://github.com/puppetlabs/puppetlabs-motd/compare/v5.0.0...v6.0.0) + +### Changed + +- Update metadata.json - remove ubuntu 14.04 [\#401](https://github.com/puppetlabs/puppetlabs-motd/pull/401) ([daianamezdrea](https://github.com/daianamezdrea)) + +### Fixed + +- \(IAC-1497\) - Removal of unsupported `translate` dependency [\#404](https://github.com/puppetlabs/puppetlabs-motd/pull/404) ([david22swan](https://github.com/david22swan)) + +## [v5.0.0](https://github.com/puppetlabs/puppetlabs-motd/tree/v5.0.0) (2021-03-01) + +[Full Changelog](https://github.com/puppetlabs/puppetlabs-motd/compare/v4.3.0...v5.0.0) + +### Changed + +- pdksync - Remove SLES 11 support [\#399](https://github.com/puppetlabs/puppetlabs-motd/pull/399) ([sanfrancrisko](https://github.com/sanfrancrisko)) +- pdksync - Remove RHEL 5 family support [\#398](https://github.com/puppetlabs/puppetlabs-motd/pull/398) ([sanfrancrisko](https://github.com/sanfrancrisko)) +- pdksync - Remove Puppet 5 from testing and bump minimal version to 6.0.0 [\#394](https://github.com/puppetlabs/puppetlabs-motd/pull/394) ([carabasdaniel](https://github.com/carabasdaniel)) + +## [v4.3.0](https://github.com/puppetlabs/puppetlabs-motd/tree/v4.3.0) (2020-12-14) + +[Full Changelog](https://github.com/puppetlabs/puppetlabs-motd/compare/v4.2.0...v4.3.0) + +### Added + +- pdksync - \(feat\) - Add support for Puppet 7 [\#369](https://github.com/puppetlabs/puppetlabs-motd/pull/369) ([daianamezdrea](https://github.com/daianamezdrea)) + +## [v4.2.0](https://github.com/puppetlabs/puppetlabs-motd/tree/v4.2.0) (2020-08-20) + +[Full Changelog](https://github.com/puppetlabs/puppetlabs-motd/compare/v4.1.1...v4.2.0) + +### Added + +- \(IAC-974\) - Removal of inappropriate terminology [\#326](https://github.com/puppetlabs/puppetlabs-motd/pull/326) ([david22swan](https://github.com/david22swan)) +- pdksync - \(IAC-973\) - Update travis/appveyor to run on new default branch main [\#320](https://github.com/puppetlabs/puppetlabs-motd/pull/320) ([david22swan](https://github.com/david22swan)) +- \(IAC-746\) - Add ubuntu 20.04 support [\#309](https://github.com/puppetlabs/puppetlabs-motd/pull/309) ([david22swan](https://github.com/david22swan)) + +### UNCATEGORIZED PRS; LABEL THEM ON GITHUB + +- Update json requirement from 2.3.0 to 2.3.1 [\#316](https://github.com/puppetlabs/puppetlabs-motd/pull/316) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview)) +- Update json requirement from = 2.1.0 to 2.3.0 [\#306](https://github.com/puppetlabs/puppetlabs-motd/pull/306) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview)) +- Bump github\_changelog\_generator from 20ee04ba1234e9e83eb2ffb5056e23d641c7a018 to 1.15.2 [\#305](https://github.com/puppetlabs/puppetlabs-motd/pull/305) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview)) + +## [v4.1.1](https://github.com/puppetlabs/puppetlabs-motd/tree/v4.1.1) (2020-05-19) + +[Full Changelog](https://github.com/puppetlabs/puppetlabs-motd/compare/v4.1.0...v4.1.1) + +### Fixed + +- \(MAINT\) Ensure FreeBSD compatibility [\#271](https://github.com/puppetlabs/puppetlabs-motd/pull/271) ([dandrzejewski](https://github.com/dandrzejewski)) + ## [v4.1.0](https://github.com/puppetlabs/puppetlabs-motd/tree/v4.1.0) (2020-01-20) [Full Changelog](https://github.com/puppetlabs/puppetlabs-motd/compare/v4.0.0...v4.1.0) ### Added -- pdksync - \(FM-8581\) - Debian 10 added to travis and provision file refactored [\#277](https://github.com/puppetlabs/puppetlabs-motd/pull/277) ([david22swan](https://github.com/david22swan)) -- pdksync - "MODULES-10242 Add ubuntu14 support back to the modules" [\#267](https://github.com/puppetlabs/puppetlabs-motd/pull/267) ([sheenaajay](https://github.com/sheenaajay)) +- \(MODULES-10242\) Add back support for Ubuntu 14.04 [\#267](https://github.com/puppetlabs/puppetlabs-motd/pull/267) ([sheenaajay](https://github.com/sheenaajay)) - \(FM-8691\) - Addition of Support for CentOS 8 [\#264](https://github.com/puppetlabs/puppetlabs-motd/pull/264) ([david22swan](https://github.com/david22swan)) +### Fixed + +- \(MODULES-10387\) Raise lower bound for puppetlabs-registry dependency to 4.0.0 [\#276](https://github.com/puppetlabs/puppetlabs-motd/pull/276) ([daianamezdrea](https://github.com/daianamezdrea)) + ## [v4.0.0](https://github.com/puppetlabs/puppetlabs-motd/tree/v4.0.0) (2019-11-11) [Full Changelog](https://github.com/puppetlabs/puppetlabs-motd/compare/v3.1.0...v4.0.0) @@ -204,4 +315,4 @@ It also includes documentation and testing improvements. ####Known Bugs -\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* +\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* diff --git a/spec/fixtures/module/CONTRIBUTING.md b/spec/fixtures/module/CONTRIBUTING.md index 9c171f9..e7a3a7c 100644 --- a/spec/fixtures/module/CONTRIBUTING.md +++ b/spec/fixtures/module/CONTRIBUTING.md @@ -1,271 +1,3 @@ # Contributing to Puppet modules -So you want to contribute to a Puppet module: Great! Below are some instructions to get you started doing -that very thing while setting expectations around code quality as well as a few tips for making the -process as easy as possible. - -### Table of Contents - -1. [Getting Started](#getting-started) -1. [Commit Checklist](#commit-checklist) -1. [Submission](#submission) -1. [More about commits](#more-about-commits) -1. [Testing](#testing) - - [Running Tests](#running-tests) - - [Writing Tests](#writing-tests) -1. [Get Help](#get-help) - -## Getting Started - -- Fork the module repository on GitHub and clone to your workspace - -- Make your changes! - -## Commit Checklist - -### The Basics - -- [x] my commit is a single logical unit of work - -- [x] I have checked for unnecessary whitespace with "git diff --check" - -- [x] my commit does not include commented out code or unneeded files - -### The Content - -- [x] my commit includes tests for the bug I fixed or feature I added - -- [x] my commit includes appropriate documentation changes if it is introducing a new feature or changing existing functionality - -- [x] my code passes existing test suites - -### The Commit Message - -- [x] the first line of my commit message includes: - - - [x] an issue number (if applicable), e.g. "(MODULES-xxxx) This is the first line" - - - [x] a short description (50 characters is the soft limit, excluding ticket number(s)) - -- [x] the body of my commit message: - - - [x] is meaningful - - - [x] uses the imperative, present tense: "change", not "changed" or "changes" - - - [x] includes motivation for the change, and contrasts its implementation with the previous behavior - -## Submission - -### Pre-requisites - -- Make sure you have a [GitHub account](https://github.com/join) - -- [Create a ticket](https://tickets.puppet.com/secure/CreateIssue!default.jspa), or [watch the ticket](https://tickets.puppet.com/browse/) you are patching for. - -### Push and PR - -- Push your changes to your fork - -- [Open a Pull Request](https://help.github.com/articles/creating-a-pull-request-from-a-fork/) against the repository in the puppetlabs organization - -## More about commits - - 1. Make separate commits for logically separate changes. - - Please break your commits down into logically consistent units - which include new or changed tests relevant to the rest of the - change. The goal of doing this is to make the diff easier to - read for whoever is reviewing your code. In general, the easier - your diff is to read, the more likely someone will be happy to - review it and get it into the code base. - - If you are going to refactor a piece of code, please do so as a - separate commit from your feature or bug fix changes. - - We also really appreciate changes that include tests to make - sure the bug is not re-introduced, and that the feature is not - accidentally broken. - - Describe the technical detail of the change(s). If your - description starts to get too long, that is a good sign that you - probably need to split up your commit into more finely grained - pieces. - - Commits which plainly describe the things which help - reviewers check the patch and future developers understand the - code are much more likely to be merged in with a minimum of - bike-shedding or requested changes. Ideally, the commit message - would include information, and be in a form suitable for - inclusion in the release notes for the version of Puppet that - includes them. - - Please also check that you are not introducing any trailing - whitespace or other "whitespace errors". You can do this by - running "git diff --check" on your changes before you commit. - - 2. Sending your patches - - To submit your changes via a GitHub pull request, we _highly_ - recommend that you have them on a topic branch, instead of - directly on "main". - It makes things much easier to keep track of, especially if - you decide to work on another thing before your first change - is merged in. - - GitHub has some pretty good - [general documentation](http://help.github.com/) on using - their site. They also have documentation on - [creating pull requests](https://help.github.com/articles/creating-a-pull-request-from-a-fork/). - - In general, after pushing your topic branch up to your - repository on GitHub, you can switch to the branch in the - GitHub UI and click "Pull Request" towards the top of the page - in order to open a pull request. - - 3. Update the related JIRA issue. - - If there is a JIRA issue associated with the change you - submitted, then you should update the ticket to include the - location of your branch, along with any other commentary you - may wish to make. - -# Testing - -## Getting Started - -Our Puppet modules provide [`Gemfile`](./Gemfile)s, which can tell a Ruby package manager such as [bundler](http://bundler.io/) what Ruby packages, -or Gems, are required to build, develop, and test this software. - -Please make sure you have [bundler installed](http://bundler.io/#getting-started) on your system, and then use it to -install all dependencies needed for this project in the project root by running - -```shell -% bundle install --path .bundle/gems -Fetching gem metadata from https://rubygems.org/........ -Fetching gem metadata from https://rubygems.org/.. -Using rake (10.1.0) -Using builder (3.2.2) --- 8><-- many more --><8 -- -Using rspec-system-puppet (2.2.0) -Using serverspec (0.6.3) -Using rspec-system-serverspec (1.0.0) -Using bundler (1.3.5) -Your bundle is complete! -Use `bundle show [gemname]` to see where a bundled gem is installed. -``` - -NOTE: some systems may require you to run this command with sudo. - -If you already have those gems installed, make sure they are up-to-date: - -```shell -% bundle update -``` - -## Running Tests - -With all dependencies in place and up-to-date, run the tests: - -### Unit Tests - -```shell -% bundle exec rake spec -``` - -This executes all the [rspec tests](http://rspec-puppet.com/) in the directories defined [here](https://github.com/puppetlabs/puppetlabs_spec_helper/blob/699d9fbca1d2489bff1736bb254bb7b7edb32c74/lib/puppetlabs_spec_helper/rake_tasks.rb#L17) and so on. -rspec tests may have the same kind of dependencies as the module they are testing. Although the module defines these dependencies in its [metadata.json](./metadata.json), -rspec tests define them in [.fixtures.yml](./fixtures.yml). - -### Acceptance Tests - -Some Puppet modules also come with acceptance tests, which use [beaker][]. These tests spin up a virtual machine under -[VirtualBox](https://www.virtualbox.org/), controlled with [Vagrant](http://www.vagrantup.com/), to simulate scripted test -scenarios. In order to run these, you need both Virtualbox and Vagrant installed on your system. - -Run the tests by issuing the following command - -```shell -% bundle exec rake spec_clean -% bundle exec rspec spec/acceptance -``` - -This will now download a pre-fabricated image configured in the [default node-set](./spec/acceptance/nodesets/default.yml), -install Puppet, copy this module, and install its dependencies per [spec/spec_helper_acceptance.rb](./spec/spec_helper_acceptance.rb) -and then run all the tests under [spec/acceptance](./spec/acceptance). - -## Writing Tests - -### Unit Tests - -When writing unit tests for Puppet, [rspec-puppet][] is your best friend. It provides tons of helper methods for testing your manifests against a -catalog (e.g. contain_file, contain_package, with_params, etc). It would be ridiculous to try and top rspec-puppet's [documentation][rspec-puppet_docs] -but here's a tiny sample: - -Sample manifest: - -```puppet -file { "a test file": - ensure => present, - path => "/etc/sample", -} -``` - -Sample test: - -```ruby -it 'does a thing' do - expect(subject).to contain_file("a test file").with({:path => "/etc/sample"}) -end -``` - -### Acceptance Tests - -Writing acceptance tests for Puppet involves [beaker][] and its cousin [beaker-rspec][]. A common pattern for acceptance tests is to create a test manifest, apply it -twice to check for idempotency or errors, then run expectations. - -```ruby -it 'does an end-to-end thing' do - pp = <<-EOF - file { 'a test file': - ensure => present, - path => "/etc/sample", - content => "test string", - } - - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) - -end - -describe file("/etc/sample") do - it { is_expected.to contain "test string" } -end - -``` - -# If you have commit access to the repository - -Even if you have commit access to the repository, you still need to go through the process above, and have someone else review and merge -in your changes. The rule is that **all changes must be reviewed by a project developer that did not write the code to ensure that -all changes go through a code review process.** - -The record of someone performing the merge is the record that they performed the code review. Again, this should be someone other than the author of the topic branch. - -# Get Help - -### On the web -* [Puppet help messageboard](http://puppet.com/community/get-help) -* [Writing tests](https://docs.puppet.com/guides/module_guides/bgtm.html#step-three-module-testing) -* [General GitHub documentation](http://help.github.com/) -* [GitHub pull request documentation](http://help.github.com/send-pull-requests/) - -### On chat -* Slack (slack.puppet.com) #forge-modules, #puppet-dev, #windows, #voxpupuli -* IRC (freenode) #puppet-dev, #voxpupuli - - -[rspec-puppet]: http://rspec-puppet.com/ -[rspec-puppet_docs]: http://rspec-puppet.com/documentation/ -[beaker]: https://github.com/puppetlabs/beaker -[beaker-rspec]: https://github.com/puppetlabs/beaker-rspec +Check out our [Contributing to Supported Modules Blog Post](https://puppetlabs.github.io/iac/docs/contributing_to_a_module.html) to find all the information that you will need. diff --git a/spec/fixtures/module/Gemfile b/spec/fixtures/module/Gemfile index eb8fb94..3f6f5c7 100644 --- a/spec/fixtures/module/Gemfile +++ b/spec/fixtures/module/Gemfile @@ -13,23 +13,32 @@ def location_for(place_or_version, fake_version = nil) end end -ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments -minor_version = ruby_version_segments[0..1].join('.') - group :development do - gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0') - gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') - gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') - gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9') - gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-module-posix-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby] - gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby] - gem "puppet-module-win-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-module-win-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-lint-i18n", require: false - gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') + gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "voxpupuli-puppet-lint-plugins", '~> 4.0', require: false + gem "facterdb", '~> 1.18', require: false + gem "metadata-json-lint", '>= 2.0.2', '< 4.0.0', require: false + gem "puppetlabs_spec_helper", '~> 5.0', require: false + gem "rspec-puppet-facts", '~> 2.0', require: false + gem "codecov", '~> 0.2', require: false + gem "dependency_checker", '~> 0.2', require: false + gem "parallel_tests", '= 3.12.1', require: false + gem "pry", '~> 0.10', require: false + gem "simplecov-console", '~> 0.5', require: false + gem "puppet-debugger", '~> 1.0', require: false + gem "rubocop", '= 1.48.1', require: false + gem "rubocop-performance", '= 1.16.0', require: false + gem "rubocop-rspec", '= 2.19.0', require: false + gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "github_changelog_generator", '= 1.15.2', require: false +end +group :system_tests do + gem "puppet_litmus", '< 1.0.0', require: false, platforms: [:ruby, :x64_mingw] + gem "serverspec", '~> 2.41', require: false end puppet_version = ENV['PUPPET_GEM_VERSION'] @@ -46,16 +55,6 @@ gems['puppet'] = location_for(puppet_version) gems['facter'] = location_for(facter_version) if facter_version gems['hiera'] = location_for(hiera_version) if hiera_version -if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)} - # If we're using a Puppet gem on Windows which handles its own win32-xxx gem - # dependencies (>= 3.5.0), set the maximum versions (see PUP-6445). - gems['win32-dir'] = ['<= 0.4.9', require: false] - gems['win32-eventlog'] = ['<= 0.6.5', require: false] - gems['win32-process'] = ['<= 0.7.5', require: false] - gems['win32-security'] = ['<= 0.2.5', require: false] - gems['win32-service'] = ['0.8.8', require: false] -end - gems.each do |gem_name, gem_params| gem gem_name, *gem_params end diff --git a/spec/fixtures/module/REFERENCE.md b/spec/fixtures/module/REFERENCE.md index 26e8c3a..6864a33 100644 --- a/spec/fixtures/module/REFERENCE.md +++ b/spec/fixtures/module/REFERENCE.md @@ -1,15 +1,16 @@ # Reference + ## Table of Contents -**Classes** +### Classes * [`motd`](#motd): This module configures a system message of the day on a wide variety of systems. ## Classes -### motd +### `motd` This module configures a system message of the day on a wide variety of systems. @@ -23,9 +24,18 @@ include motd #### Parameters -The following parameters are available in the `motd` class. +The following parameters are available in the `motd` class: + +* [`dynamic_motd`](#-motd--dynamic_motd) +* [`template`](#-motd--template) +* [`content`](#-motd--content) +* [`issue_template`](#-motd--issue_template) +* [`issue_content`](#-motd--issue_content) +* [`issue_net_template`](#-motd--issue_net_template) +* [`issue_net_content`](#-motd--issue_net_content) +* [`windows_motd_title`](#-motd--windows_motd_title) -##### `dynamic_motd` +##### `dynamic_motd` Data type: `Boolean` @@ -33,7 +43,7 @@ Enables or disables dynamic motd on Debian systems. Default value: `true` -##### `template` +##### `template` Data type: `Optional[String]` @@ -41,7 +51,7 @@ Specifies a custom template. A template takes precedence over `content`. Valid o Default value: `undef` -##### `content` +##### `content` Data type: `Optional[String]` @@ -49,7 +59,7 @@ Specifies a static string as the motd content. Default value: `undef` -##### `issue_template` +##### `issue_template` Data type: `Optional[String]` @@ -57,7 +67,7 @@ Specifies a custom template to process and save to `/etc/issue`. A template take Default value: `undef` -##### `issue_content` +##### `issue_content` Data type: `Optional[String]` @@ -65,7 +75,7 @@ Specifies a static string as the `/etc/issue` content. Default value: `undef` -##### `issue_net_template` +##### `issue_net_template` Data type: `Optional[String]` @@ -73,7 +83,7 @@ Specifies a custom template to process and save to `/etc/issue.net`. A template Default value: `undef` -##### `issue_net_content` +##### `issue_net_content` Data type: `Optional[String]` @@ -81,7 +91,7 @@ Specifies a static string as the `/etc/issue.net` content. Default value: `undef` -##### `windows_motd_title` +##### `windows_motd_title` Data type: `String` @@ -90,5 +100,5 @@ Specifies a static string to be used for: and 'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\policies\system\legalnoticecaption' The 'legalnoticetext' registry key is shown before login on a Windows system. -Default value: 'Message of the day' +Default value: `'Message of the day'` diff --git a/spec/fixtures/module/Rakefile b/spec/fixtures/module/Rakefile index d1ab1bc..0f8754e 100644 --- a/spec/fixtures/module/Rakefile +++ b/spec/fixtures/module/Rakefile @@ -1,12 +1,12 @@ # frozen_string_literal: true +require 'bundler' require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-syntax/tasks/puppet-syntax' require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? -require 'puppet_pot_generator/rake_tasks' def changelog_user return unless Rake.application.top_level_tasks.include? "changelog" @@ -43,6 +43,7 @@ end PuppetLint.configuration.send('disable_relative') + if Bundler.rubygems.find_name('github_changelog_generator').any? GitHubChangelogGenerator::RakeTask.new :changelog do |config| raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? @@ -53,7 +54,7 @@ if Bundler.rubygems.find_name('github_changelog_generator').any? config.header = "# Change log\n\nAll notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org)." config.add_pr_wo_labels = true config.issues = false - config.merge_prefix = "### UNCATEGORIZED PRS; GO LABEL THEM" + config.merge_prefix = "### UNCATEGORIZED PRS; LABEL THEM ON GITHUB" config.configure_sections = { "Changed" => { "prefix" => "### Changed", @@ -61,11 +62,11 @@ if Bundler.rubygems.find_name('github_changelog_generator').any? }, "Added" => { "prefix" => "### Added", - "labels" => ["feature", "enhancement"], + "labels" => ["enhancement", "feature"], }, "Fixed" => { "prefix" => "### Fixed", - "labels" => ["bugfix"], + "labels" => ["bug", "documentation", "bugfix"], }, } end @@ -73,16 +74,15 @@ else desc 'Generate a Changelog from GitHub' task :changelog do raise <= Gem::Version.new('2.2.2')" + version: '~> 1.15' + condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')" EOM end end diff --git a/spec/fixtures/module/appveyor.yml b/spec/fixtures/module/appveyor.yml deleted file mode 100644 index eb3dcfb..0000000 --- a/spec/fixtures/module/appveyor.yml +++ /dev/null @@ -1,84 +0,0 @@ ---- -version: 1.1.x.{build} -branches: - only: - - main - - release -skip_commits: - message: /^\(?doc\)?.*/ -clone_depth: 10 -init: - - SET - - 'mkdir C:\ProgramData\PuppetLabs\code && exit 0' - - 'mkdir C:\ProgramData\PuppetLabs\facter && exit 0' - - 'mkdir C:\ProgramData\PuppetLabs\hiera && exit 0' - - 'mkdir C:\ProgramData\PuppetLabs\puppet\var && exit 0' -environment: - HONEYCOMB_WRITEKEY: 7f3c63a70eecc61d635917de46bea4e6 - HONEYCOMB_DATASET: litmus tests - SIMPLECOV: yes - matrix: - - - RUBY_VERSION: 24-x64 - CHECK: syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop - - - PUPPET_GEM_VERSION: ~> 5.0 - RUBY_VERSION: 24 - CHECK: parallel_spec - - - PUPPET_GEM_VERSION: ~> 5.0 - RUBY_VERSION: 24-x64 - CHECK: parallel_spec - - - PUPPET_GEM_VERSION: ~> 6.0 - RUBY_VERSION: 25 - CHECK: parallel_spec - - - PUPPET_GEM_VERSION: ~> 6.0 - RUBY_VERSION: 25-x64 - CHECK: parallel_spec - - - RUBY_VERSION: 25-x64 - ACCEPTANCE: yes - TARGET_HOST: localhost - - - RUBY_VERSION: 25-x64 - ACCEPTANCE: yes - TARGET_HOST: localhost - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 -for: -- - matrix: - only: - - ACCEPTANCE: yes - install: - - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH% - - bundle install --jobs 4 --retry 2 - - type Gemfile.lock - test_script: - - bundle exec puppet -V - - ruby -v - - gem -v - - bundle -v - - bundle exec rake spec_prep - - bundle exec rake litmus:acceptance:localhost -matrix: - fast_finish: true -install: - - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH% - - bundle install --jobs 4 --retry 2 --without system_tests - - type Gemfile.lock -build: off -test_script: - - bundle exec puppet -V - - ruby -v - - gem -v - - bundle -v - - bundle exec rake %CHECK% -notifications: - - provider: Email - to: - - nobody@nowhere.com - on_build_success: false - on_build_failure: false - on_build_status_changed: false diff --git a/spec/fixtures/module/data/common.yaml b/spec/fixtures/module/data/common.yaml new file mode 100644 index 0000000..2fbf0ff --- /dev/null +++ b/spec/fixtures/module/data/common.yaml @@ -0,0 +1 @@ +--- {} diff --git a/spec/fixtures/module/distelli-manifest.yml b/spec/fixtures/module/distelli-manifest.yml deleted file mode 100644 index 69d13c7..0000000 --- a/spec/fixtures/module/distelli-manifest.yml +++ /dev/null @@ -1,25 +0,0 @@ -team-modules/puppetlabs-motd: - PreBuild: - - source /opt/rh/rh-ruby25/enable - - echo "--- LETS update BUNDLER ---" - - bundle install --path vendor/bundle --jobs 3 - Build: - - echo "--- PROVISIONING ---" - - source /opt/rh/rh-ruby25/enable - - bundle exec rake litmus:provision_list[release_checks] - - cat inventory.yaml - - echo "--- AGENT INSTALLATION ---" - - bundle exec rake litmus:install_agent - - echo "--- MODULE INSTALLATION ---" - - bundle exec rake litmus:install_module - - echo "--- TESTS RUNNING ---" - - bundle exec rake litmus:acceptance:parallel - AfterBuildSuccess: - - source /opt/rh/rh-ruby25/enable - - bundle exec rake litmus:tear_down - AfterBuildFailure: - - source /opt/rh/rh-ruby25/enable - - bundle exec rake litmus:tear_down - CommitData: - - RepoType: Git - - RepoPath: . diff --git a/spec/fixtures/module/hiera.yaml b/spec/fixtures/module/hiera.yaml new file mode 100644 index 0000000..545fff3 --- /dev/null +++ b/spec/fixtures/module/hiera.yaml @@ -0,0 +1,21 @@ +--- +version: 5 + +defaults: # Used for any hierarchy level that omits these keys. + datadir: data # This path is relative to hiera.yaml's directory. + data_hash: yaml_data # Use the built-in YAML backend. + +hierarchy: + - name: "osfamily/major release" + paths: + # Used to distinguish between Debian and Ubuntu + - "os/%{facts.os.name}/%{facts.os.release.major}.yaml" + - "os/%{facts.os.family}/%{facts.os.release.major}.yaml" + # Used for Solaris + - "os/%{facts.os.family}/%{facts.kernelrelease}.yaml" + - name: "osfamily" + paths: + - "os/%{facts.os.name}.yaml" + - "os/%{facts.os.family}.yaml" + - name: 'common' + path: 'common.yaml' diff --git a/spec/fixtures/module/lib/this/is/a/nested/path/file.rb b/spec/fixtures/module/lib/this/is/a/nested/path/file.rb deleted file mode 100644 index 4d757a0..0000000 --- a/spec/fixtures/module/lib/this/is/a/nested/path/file.rb +++ /dev/null @@ -1 +0,0 @@ -# A deeply nested file \ No newline at end of file diff --git a/spec/fixtures/module/locales/config.yaml b/spec/fixtures/module/locales/config.yaml deleted file mode 100644 index 2135856..0000000 --- a/spec/fixtures/module/locales/config.yaml +++ /dev/null @@ -1,26 +0,0 @@ ---- -# This is the project-specific configuration file for setting up -# fast_gettext for your project. -gettext: - # This is used for the name of the .pot and .po files; they will be - # called .pot? - project_name: puppetlabs-motd - # This is used in comments in the .pot and .po files to indicate what - # project the files belong to and should bea little more desctiptive than - # - package_name: puppetlabs-motd - # The locale that the default messages in the .pot file are in - default_locale: en - # The email used for sending bug reports. - bugs_address: docs@puppet.com - # The holder of the copyright. - copyright_holder: Puppet, Inc. - # This determines which comments in code should be eligible for translation. - # Any comments that start with this string will be externalized. (Leave - # empty to include all.) - comments_tag: TRANSLATOR - # Patterns for +Dir.glob+ used to find all files that might contain - # translatable content, relative to the project root directory - source_files: - - './lib/**/*.rb' - diff --git a/spec/fixtures/module/locales/ja/puppetlabs-motd.po b/spec/fixtures/module/locales/ja/puppetlabs-motd.po deleted file mode 100644 index dd3723b..0000000 --- a/spec/fixtures/module/locales/ja/puppetlabs-motd.po +++ /dev/null @@ -1,54 +0,0 @@ -# #-#-#-#-# puppetlabs-motd.pot (PACKAGE VERSION) #-#-#-#-# -# #-#-#-#-# puppetlabs-motd_metadata.pot (PACKAGE VERSION) #-#-#-#-# -# -# #-#-#-#-# puppetlabs-motd_metadata.pot (PACKAGE VERSION) #-#-#-#-# -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-31 15:17:29 +0300\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: Eriko Kashiwagi , 2018\n" -"Language-Team: Japanese (Japan) (https://www.transifex.com/puppet/teams/29089/ja_JP/)\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Language: ja_JP\n" -"Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Translate Toolkit 2.0.0\n" - -#. metadata.json -#: .summary -msgid "" -"A simple module to demonstrate managing /etc/motd or Windows Logon Message " -"as a template" -msgstr "/etc/motdまたは Windowsログオンメッセージのテンプレートによる管理をデモンストレーションするためのシンプルなモジュール" - -#. metadata.json -#: .description -msgid "" -"This module simply manages /etc/motd or the Windows Logon Message as a " -"template, showing interpolation of system attributes" -msgstr "" -"本モジュールは、/etc/motdまたはWindowsログオンメッセージをテンプレートとして管理するシンプルなモジュールで、システム属性の補間を示します。" - -#. ./manifests/init.pp:31 -msgid "" -"Both $template and $content parameters passed to motd, ignoring content" -msgstr "$templateパラメータと$contentパラメータの両方がmotdに渡され、contentは無視されました。" - -#. ./manifests/init.pp:42 -msgid "" -"Both $issue_template and $issue_content parameters passed to motd, ignoring " -"issue_content" -msgstr "" -"$issue_templateパラメータと$issue_contentパラメータの両方がmotdに渡され、issue_contentは無視されました。" - -#. ./manifests/init.pp:53 -msgid "" -"Both $issue_net_template and $issue_net_content parameters passed to motd, " -"ignoring issue_net_content" -msgstr "" -"$issue_net_templateパラメータと$issue_net_contentパラメータの両方がmotdに渡され、issue_net_contentは無視されました。" diff --git a/spec/fixtures/module/locales/puppetlabs-motd.pot b/spec/fixtures/module/locales/puppetlabs-motd.pot deleted file mode 100644 index 6c875a2..0000000 --- a/spec/fixtures/module/locales/puppetlabs-motd.pot +++ /dev/null @@ -1,83 +0,0 @@ -# #-#-#-#-# puppetlabs-motd.pot (PACKAGE VERSION) #-#-#-#-# -# #-#-#-#-# puppetlabs-motd_metadata.pot (PACKAGE VERSION) #-#-#-#-# -# -# #-#-#-#-# puppetlabs-motd_metadata.pot (PACKAGE VERSION) #-#-#-#-# -# -#, fuzzy -msgid "" -msgstr "" -"#-#-#-#-# puppetlabs-motd.pot (PACKAGE VERSION) #-#-#-#-#\n" -"#-#-#-#-# puppetlabs-motd_metadata.pot (PACKAGE VERSION) #-#-#-#-#\n" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To:\n" -"POT-Creation-Date: 2018-08-30T17:06:40+03:00\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"X-Generator: Translate Toolkit 2.0.0\n" -"#-#-#-#-# puppet.pot (PACKAGE VERSION) #-#-#-#-#\n" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-30 17:06:26 +0300\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"X-Generator: Translate Toolkit 2.0.0\n" -"#-#-#-#-# puppetlabs-motd_metadata.pot (PACKAGE VERSION) #-#-#-#-#\n" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To:\n" -"POT-Creation-Date: 2018-08-31T15:17:37+03:00\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"X-Generator: Translate Toolkit 2.0.0\n" -"#-#-#-#-# puppet.pot (PACKAGE VERSION) #-#-#-#-#\n" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-31 15:17:29 +0300\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"X-Generator: Translate Toolkit 2.0.0\n" - -#. metadata.json -#: .summary -msgid "" -"A simple module to demonstrate managing /etc/motd or Windows Logon Message " -"as a template" -msgstr "" - -#. metadata.json -#: .description -msgid "" -"This module simply manages /etc/motd or the Windows Logon Message as a " -"template, showing interpolation of system attributes" -msgstr "" - -#. ./manifests/init.pp:31 -msgid "Both $template and $content parameters passed to motd, ignoring content" -msgstr "" - -#. ./manifests/init.pp:42 -msgid "" -"Both $issue_template and $issue_content parameters passed to motd, ignoring " -"issue_content" -msgstr "" - -#. ./manifests/init.pp:53 -msgid "" -"Both $issue_net_template and $issue_net_content parameters passed to motd, " -"ignoring issue_net_content" -msgstr "" diff --git a/spec/fixtures/module/manifests/init.pp b/spec/fixtures/module/manifests/init.pp index 94d8e27..848b868 100644 --- a/spec/fixtures/module/manifests/init.pp +++ b/spec/fixtures/module/manifests/init.pp @@ -41,10 +41,9 @@ Optional[String] $issue_net_content = undef, String $windows_motd_title = 'Message of the day', ) { - if $template { if $content { - warning(translate('Both $template and $content parameters passed to motd, ignoring content')) + warning('Both $template and $content parameters passed to motd, ignoring content') } $motd_content = epp($template) } elsif $content { @@ -55,7 +54,7 @@ if $issue_template { if $issue_content { - warning(translate('Both $issue_template and $issue_content parameters passed to motd, ignoring issue_content')) + warning('Both $issue_template and $issue_content parameters passed to motd, ignoring issue_content') } $_issue_content = epp($issue_template) } elsif $issue_content { @@ -66,7 +65,7 @@ if $issue_net_template { if $issue_net_content { - warning(translate('Both $issue_net_template and $issue_net_content parameters passed to motd, ignoring issue_net_content')) + warning('Both $issue_net_template and $issue_net_content parameters passed to motd, ignoring issue_net_content') } $_issue_net_content = epp($issue_net_template) } elsif $issue_net_content { @@ -96,14 +95,16 @@ mode => $mode, } - if $facts['kernel'] in ['Linux', 'SunOS', 'FreeBSD', 'AIX'] { - file { '/etc/motd': - ensure => file, - backup => false, - content => $motd_content, - } + if $facts['kernel'] in ['Linux', 'SunOS', 'FreeBSD', 'AIX'] { + if $facts['kernel'] == 'FreeBSD' { + if versioncmp($facts['os']['release']['major'], '13') >= 0 { + $_motd_location = '/etc/motd.template' + } else { + $_motd_location = '/etc/motd' + } + } else { + $_motd_location = '/etc/motd' - if $facts['kernel'] != 'FreeBSD' { if $_issue_content { file { '/etc/issue': ensure => file, @@ -121,10 +122,16 @@ } } - if ($facts['osfamily'] == 'Debian') and ($dynamic_motd == false) { - if $facts['operatingsystem'] == 'Debian' and versioncmp($facts['operatingsystemmajrelease'], '7') > 0 { + file { $_motd_location: + ensure => file, + backup => false, + content => $motd_content, + } + + if ($facts['os']['family'] == 'Debian') and ($dynamic_motd == false) { + if $facts['os']['name'] == 'Debian' and versioncmp($facts['os']['release']['major'], '7') > 0 { $_line_to_remove = 'session optional pam_motd.so motd=/run/motd.dynamic' - } elsif $facts['operatingsystem'] == 'Ubuntu' and versioncmp($facts['operatingsystemmajrelease'], '16.00') > 0 { + } elsif $facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['major'], '16.00') > 0 { $_line_to_remove = 'session optional pam_motd.so motd=/run/motd.dynamic' } else { $_line_to_remove = 'session optional pam_motd.so motd=/run/motd.dynamic noupdate' diff --git a/spec/fixtures/module/metadata.json b/spec/fixtures/module/metadata.json index d0828cf..395af66 100644 --- a/spec/fixtures/module/metadata.json +++ b/spec/fixtures/module/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-motd", - "version": "4.1.0", + "version": "7.0.0", "author": "puppetlabs", "summary": "A simple module to demonstrate managing /etc/motd or Windows Logon Message as a template", "license": "Apache-2.0", @@ -10,32 +10,25 @@ "dependencies": [ { "name": "puppetlabs/registry", - "version_requirement": ">= 1.0.0 < 4.0.0" + "version_requirement": ">= 1.0.0 < 6.0.0" }, { "name": "puppetlabs/stdlib", - "version_requirement": ">= 2.1.0 < 7.0.0" - }, - { - "name": "puppetlabs/translate", - "version_requirement": ">= 1.0.0 < 3.0.0" + "version_requirement": ">= 2.1.0 < 9.0.0" } ], "operatingsystem_support": [ { "operatingsystem": "RedHat", "operatingsystemrelease": [ - "5", - "6", "7", - "8" + "8", + "9" ] }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ - "5", - "6", "7", "8" ] @@ -43,30 +36,25 @@ { "operatingsystem": "OracleLinux", "operatingsystemrelease": [ - "5", - "6", "7" ] }, { "operatingsystem": "Scientific", "operatingsystemrelease": [ - "6", "7" ] }, { "operatingsystem": "Debian", "operatingsystemrelease": [ - "8", - "9", - "10" + "10", + "11" ] }, { "operatingsystem": "SLES", "operatingsystemrelease": [ - "11", "12", "15" ] @@ -74,30 +62,41 @@ { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ - "14.04", - "16.04", - "18.04" + "18.04", + "20.04", + "22.04" ] }, { "operatingsystem": "Windows", "operatingsystemrelease": [ - "2008 R2", "2012 R2", "2016", "2019", "10" ] + }, + { + "operatingsystem": "Rocky", + "operatingsystemrelease": [ + "8" + ] + }, + { + "operatingsystem": "AlmaLinux", + "operatingsystemrelease": [ + "8" + ] } ], "requirements": [ { "name": "puppet", - "version_requirement": ">= 5.5.10 < 7.0.0" + "version_requirement": ">= 7.0.0 < 9.0.0" } ], "description": "This module simply manages /etc/motd or the Windows Logon Message as a template, showing interpolation of system attributes", - "template-url": "https://github.com/puppetlabs/pdk-templates#main", - "template-ref": "heads/main-0-g88c96ab", - "pdk-version": "1.16.0" + "template-url": "https://github.com/puppetlabs/pdk-templates.git#main", + "template-ref": "heads/main-0-gc6d4446", + "pdk-version": "2.7.1" } diff --git a/spec/fixtures/module/pdk.yaml b/spec/fixtures/module/pdk.yaml new file mode 100644 index 0000000..4bef4bd --- /dev/null +++ b/spec/fixtures/module/pdk.yaml @@ -0,0 +1,2 @@ +--- +ignore: [] diff --git a/spec/fixtures/module/provision.yaml b/spec/fixtures/module/provision.yaml index 396017e..8983f27 100644 --- a/spec/fixtures/module/provision.yaml +++ b/spec/fixtures/module/provision.yaml @@ -1,22 +1,81 @@ --- default: - provisioner: docker - images: ['waffleimage/centos7'] + provisioner: docker + images: + - litmusimage/centos:7 vagrant: provisioner: vagrant - images: ['centos/7', 'generic/ubuntu1804', 'gusztavvargadr/windows-server'] + images: + - centos/7 + - generic/ubuntu1804 + - gusztavvargadr/windows-server travis_deb: - provisioner: docker - images: ['waffleimage/debian8', 'waffleimage/debian9', 'waffleimage/debian10'] -travis_ub: - provisioner: docker - images: ['waffleimage/ubuntu14.04', 'waffleimage/ubuntu16.04', 'waffleimage/ubuntu18.04'] -travis_el6: - provisioner: docker - images: ['waffleimage/centos6', 'waffleimage/oraclelinux6', 'waffleimage/scientificlinux6'] + provisioner: docker + images: + - litmusimage/debian:8 + - litmusimage/debian:9 + - litmusimage/debian:10 +travis_ub_6: + provisioner: docker + images: + - litmusimage/ubuntu:14.04 + - litmusimage/ubuntu:16.04 + - litmusimage/ubuntu:18.04 + - litmusimage/ubuntu:20.04 travis_el7: - provisioner: docker - images: ['waffleimage/centos7', 'waffleimage/oraclelinux7', 'waffleimage/scientificlinux7'] -release_checks: - provisioner: vmpooler - images: ['redhat-5-x86_64', 'redhat-6-x86_64', 'redhat-7-x86_64', 'redhat-8-x86_64', 'centos-5-x86_64', 'centos-6-x86_64', 'centos-7-x86_64', 'centos-8-x86_64', 'oracle-5-x86_64', 'oracle-6-x86_64', 'oracle-7-x86_64', 'scientific-6-x86_64', 'scientific-7-x86_64', 'debian-8-x86_64', 'debian-9-x86_64', 'debian-10-x86_64', 'sles-11-x86_64', 'sles-12-x86_64', 'sles-15-x86_64', 'ubuntu-1404-x86_64', 'ubuntu-1604-x86_64', 'ubuntu-1804-x86_64', 'win-2008r2-x86_64', 'win-2012r2-x86_64', 'win-2016-core-x86_64', 'win-2019-core-x86_64', 'win-10-pro-x86_64'] + provisioner: docker + images: + - litmusimage/centos:7 + - litmusimage/oraclelinux:7 + - litmusimage/scientificlinux:7 +travis_el8: + provisioner: docker + images: + - litmusimage/centos:8 +release_checks_6: + provisioner: abs + images: + - redhat-6-x86_64 + - redhat-7-x86_64 + - redhat-8-x86_64 + - centos-6-x86_64 + - centos-7-x86_64 + - centos-8-x86_64 + - oracle-5-x86_64 + - oracle-6-x86_64 + - oracle-7-x86_64 + - scientific-6-x86_64 + - scientific-7-x86_64 + - debian-8-x86_64 + - debian-9-x86_64 + - debian-10-x86_64 + - sles-12-x86_64 + - sles-15-x86_64 + - ubuntu-1404-x86_64 + - ubuntu-1604-x86_64 + - ubuntu-1804-x86_64 + - ubuntu-2004-x86_64 + - win-2008r2-x86_64 + - win-2012r2-x86_64 + - win-2016-core-x86_64 + - win-2019-core-x86_64 + - win-10-pro-x86_64 +release_checks_7: + provisioner: abs + images: + - redhat-7-x86_64 + - redhat-8-x86_64 + - centos-7-x86_64 + - centos-8-x86_64 + - oracle-7-x86_64 + - scientific-7-x86_64 + - debian-9-x86_64 + - debian-10-x86_64 + - sles-12-x86_64 + - sles-15-x86_64 + - ubuntu-1804-x86_64 + - ubuntu-2004-x86_64 + - win-2012r2-x86_64 + - win-2016-core-x86_64 + - win-2019-core-x86_64 + - win-10-pro-x86_64 diff --git a/spec/fixtures/module/spec/acceptance/motd_spec.rb b/spec/fixtures/module/spec/acceptance/motd_spec.rb index 219d6ac..990171c 100644 --- a/spec/fixtures/module/spec/acceptance/motd_spec.rb +++ b/spec/fixtures/module/spec/acceptance/motd_spec.rb @@ -1,115 +1,131 @@ -require 'spec_helper_acceptance' +# frozen_string_literal: true -motd_file = '/etc/motd' - -issue_file = '/etc/issue' - -issue_net_file = '/etc/issue.net' - -template_expected_content = 'Test Template for Rspec' - -pp_static_content = <<-PUPPETCODE - class { motd: - content => "Hello world!\n", - } -PUPPETCODE - -pp_static_template = <<-PUPPETCODE - class { motd: - template => "motd/spec.epp", - } -PUPPETCODE - -pp_static_content_issue = <<-PUPPETCODE - class { motd: - issue_content => "Hello world!\n", - content => "Hello world!\n", - } -PUPPETCODE - -pp_static_template_issue = <<-PUPPETCODE - class { motd: - issue_template => "motd/spec.epp", - content => "Hello world!\n", - } -PUPPETCODE - -pp_static_content_issue_net = <<-PUPPETCODE - class { motd: - issue_net_content => "Hello world!\n", - content => "Hello world!\n", - } -PUPPETCODE - -pp_static_template_issue_net = <<-PUPPETCODE - class { motd: - issue_net_template => "motd/spec.epp", - content => "Hello world!\n", - } -PUPPETCODE - -pp_debian_dynamic = <<-PUPPETCODE - class { motd: - dynamic_motd => false, - content => "Hello world!\n", - } -PUPPETCODE - -# @summary: Helper function to run common functionality of MOTD acceptance tests. -# Applies the manifest twice, if not windows checks for file against expected contents. -# If a Debian dynamic test bool is given as true, executes a test for that platform. -# @param [string] pp: Class MOTD definition to be tested -# @param [string] expected_contain: Expected contents of the MOTD file to be compared -# @param [string] filename: MOTD file to be tested -def test_motd(pp, expected_contain, filename) - idempotent_apply(pp) - - return unless os[:family] != 'windows' - expect(file(filename)).to be_file - expect(file(filename)).to contain expected_contain -end +require 'spec_helper_acceptance' describe 'Message of the day' do context 'when static message from content' do + pp = <<-PUPPETCODE + class { motd: + content => "Hello world!\n", + } + PUPPETCODE + it do - test_motd(pp_static_content, "Hello world!\n", motd_file) + idempotent_apply(pp) + + unless os[:family] == 'windows' + expect(file('/etc/motd')).to be_file + expect(file('/etc/motd')).to contain("Hello world!\n") + end end end context 'when static message from template' do + pp = <<-PUPPETCODE + class { motd: + template => "motd/spec.epp", + } + PUPPETCODE + it do - test_motd(pp_static_template, template_expected_content, motd_file) + idempotent_apply(pp) + + unless os[:family] == 'windows' + expect(file('/etc/motd')).to be_file + expect(file('/etc/motd')).to contain('Test Template for Rspec') + end end end context 'when static message from content in /etc/issue' do + pp = <<-PUPPETCODE + class { motd: + issue_content => "Hello world!\n", + content => "Hello world!\n", + } + PUPPETCODE + it do - test_motd(pp_static_content_issue, "Hello world!\n", issue_file) + idempotent_apply(pp) + + unless os[:family] == 'windows' + expect(file('/etc/issue')).to be_file + expect(file('/etc/issue')).to contain("Hello world!\n") + end end end context 'when static message from template in /etc/issue' do + pp = <<-PUPPETCODE + class { motd: + issue_template => "motd/spec.epp", + content => "Hello world!\n", + } + PUPPETCODE + it do - test_motd(pp_static_template_issue, template_expected_content, issue_file) + idempotent_apply(pp) + + unless os[:family] == 'windows' + expect(file('/etc/issue')).to be_file + expect(file('/etc/issue')).to contain('Test Template for Rspec') + end end end context 'when static message from content in /etc/issue.net' do + pp = <<-PUPPETCODE + class { motd: + issue_net_content => "Hello world!\n", + content => "Hello world!\n", + } + PUPPETCODE + it do - test_motd(pp_static_content_issue_net, "Hello world!\n", issue_net_file) + idempotent_apply(pp) + + unless os[:family] == 'windows' + expect(file('/etc/issue.net')).to be_file + expect(file('/etc/issue.net')).to contain("Hello world!\n") + end end end context 'when static message from template in /etc/issue.net' do + pp = <<-PUPPETCODE + class { motd: + issue_net_template => "motd/spec.epp", + content => "Hello world!\n", + } + PUPPETCODE + it do - test_motd(pp_static_template_issue_net, template_expected_content, issue_net_file) + idempotent_apply(pp) + + unless os[:family] == 'windows' + expect(file('/etc/issue.net')).to be_file + expect(file('/etc/issue.net')).to contain('Test Template for Rspec') + end end end context 'when disable dynamic motd settings on Debian', if: os[:family] == 'debian' do + pp = <<-PUPPETCODE + class { motd: + dynamic_motd => false, + content => "Hello world!\n", + } + PUPPETCODE + it do - test_motd(pp_debian_dynamic, "Hello world!\n", motd_file) + idempotent_apply(pp) + + unless os[:family] == 'windows' + expect(file('/etc/motd')).to be_file + expect(file('/etc/motd')).to contain("Hello world!\n") + end end + describe file('/etc/pam.d/sshd') do its(:content) { is_expected.not_to match %r{session optional pam_motd.so motd=/run/motd.dynamic} } end diff --git a/spec/fixtures/module/spec/classes/motd_spec.rb b/spec/fixtures/module/spec/classes/motd_spec.rb index 13c9b8c..085f755 100644 --- a/spec/fixtures/module/spec/classes/motd_spec.rb +++ b/spec/fixtures/module/spec/classes/motd_spec.rb @@ -1,41 +1,51 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'motd', type: :class do describe 'On a non-linux system' do - let(:facts) { { kernel: 'Unknown' } } + let(:facts) do + { + kernel: 'Unknown', + os: { + name: 'Unknown', + family: 'Unknown', + architecture: 'Unknown', + release: { + major: 'Unknown' + } + }, + memory: { + system: { + available: 'Unknown' + } + }, + processors: { + models: [ + 'Unknown', + ] + } + } + end it 'does not fail' do - is_expected.not_to raise_error + expect(subject).not_to raise_error end + it { is_expected.not_to contain_file('/etc/motd') } it { is_expected.not_to contain_file('/etc/issue') } it { is_expected.not_to contain_file('/etc/issue.net') } end describe 'On Linux' do - let(:facts) do - { - kernel: 'Linux', - operatingsystem: 'TestOS', - operatingsystemrelease: 5, - osfamily: 'Debian', - architecture: 'x86_64', - processor0: 'intel awesome', - fqdn: 'test.example.com', - ipaddress: '123.23.243.1', - memorysize: '16.00 GB', - } - end + let(:facts) { on_supported_os['redhat-9-x86_64'] } context 'when neither template or source are specified' do it do - is_expected.to contain_File('/etc/motd').with( - ensure: 'file', - backup: 'false', - content: "TestOS 5 x86_64\n\nFQDN: test.example.com (123.23.243.1)\nProcessor: intel awesome\nKernel: Linux\nMemory Size: 16.00 GB\n", - owner: 'root', - group: 'root', - mode: '0644', + expect(subject).to contain_File('/etc/motd').with( + ensure: 'file', backup: 'false', + content: "RedHat 9.0 x86_64\n\nFQDN: foo.example.com (10.109.1.2)\nProcessor: Intel Xeon Processor (Cascadelake)\nKernel: Linux\nMemory Size: 3.10 GiB\n", + owner: 'root', group: 'root', mode: '0644' ) end end @@ -44,12 +54,12 @@ let(:params) do { content: 'Hello!', - template: 'motd/spec.epp', + template: 'motd/spec.epp' } end it do - is_expected.to contain_File('/etc/motd').with( + expect(subject).to contain_File('/etc/motd').with( ensure: 'file', backup: 'false', content: "Test Template for Rspec\n", @@ -61,7 +71,7 @@ let(:params) { { content: 'Hello!' } } it do - is_expected.to contain_File('/etc/motd').with( + expect(subject).to contain_File('/etc/motd').with( ensure: 'file', backup: 'false', content: 'Hello!', @@ -73,7 +83,7 @@ let(:params) { { template: 'motd/spec.epp' } } it do - is_expected.to contain_File('/etc/motd').with( + expect(subject).to contain_File('/etc/motd').with( ensure: 'file', backup: 'false', content: "Test Template for Rspec\n", @@ -85,13 +95,10 @@ let(:params) { { issue_template: 'motd/spec.epp' } } it do - is_expected.to contain_File('/etc/issue').with( - ensure: 'file', - backup: 'false', + expect(subject).to contain_File('/etc/issue').with( + ensure: 'file', backup: 'false', content: "Test Template for Rspec\n", - owner: 'root', - group: 'root', - mode: '0644', + owner: 'root', group: 'root', mode: '0644' ) end end @@ -100,7 +107,7 @@ let(:params) { { issue_content: 'Hello!' } } it do - is_expected.to contain_File('/etc/issue').with( + expect(subject).to contain_File('/etc/issue').with( ensure: 'file', backup: 'false', content: 'Hello!', @@ -113,12 +120,12 @@ let(:params) do { issue_content: 'Hello!', - issue_template: 'motd/spec.epp', + issue_template: 'motd/spec.epp' } end it do - is_expected.to contain_File('/etc/issue').with( + expect(subject).to contain_File('/etc/issue').with( ensure: 'file', backup: 'false', content: "Test Template for Rspec\n", @@ -130,13 +137,10 @@ let(:params) { { issue_net_template: 'motd/spec.epp' } } it do - is_expected.to contain_File('/etc/issue.net').with( - ensure: 'file', - backup: 'false', + expect(subject).to contain_File('/etc/issue.net').with( + ensure: 'file', backup: 'false', content: "Test Template for Rspec\n", - owner: 'root', - group: 'root', - mode: '0644', + owner: 'root', group: 'root', mode: '0644' ) end end @@ -145,7 +149,7 @@ let(:params) { { issue_net_content: 'Hello!' } } it do - is_expected.to contain_File('/etc/issue.net').with( + expect(subject).to contain_File('/etc/issue.net').with( ensure: 'file', backup: 'false', content: 'Hello!', @@ -158,12 +162,12 @@ let(:params) do { issue_net_content: 'Hello!', - issue_net_template: 'motd/spec.epp', + issue_net_template: 'motd/spec.epp' } end it do - is_expected.to contain_File('/etc/issue.net').with( + expect(subject).to contain_File('/etc/issue.net').with( ensure: 'file', backup: 'false', content: "Test Template for Rspec\n", @@ -173,19 +177,12 @@ end describe 'On Debian based Operating Systems' do - let(:facts) do - { - kernel: 'Linux', - operatingsystem: 'Debian', - operatingsystemmajrelease: '7', - osfamily: 'Debian', - } - end + let(:facts) { on_supported_os['debian-11-x86_64'] } context 'when dynamic motd is false' do let(:params) { { dynamic_motd: false } } - it { is_expected.to contain_file_line('dynamic_motd').with_line('session optional pam_motd.so motd=/run/motd.dynamic noupdate') } + it { is_expected.to contain_file_line('dynamic_motd').with_line('session optional pam_motd.so motd=/run/motd.dynamic') } end context 'when dynamic motd is true' do @@ -194,45 +191,38 @@ it { is_expected.not_to contain_file_line('dynamic_motd') } end end + describe 'On Windows' do - let(:facts) do - { - kernel: 'windows', - operatingsystem: 'TestOS', - operatingsystemrelease: 5, - osfamily: 'windows', - architecture: 'x86_64', - processor0: 'intel awesome', - fqdn: 'test.example.com', - ipaddress: '123.23.243.1', - memorysize: '16.00 GB', - } - end + let(:facts) { on_supported_os['windows-10-x86_64'] } context 'when neither template or source are specified' do it do - is_expected.to contain_Registry_value('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\policies\system\legalnoticetext').with( + expect(subject).to contain_Registry_value('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\policies\system\legalnoticetext').with( ensure: 'present', type: 'string', - data: "TestOS 5 x86_64\n\nFQDN: test.example.com (123.23.243.1)\nProcessor: intel awesome\nKernel: windows\nMemory Size: 16.00 GB\n", + data: "windows 10 x64\n\nFQDN: foo.example.com (10.138.1.5)\nProcessor: Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz\nKernel: windows\nMemory Size: 14.34 GiB\n", ) end end + context 'when content is specified' do let(:params) do { content: 'Hello!', - windows_motd_title: 'This is the title.', + windows_motd_title: 'This is the title.' } end it do - is_expected.to contain_Registry_value('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\policies\system\legalnoticetext').with( + expect(subject).to contain_Registry_value('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\policies\system\legalnoticetext').with( ensure: 'present', type: 'string', data: 'Hello!', ) - is_expected.to contain_Registry_value('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\policies\system\legalnoticecaption').with( + end + + it do + expect(subject).to contain_Registry_value('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\policies\system\legalnoticecaption').with( ensure: 'present', type: 'string', data: 'This is the title.', @@ -242,26 +232,43 @@ end describe 'On FreeBSD' do - let(:facts) do + # let(:facts) { on_supported_os['freebsd-12-amd64'] } + let :facts do { kernel: 'FreeBSD', - operatingsystem: 'TestOS', - operatingsystemrelease: 11, - osfamily: 'FreeBSD', - architecture: 'amd64', - processor0: 'intel', - fqdn: 'test.example.com', - ipaddress: '123.23.243.1', - memorysize: '16.00 GB', + path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + os: { + name: 'FreeBSD', + family: 'FreeBSD', + architecture: 'amd64', + release: { + full: '11', + major: '11' + } + }, + networking: { + fqdn: 'test.example.com', + ip: '123.23.243.1' + }, + memory: { + system: { + available: '16.00 GB' + } + }, + processors: { + models: [ + 'intel', + ] + } } end context 'when neither template or source are specified' do it do - is_expected.to contain_File('/etc/motd').with( + expect(subject).to contain_File('/etc/motd').with( ensure: 'file', backup: 'false', - content: "TestOS 11 amd64\n\nFQDN: test.example.com (123.23.243.1)\nProcessor: intel\nKernel: FreeBSD\nMemory Size: 16.00 GB\n", + content: "FreeBSD 11 amd64\n\nFQDN: test.example.com (123.23.243.1)\nProcessor: intel\nKernel: FreeBSD\nMemory Size: 16.00 GB\n", ) end end @@ -270,12 +277,12 @@ let(:params) do { content: 'Hello!', - template: 'motd/spec.epp', + template: 'motd/spec.epp' } end it do - is_expected.to contain_File('/etc/motd').with( + expect(subject).to contain_File('/etc/motd').with( ensure: 'file', backup: 'false', content: "Test Template for Rspec\n", @@ -287,7 +294,7 @@ let(:params) { { content: 'Hello!' } } it do - is_expected.to contain_File('/etc/motd').with( + expect(subject).to contain_File('/etc/motd').with( ensure: 'file', backup: 'false', content: 'Hello!', @@ -299,7 +306,7 @@ let(:params) { { template: 'motd/spec.epp' } } it do - is_expected.to contain_File('/etc/motd').with( + expect(subject).to contain_File('/etc/motd').with( ensure: 'file', backup: 'false', content: "Test Template for Rspec\n", @@ -307,58 +314,68 @@ end end end + describe 'On AIX' do - let(:facts) do + # let(:facts) { on_supported_os['aix-7.1-power'] } + let :facts do { kernel: 'AIX', - operatingsystem: 'AIX', - operatingsystemrelease: '7100-04-02-1614', - osfamily: 'AIX', - architecture: 'PowerPC_POWER8', - processor0: 'PowerPC_POWER8', - fqdn: 'test.example.com', - ipaddress: '123.23.243.1', - memorysize: '16.00 GB', + path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + os: { + name: 'AIX', + family: 'AIX', + architecture: 'PowerPC_POWER8', + release: { + full: '7100-04-02-1614' + } + }, + networking: { + fqdn: 'test.example.com', + ip: '123.23.243.1' + }, + memory: { + system: { + available: '16.00 GB' + } + }, + processors: { + models: [ + 'PowerPC_POWER8', + ] + } } end context 'when neither template or source are specified' do it do - is_expected.to contain_File('/etc/motd').with( - ensure: 'file', - backup: 'false', + expect(subject).to contain_File('/etc/motd').with( + ensure: 'file', backup: 'false', content: "AIX 7100-04-02-1614 PowerPC_POWER8\n\nFQDN: test.example.com (123.23.243.1)\nProcessor: \PowerPC_POWER8\nKernel: AIX\nMemory Size: 16.00 GB\n", - owner: 'bin', - group: 'bin', - mode: '0644', + owner: 'bin', group: 'bin', mode: '0644' ) end end + context 'when a template is specified for /etc/issue' do let(:params) { { issue_template: 'motd/spec.epp' } } it do - is_expected.to contain_File('/etc/issue').with( - ensure: 'file', - backup: 'false', + expect(subject).to contain_File('/etc/issue').with( + ensure: 'file', backup: 'false', content: "Test Template for Rspec\n", - owner: 'bin', - group: 'bin', - mode: '0644', + owner: 'bin', group: 'bin', mode: '0644' ) end end + context 'when a template is specified for /etc/issue.net' do let(:params) { { issue_net_template: 'motd/spec.epp' } } it do - is_expected.to contain_File('/etc/issue.net').with( - ensure: 'file', - backup: 'false', + expect(subject).to contain_File('/etc/issue.net').with( + ensure: 'file', backup: 'false', content: "Test Template for Rspec\n", - owner: 'bin', - group: 'bin', - mode: '0644', + owner: 'bin', group: 'bin', mode: '0644' ) end end diff --git a/spec/fixtures/module/spec/spec_helper.rb b/spec/fixtures/module/spec/spec_helper.rb index bc023f5..1a8b68b 100644 --- a/spec/fixtures/module/spec/spec_helper.rb +++ b/spec/fixtures/module/spec/spec_helper.rb @@ -9,11 +9,11 @@ require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) -include RspecPuppetFacts +include RspecPuppetFacts # rubocop:disable Style/MixinUsage default_facts = { puppetversion: Puppet.version, - facterversion: Facter.version, + facterversion: Facter.version } default_fact_files = [ @@ -26,7 +26,7 @@ begin default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) - rescue => e + rescue StandardError => e RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" end end @@ -42,11 +42,24 @@ # set to strictest setting for testing # by default Puppet runs at warning level Puppet.settings[:strict] = :warning + Puppet.settings[:strict_variables] = true end c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] c.after(:suite) do RSpec::Puppet::Coverage.report!(0) end + + # Filter backtrace noise + backtrace_exclusion_patterns = [ + %r{spec_helper}, + %r{gems}, + ] + + if c.respond_to?(:backtrace_exclusion_patterns) + c.backtrace_exclusion_patterns = backtrace_exclusion_patterns + elsif c.respond_to?(:backtrace_clean_patterns) + c.backtrace_clean_patterns = backtrace_exclusion_patterns + end end # Ensures that a module is defined diff --git a/spec/fixtures/module/spec/spec_helper_acceptance.rb b/spec/fixtures/module/spec/spec_helper_acceptance.rb index aabeb0b..4ac8d7e 100644 --- a/spec/fixtures/module/spec/spec_helper_acceptance.rb +++ b/spec/fixtures/module/spec/spec_helper_acceptance.rb @@ -1,82 +1,6 @@ # frozen_string_literal: true -require 'serverspec' require 'puppet_litmus' require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb')) -include PuppetLitmus -if ENV['TARGET_HOST'].nil? || ENV['TARGET_HOST'] == 'localhost' - puts 'Running tests against this machine !' - if Gem.win_platform? - set :backend, :cmd - else - set :backend, :exec - end -else - # load inventory - inventory_hash = inventory_hash_from_inventory_file - node_config = config_from_node(inventory_hash, ENV['TARGET_HOST']) - - if target_in_group(inventory_hash, ENV['TARGET_HOST'], 'docker_nodes') - host = ENV['TARGET_HOST'] - set :backend, :docker - set :docker_container, host - elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'ssh_nodes') - set :backend, :ssh - options = Net::SSH::Config.for(host) - options[:user] = node_config.dig('ssh', 'user') unless node_config.dig('ssh', 'user').nil? - options[:port] = node_config.dig('ssh', 'port') unless node_config.dig('ssh', 'port').nil? - options[:keys] = node_config.dig('ssh', 'private-key') unless node_config.dig('ssh', 'private-key').nil? - options[:password] = node_config.dig('ssh', 'password') unless node_config.dig('ssh', 'password').nil? - # Support both net-ssh 4 and 5. - # rubocop:disable Metrics/BlockNesting - options[:verify_host_key] = if node_config.dig('ssh', 'host-key-check').nil? - # Fall back to SSH behavior. This variable will only be set in net-ssh 5.3+. - if @strict_host_key_checking.nil? || @strict_host_key_checking - Net::SSH::Verifiers::Always.new - else - # SSH's behavior with StrictHostKeyChecking=no: adds new keys to known_hosts. - # If known_hosts points to /dev/null, then equivalent to :never where it - # accepts any key beacuse they're all new. - Net::SSH::Verifiers::AcceptNewOrLocalTunnel.new - end - elsif node_config.dig('ssh', 'host-key-check') - if defined?(Net::SSH::Verifiers::Always) - Net::SSH::Verifiers::Always.new - else - Net::SSH::Verifiers::Secure.new - end - elsif defined?(Net::SSH::Verifiers::Never) - Net::SSH::Verifiers::Never.new - else - Net::SSH::Verifiers::Null.new - end - # rubocop:enable Metrics/BlockNesting - host = if ENV['TARGET_HOST'].include?(':') - ENV['TARGET_HOST'].split(':').first - else - ENV['TARGET_HOST'] - end - set :host, options[:host_name] || host - set :ssh_options, options - set :request_pty, true - elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'winrm_nodes') - require 'winrm' - - set :backend, :winrm - set :os, family: 'windows' - user = node_config.dig('winrm', 'user') unless node_config.dig('winrm', 'user').nil? - pass = node_config.dig('winrm', 'password') unless node_config.dig('winrm', 'password').nil? - endpoint = "http://#{ENV['TARGET_HOST']}:5985/wsman" - - opts = { - user: user, - password: pass, - endpoint: endpoint, - operation_timeout: 300, - } - - winrm = WinRM::Connection.new opts - Specinfra.configuration.winrm = winrm - end -end +PuppetLitmus.configure! diff --git a/spec/fixtures/module/templates/motd.epp b/spec/fixtures/module/templates/motd.epp index 6353a04..c8e3d1a 100644 --- a/spec/fixtures/module/templates/motd.epp +++ b/spec/fixtures/module/templates/motd.epp @@ -1,6 +1,6 @@ -<%= $facts[operatingsystem] %> <%= $facts[operatingsystemrelease] %> <%= $facts[architecture] %> +<%= $facts[os][name] %> <%= $facts[os][release][full] %> <%= $facts[os][architecture] %> -FQDN: <%= $facts[fqdn] %> (<%= $facts[ipaddress] %>) -Processor: <%= $facts[processor0] %> +FQDN: <%= $facts[networking][fqdn] %> (<%= $facts[networking][ip] %>) +Processor: <%= $facts[processors][models][0] %> Kernel: <%= $facts[kernel] %> -Memory Size: <%= $facts[memorysize] %> +Memory Size: <%= $facts[memory][system][available] %> From 73b603c3bd0a7e9b9794baf60d1f7e64bb77ec37 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 12:34:01 +0100 Subject: [PATCH 22/25] (CONT-881) Update acceptance job name --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index feec48d..9265bcf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,7 @@ jobs: runs_on: - "ubuntu-latest" - "windows-latest" + name: "acceptance (${{ matrix.runs_on }} ruby ${{ matrix.ruby_version }} | puppet ${{matrix.puppet_gem_version}})" uses: "puppetlabs/cat-github-actions/.github/workflows/gem_acceptance.yml@main" secrets: "inherit" with: From fbd7ceff9bb759606a789dd40b275f408ef707a3 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 13:42:07 +0100 Subject: [PATCH 23/25] (CONT-881) Update ruby requirement --- puppet-modulebuilder.gemspec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/puppet-modulebuilder.gemspec b/puppet-modulebuilder.gemspec index bce8c22..890f3d9 100644 --- a/puppet-modulebuilder.gemspec +++ b/puppet-modulebuilder.gemspec @@ -9,7 +9,6 @@ Gem::Specification.new do |spec| spec.email = ['sheena@puppet.com', 'https://puppetlabs.github.io/iac/'] spec.summary = 'A gem to set up puppet-modulebuilder' spec.homepage = 'https://github.com/puppetlabs/puppet-modulebuilder' - spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0') spec.license = 'Apache-2.0' spec.metadata['homepage_uri'] = spec.homepage @@ -27,4 +26,6 @@ Gem::Specification.new do |spec| # minitar and pathspec is required for building Puppet modules spec.add_runtime_dependency 'minitar', '~> 0.9' spec.add_runtime_dependency 'pathspec', '>= 0.2.1', '< 2.0.0' + + spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0') end From e415693c53821286de157ea94e2262f6d28f26b4 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 13:42:25 +0100 Subject: [PATCH 24/25] (CONT-881) Add ffi gem for win platforms --- Gemfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Gemfile b/Gemfile index 12f8a4a..0fb61aa 100644 --- a/Gemfile +++ b/Gemfile @@ -32,4 +32,7 @@ group :development do gem 'simplecov' gem 'simplecov-console' + + # Required for testing on Windows + gem 'ffi', :platforms => [:x64_mingw] end From 3c943030be7895f85698dc70ba8c3cb612c0e40c Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Tue, 18 Apr 2023 13:57:55 +0100 Subject: [PATCH 25/25] (CONT-881) Clean up legacy files/entries --- .github/CODEOWNERS | 2 -- .github/dependabot.yml | 15 --------------- HISTORY.md | 3 --- README.md | 2 -- 4 files changed, 22 deletions(-) delete mode 100644 .github/CODEOWNERS delete mode 100644 .github/dependabot.yml delete mode 100644 HISTORY.md diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS deleted file mode 100644 index fcdf05a..0000000 --- a/.github/CODEOWNERS +++ /dev/null @@ -1,2 +0,0 @@ -# Setting ownership to the modules team -* @puppetlabs/modules @puppetlabs/pdk diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index c2cfd7b..0000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,15 +0,0 @@ -version: 2 -updates: -- package-ecosystem: bundler - directory: "/" - schedule: - interval: daily - time: "13:00" - open-pull-requests-limit: 10 - ignore: - - dependency-name: rake - versions: - - ">= 13.a, < 14" - - dependency-name: rubocop - versions: - - "> 0.68" diff --git a/HISTORY.md b/HISTORY.md deleted file mode 100644 index a4b43d7..0000000 --- a/HISTORY.md +++ /dev/null @@ -1,3 +0,0 @@ -## v0.1.0 - -This is the initial release of the project. diff --git a/README.md b/README.md index 1ce0a70..bdc5c58 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -[![Build Status](https://travis-ci.com/puppetlabs/puppet-modulebuilder.svg?branch=main)](https://travis-ci.com/puppetlabs/puppet-modulebuilder) [![Build status](https://ci.appveyor.com/api/projects/status/j9tosvq4a09iw0bx/branch/main?svg=true)](https://ci.appveyor.com/project/puppetlabs/puppet-modulebuilder/branch/main) - # Puppet::Modulebuilder The `puppet-modulebuilder` gem contains the reference implementation for building Puppet modules from source.