diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 00000000..cb781ef2 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,23 @@ +fixtures: + forge_modules: + powershellget: + repo: 'dsc/powershellget' + ref: '2.2.5-0-1' + jeadsc: + repo: 'dsc/jeadsc' + ref: '0.7.2-0-3' + xpsdesiredstateconfiguration: + repo: 'dsc/xpsdesiredstateconfiguration' + ref: '9.1.0-0-1' + xwebadministration: + repo: 'dsc/xwebadministration' + ref: '3.2.0-0-2' + accesscontroldsc: + repo: 'dsc/accesscontroldsc' + ref: '1.4.1-0-3' + repositories: + facts: 'https://github.com/puppetlabs/puppetlabs-facts.git' + puppet_agent: + repo: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' + ref: v4.13.0 + provision: 'https://github.com/puppetlabs/provision.git' diff --git a/.github/matrix.json b/.github/matrix.json new file mode 100644 index 00000000..130b7db8 --- /dev/null +++ b/.github/matrix.json @@ -0,0 +1,7 @@ +[ + { + "label":"Windows-2022", + "provider":"provision_service", + "image":"windows-2022" + } +] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb6b2d7d..90f55661 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,28 +29,13 @@ jobs: uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main" secrets: "inherit" with: - rake_task: "spec:coverage" + rake_task: "spec:simplecov" ruby_version: ${{ matrix.ruby_version }} puppet_gem_version: ${{ matrix.puppet_version }} acceptance: - needs: "spec" - strategy: - matrix: - ruby_version: - - "2.7" - - "3.2" - include: - - ruby-version: '2.7' - puppet_version: '~> 7.0' - - ruby_version: '3.2' - puppet_version: '~> 8.0' - runs_on: - - "windows-latest" - name: "acceptance (${{ matrix.runs_on}} ruby ${{ matrix.ruby_version }} | puppet ${{ matrix.puppet_version }})" - uses: "./.github/workflows/custom_acceptance.yml" + needs: spec + uses: "puppetlabs/cat-github-actions/.github/workflows/module_acceptance.yml@main" secrets: "inherit" with: - ruby_version: ${{ matrix.ruby_version }} - puppet_version: ${{ matrix.puppet_version }} - runs_on: ${{ matrix.runs_on }} + flags: '--custom-matrix ./.github/matrix.json' diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 4acc4f6b..feffc85e 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -26,23 +26,8 @@ jobs: puppet_gem_version: ${{ matrix.puppet_version }} acceptance: - needs: "spec" - strategy: - matrix: - ruby_version: - - "2.7" - - "3.2" - include: - - ruby-version: '2.7' - puppet_version: '~> 7.0' - - ruby_version: '3.2' - puppet_version: '~> 8.0' - runs_on: - - "windows-latest" - name: "acceptance (${{ matrix.runs_on}} ruby ${{ matrix.ruby_version }} | puppet ${{ matrix.puppet_version }})" - uses: "./.github/workflows/custom_acceptance.yml" + needs: spec + uses: "puppetlabs/cat-github-actions/.github/workflows/module_acceptance.yml@main" secrets: "inherit" with: - ruby_version: ${{ matrix.ruby_version }} - puppet_version: ${{ matrix.puppet_version }} - runs_on: ${{ matrix.runs_on }} + flags: '--custom-matrix ./.github/matrix.json' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 11f40c40..65ccecd8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-01-30 16:36:55 UTC using RuboCop version 1.50.2. +# on 2024-03-04 12:06:29 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 @@ -32,28 +32,28 @@ Lint/IncompatibleIoSelectWithFiberScheduler: Exclude: - 'lib/pwsh.rb' -# Offense count: 17 +# Offense count: 16 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: - Max: 83 + Max: 63 -# Offense count: 2 +# Offense count: 1 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. # AllowedMethods: refine Metrics/BlockLength: - Max: 35 + Max: 28 -# Offense count: 2 +# Offense count: 1 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 553 + Max: 296 # Offense count: 12 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/CyclomaticComplexity: Max: 24 -# Offense count: 23 +# Offense count: 22 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: Max: 42 @@ -88,17 +88,17 @@ RSpec/BeforeAfterAll: - 'spec/spec_helper.rb' - 'spec/rails_helper.rb' - 'spec/support/**/*.rb' - - 'spec/acceptance/dsc/basic.rb' + - 'spec/acceptance/dsc/basic_spec.rb' # Offense count: 26 # Configuration parameters: Prefixes, AllowedPatterns. # Prefixes: when, with, without RSpec/ContextWording: Exclude: - - 'spec/acceptance/dsc/basic.rb' - - 'spec/acceptance/dsc/cim_instances.rb' - - 'spec/acceptance/dsc/class.rb' - - 'spec/acceptance/dsc/complex.rb' + - 'spec/acceptance/dsc/basic_spec.rb' + - 'spec/acceptance/dsc/cim_instances_spec.rb' + - 'spec/acceptance/dsc/class_spec.rb' + - 'spec/acceptance/dsc/complex_spec.rb' - 'spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb' - 'spec/unit/pwsh/windows_powershell_spec.rb' - 'spec/unit/pwsh_spec.rb' @@ -112,18 +112,18 @@ RSpec/DescribeClass: - '**/spec/routing/**/*' - '**/spec/system/**/*' - '**/spec/views/**/*' - - 'spec/acceptance/dsc/basic.rb' - - 'spec/acceptance/dsc/cim_instances.rb' - - 'spec/acceptance/dsc/class.rb' - - 'spec/acceptance/dsc/complex.rb' + - 'spec/acceptance/dsc/basic_spec.rb' + - 'spec/acceptance/dsc/cim_instances_spec.rb' + - 'spec/acceptance/dsc/class_spec.rb' + - 'spec/acceptance/dsc/complex_spec.rb' - 'spec/unit/pwsh_spec.rb' -# Offense count: 32 +# Offense count: 34 # Configuration parameters: CountAsOne. RSpec/ExampleLength: Max: 70 -# Offense count: 105 +# Offense count: 125 # Configuration parameters: . # SupportedStyles: have_received, receive RSpec/MessageSpies: @@ -138,7 +138,7 @@ RSpec/MultipleDescribes: RSpec/MultipleExpectations: Max: 15 -# Offense count: 107 +# Offense count: 108 # Configuration parameters: AllowSubject. RSpec/MultipleMemoizedHelpers: Max: 17 @@ -156,14 +156,14 @@ RSpec/NoExpectationExample: - 'spec/unit/pwsh/windows_powershell_spec.rb' - 'spec/unit/pwsh_spec.rb' -# Offense count: 56 +# Offense count: 62 RSpec/StubbedMock: Exclude: - 'spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb' - 'spec/unit/pwsh/util_spec.rb' - 'spec/unit/pwsh/windows_powershell_spec.rb' -# Offense count: 65 +# Offense count: 68 RSpec/SubjectStub: Exclude: - 'spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb' diff --git a/Rakefile b/Rakefile index 123aafef..ce2bd00f 100644 --- a/Rakefile +++ b/Rakefile @@ -6,16 +6,12 @@ require 'fileutils' require 'open3' require 'pwsh/version' require 'rspec/core/rake_task' +require 'puppet_litmus/rake_tasks' +require 'puppetlabs_spec_helper/rake_tasks' require 'yard' -RSpec::Core::RakeTask.new(:spec) do |t| - t.pattern = 'spec/unit/**/*_spec.rb' -end -task default: :spec - namespace :spec do - desc 'Run RSpec code examples with coverage collection' - task :coverage do + task :simplecov do ENV['COVERAGE'] = 'yes' Rake::Task['spec'].execute end @@ -23,107 +19,3 @@ end YARD::Rake::YardocTask.new do |t| end -# Used in vendor_dsc_module -TAR_LONGLINK = '././@LongLink' - -# Vendor a Puppetized DSC Module to spec/fixtures/modules. -# -# This is necessary because `puppet module install` fails on modules with -# long file paths, like xpsdesiredstateconfiguration -# -# @param command [String] command to execute. -# @return [Object] the standard out stream. -def vendor_dsc_module(name, version, destination) - require 'open-uri' - require 'rubygems/package' - require 'zlib' - - module_uri = "https://forge.puppet.com/v3/files/dsc-#{name}-#{version}.tar.gz" - tar_gz_archive = File.expand_path("#{name}.tar.gz", ENV['TEMP']) - - # Download the archive from the forge - File.open(tar_gz_archive, 'wb') do |file| - file.write(URI.open(module_uri).read) # rubocop:disable Security/Open - end - - # Unzip to destination - # Taken directly from StackOverflow: - # - https://stackoverflow.com/a/19139114 - Gem::Package::TarReader.new(Zlib::GzipReader.open(tar_gz_archive)) do |tar| - dest = nil - tar.each do |entry| - if entry.full_name == TAR_LONGLINK - dest = File.join(destination, entry.read.strip) - next - end - dest ||= File.join(destination, entry.full_name) - if entry.directory? - File.delete(dest) if File.file?(dest) - FileUtils.mkdir_p(dest, mode: entry.header.mode, verbose: false) - elsif entry.file? - FileUtils.rm_rf(dest) if File.directory?(dest) - File.open(dest, 'wb') do |f| - f.print(entry.read) - end - FileUtils.chmod(entry.header.mode, dest, verbose: false) - elsif entry.header.typeflag == '2' # Symlink! - File.symlink(entry.header.linkname, dest) - end - dest = nil - end - end - - # Rename folder to just the module name, as needed by Puppet - Dir.glob("#{destination}/*#{name}*").each do |existing_folder| - new_folder = File.expand_path(name, destination) - FileUtils.mv(existing_folder, new_folder) - end -end - -# Ensure that winrm is configured on the target system. -# -# @return [Object] The result of the command execution. -def configure_winrm - return unless Gem.win_platform? - - command = 'pwsh.exe -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -File "spec/acceptance/support/setup_winrm.ps1"' - system(command) -rescue StandardError => e - puts "Failed to configure WinRM: #{e}" - exit 1 -end - -RSpec::Core::RakeTask.new(:acceptance) do |t| - t.pattern = 'spec/acceptance/dsc/*.rb' - end - -namespace :acceptance do - desc 'Prep for running DSC acceptance tests' - task :spec_prep do - # Create the modules fixture folder, if needed - modules_folder = File.expand_path('spec/fixtures/modules', File.dirname(__FILE__)) - FileUtils.mkdir_p(modules_folder) unless Dir.exist?(modules_folder) - # symlink the parent folder to the modules folder for puppet - symlink_path = File.expand_path('pwshlib', modules_folder) - File.symlink(File.dirname(__FILE__), symlink_path) unless Dir.exist?(symlink_path) - # Install each of the required modules for acceptance testing - # Note: This only works for modules in the dsc namespace on the forge. - puppetized_dsc_modules = [ - { name: 'powershellget', version: '2.2.5-0-1' }, - { name: 'jeadsc', version: '0.7.2-0-3' }, - { name: 'xpsdesiredstateconfiguration', version: '9.1.0-0-1' }, - { name: 'xwebadministration', version: '3.2.0-0-2' }, - { name: 'accesscontroldsc', version: '1.4.1-0-3' } - ] - puppetized_dsc_modules.each do |puppet_module| - next if Dir.exist?(File.expand_path(puppet_module[:name], modules_folder)) - - vendor_dsc_module(puppet_module[:name], puppet_module[:version], modules_folder) - end - - # Configure WinRM for acceptance tests - configure_winrm - end -end - -task :acceptance => 'acceptance:spec_prep' diff --git a/spec/acceptance/dsc/basic.rb b/spec/acceptance/dsc/basic_spec.rb similarity index 100% rename from spec/acceptance/dsc/basic.rb rename to spec/acceptance/dsc/basic_spec.rb diff --git a/spec/acceptance/dsc/cim_instances.rb b/spec/acceptance/dsc/cim_instances_spec.rb similarity index 100% rename from spec/acceptance/dsc/cim_instances.rb rename to spec/acceptance/dsc/cim_instances_spec.rb diff --git a/spec/acceptance/dsc/class.rb b/spec/acceptance/dsc/class_spec.rb similarity index 100% rename from spec/acceptance/dsc/class.rb rename to spec/acceptance/dsc/class_spec.rb diff --git a/spec/acceptance/dsc/complex.rb b/spec/acceptance/dsc/complex_spec.rb similarity index 100% rename from spec/acceptance/dsc/complex.rb rename to spec/acceptance/dsc/complex_spec.rb