From dbf68dcaca6ef4b2b28af1a73d6fd3db521b32dc Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Mon, 21 Aug 2023 13:30:05 +0100 Subject: [PATCH] Adds Release workflow - Release gem to GitHub - Bumps version using please-release - Use the standard Rakefile Remove changelog generator and docs that we are no longer using Signed-off-by: Dan Webb --- .github/CODEOWNERS | 1 + .github/dependabot.yml | 19 +++++---- .github/workflows/ci.yml | 8 ++-- .github/workflows/linters.yml | 8 ++++ .github/workflows/please-release.yml | 16 +++++++ .github/workflows/publish.yml | 17 ++++++++ .kitchen.appveyor.yml | 2 +- .kitchen.yml | 6 +-- .markdownlint-cli2.yaml | 4 ++ .yamllint | 15 +++++++ CHANGELOG.md | 2 - Gemfile | 11 ++--- README.md | 39 +++++++++++------ Rakefile | 62 ++++++---------------------- azure-pipelines.yml | 8 ++-- kitchen-pester.gemspec | 5 +-- spec/pester/pester_spec.rb | 22 +++++----- 17 files changed, 139 insertions(+), 106 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/linters.yml create mode 100644 .github/workflows/please-release.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .markdownlint-cli2.yaml create mode 100644 .yamllint diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..b7175b0 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +@test-kitchen/maintainers diff --git a/.github/dependabot.yml b/.github/dependabot.yml index e828072..528b325 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,11 +1,12 @@ +--- version: 2 updates: -- package-ecosystem: bundler - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 - ignore: - - dependency-name: github_changelog_generator - versions: - - 1.16.0 + - package-ecosystem: bundler + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 + ignore: + - dependency-name: github_changelog_generator + versions: + - 1.16.0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b503b8d..3c83967 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ +--- name: CI - -on: +"on": pull_request: push: branches: @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby: [ '2.6', '2.7', '3.0'] + ruby: ["2.6", "2.7", "3.0"] name: Lint & Test with Ruby ${{ matrix.ruby }} steps: - uses: actions/checkout@v2 @@ -19,4 +19,4 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - run: bundle exec rake + - run: bundle exec rake diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml new file mode 100644 index 0000000..2e5e9d1 --- /dev/null +++ b/.github/workflows/linters.yml @@ -0,0 +1,8 @@ +--- +name: 'Test' +'on': + pull_request: + +jobs: + lint-unit: + uses: test-kitchen/.github/.github/workflows/lint-unit.yml@main diff --git a/.github/workflows/please-release.yml b/.github/workflows/please-release.yml new file mode 100644 index 0000000..e376f06 --- /dev/null +++ b/.github/workflows/please-release.yml @@ -0,0 +1,16 @@ +--- +"on": + push: + branches: + - main + +name: release-please +jobs: + release-please: + runs-on: ubuntu-latest + steps: + - uses: google-github-actions/release-please-action@v3 + with: + release-type: ruby + package-name: kitchen-vra + version-file: lib/kitchen/driver/vra_version.rb diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..a3d7b1b --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,17 @@ +--- +name: Publish + +'on': + release: + types: [published] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build and publish gem + uses: jstastny/publish-gem-to-github@master + with: + token: ${{ secrets.GITHUB_TOKEN }} + owner: ${{ secrets.OWNER }} diff --git a/.kitchen.appveyor.yml b/.kitchen.appveyor.yml index 51f5121..acfa435 100644 --- a/.kitchen.appveyor.yml +++ b/.kitchen.appveyor.yml @@ -12,7 +12,7 @@ provisioner: script: provision.ps1 platforms: -- name: windows-2012R2 + - name: windows-2012R2 verifier: name: pester diff --git a/.kitchen.yml b/.kitchen.yml index 7c5e388..15c2e85 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -7,9 +7,9 @@ provisioner: script: provision.ps1 platforms: -- name: windows-2016 - driver_config: - box: stefanscherer/windows_2016 + - name: windows-2016 + driver_config: + box: stefanscherer/windows_2016 verifier: name: pester diff --git a/.markdownlint-cli2.yaml b/.markdownlint-cli2.yaml new file mode 100644 index 0000000..0cb05b4 --- /dev/null +++ b/.markdownlint-cli2.yaml @@ -0,0 +1,4 @@ +config: + ul-indent: false # MD007 + line-length: false # MD013 + no-duplicate-heading: false # MD024 diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..0046b23 --- /dev/null +++ b/.yamllint @@ -0,0 +1,15 @@ +--- +extends: default +rules: + line-length: + max: 256 + level: warning + document-start: disable + braces: + forbid: false + min-spaces-inside: 0 + max-spaces-inside: 1 + min-spaces-inside-empty: -1 + max-spaces-inside-empty: -1 + comments: + min-spaces-from-content: 1 diff --git a/CHANGELOG.md b/CHANGELOG.md index f1b7a59..18411d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -165,6 +165,4 @@ - Support for PowerShell 2 [\#5](https://github.com/test-kitchen/kitchen-pester/pull/5) ([smurawski](https://github.com/smurawski)) - Default to progress preference of silentlycontinue [\#4](https://github.com/test-kitchen/kitchen-pester/pull/4) ([smurawski](https://github.com/smurawski)) - - \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* diff --git a/Gemfile b/Gemfile index 28312ef..ea03e19 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,5 @@ source "https://rubygems.org" -# Specify your gem's dependencies in kitchen-pester.gemspec gemspec group :integration do @@ -10,16 +9,18 @@ group :integration do gem "kitchen-chocolatey" end -group :changelog do - gem "github_changelog_generator", "1.16.4" -end - group :debug do gem "pry", "~>0.13.1" gem "pry-byebug", "~>3.9.0" gem "pry-stack_explorer" end +group :development do + gem "rake", ">= 11.0" + # gem "minitest"#, "~> 5.3", "< 5.16" # Commented out as these tests are not run + # gem "mocha"#, "~> 1.1" +end + group :chefstyle do gem "chefstyle" end diff --git a/README.md b/README.md index c376b71..4f4c118 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ +# Kitchen::Pester + [![Build Status](https://dev.azure.com/test-kitchen/kitchen-pester/_apis/build/status/test-kitchen.kitchen-pester?branchName=main)](https://dev.azure.com/test-kitchen/kitchen-pester/_build/latest?definitionId=4&branchName=main) [![Gem Version](https://badge.fury.io/rb/kitchen-pester.svg)](http://badge.fury.io/rb/kitchen-pester) -# Kitchen::Pester - Execute [Pester](https://github.com/pester/Pester) tests, cross platform, right from Test-Kitchen, without having to transit the Busser layer. For now, this gem hasn't been tested with Pester v5+. @@ -10,20 +10,26 @@ For now, this gem hasn't been tested with Pester v5+. ## Usage Either -``` + +```shell gem install kitchen-pester ``` + or include -``` + +```ruby gem 'kitchen-pester' ``` + in your Gemfile. In your .kitchen.yml include + ```yaml verifier: name: pester ``` + This can be a top-level declaration, a per-node declaration, or a per-suite declaration. ## Options @@ -55,6 +61,7 @@ Note that it needs to be able to download the nupkg from `$galleryUrl/package/Po * `register_repository` - array (of maps), default is `[]` Allows you to register PSRepositories to download modules from. Useful when you want to use a private feed. This expects a map for each repository to register, the values will be splatted to `Register-PSRepository` (or `Set-PSRepository` if it already exists). + ```yaml register_repository: - Name: MyPrivateNuget @@ -66,6 +73,7 @@ This expects a map for each repository to register, the values will be splatted * `install_modules` - array (of maps), default is `[]` Array of maps, that will be splatted to the Install-Module parameters. Useful for installing dependencies from a gallery. + ```yaml install_modules: - Name: MyModule @@ -77,6 +85,7 @@ Useful for installing dependencies from a gallery. Folders (relative to the current directory or absolute) to copy to the System Under Test (SUT). The SUT's `$env:PSModulePath` will have the parent folder prepended for the session. If you are testing a PowerShell module you have built as part of your build process, this enables you to copy the module folder directly to the target machine. + ```yaml verifier: name: pester @@ -89,8 +98,8 @@ If you are testing a PowerShell module you have built as part of your build proc * `skip_pester_install` - bool default is `false` Skip installing pester and just use what's available on the box, or what you have copied with the `copy_folders` options. - * `pester_install` - map, default is + ```ruby { SkipPublisherCheck: true, @@ -98,11 +107,13 @@ Skip installing pester and just use what's available on the box, or what you hav ErrorAction: "Stop", } ``` + Specify parameters for installing Pester before running the tests. The map will be splatted to the `Install-Module -Name Pester` command. You can use this to install the module from a private gallery, for instance. * `pester_configuration` - hash, defaults to + ```ruby { run: { @@ -122,17 +133,17 @@ You can use this to install the module from a private gallery, for instance. This object is converted to a hashtable used to create a PesterConfiguration object in **Pester v5** (`$PesterConfig = New-PesterConfiguration -Hashtable $pester_configuration`), in turn used with invoke pester (`Invoke-Pester -Configuration $PesterConfig`). If some of the following **keys** are missing, the associated defaults below will be used: - - **Run.Path** = `$Env:Temp/verifier/suites` - - **TestResult.TestSuiteName** = `Pester - $KitchenInstanceName` - - **TestResult.OutputPath** = `$Env:Temp/verifier/PesterTestResults.xml` + * **Run.Path** = `$Env:Temp/verifier/suites` + * **TestResult.TestSuiteName** = `Pester - $KitchenInstanceName` + * **TestResult.OutputPath** = `$Env:Temp/verifier/PesterTestResults.xml` If the installed version of Pester is **v4**, and the `pester_configuration` hash is provided, valid parameters for `Invoke-Pester` will be used (and invalid parameter names will be ignored). In the case of Pester v4, and the `pester_configuration` hash does not provide the keys for `Script`,`OutputFile`,`OutputFormat`, `Passthru`, `PesterOption`, the defaults will be: - - Script: `$Env:Temp/verifier/suites` - - OutPutFile: `$Env:Temp/verifier/PesterTestResults.xml` - - OutputFormat: `NUnitXml` - - Passthru: `true` - - PesterOption: the result of `$(New-PesterOption -TestSuiteName "Pester - $KitchenInstanceName)` + * Script: `$Env:Temp/verifier/suites` + * OutPutFile: `$Env:Temp/verifier/PesterTestResults.xml` + * OutputFormat: `NUnitXml` + * Passthru: `true` + * PesterOption: the result of `$(New-PesterOption -TestSuiteName "Pester - $KitchenInstanceName)` * `shell` - string, default is `Nil` which makes it call PowerShell on Windows (Windows PowerShell), pwsh on other OSes. It will honour the `sudo` configuration property if set to true on non-windows. @@ -161,6 +172,7 @@ The key is the remote file to download, while the value is the destination. * `environment` - map[string, string], defaults to `{}`. Environment variables to set in SUT for your pester tests to access. + ```yaml environment: API_KEY: api-key-here @@ -176,6 +188,7 @@ Environment variables to set in SUT for your pester tests to access. If you're testing on a default image of Windows Server 2019, you probably need to replace the builtin Pester module (v3.4.0), and replace the builtin PackageManagement and PowerShellGet to a more recent for the install to work. Assuming your tests are written for Peter v4, here's a sample configuration: + ```yaml verifier: name: pester diff --git a/Rakefile b/Rakefile index be8a7db..b1bef59 100644 --- a/Rakefile +++ b/Rakefile @@ -1,57 +1,19 @@ require "bundler/gem_tasks" +require "chefstyle" +require "rubocop/rake_task" +require "rspec/core/rake_task" -require "rake/testtask" -Rake::TestTask.new(:unit) do |t| - t.libs.push "lib" - t.test_files = FileList["spec/**/*_spec.rb"] - t.verbose = true +RuboCop::RakeTask.new(:style) do |task| + task.options += ["--display-cop-names", "--no-color"] end -task test: :unit +RSpec::Core::RakeTask.new(:test) -begin - require "chefstyle" - require "rubocop/rake_task" - RuboCop::RakeTask.new(:style) do |task| - task.options += ["--display-cop-names", "--no-color"] - end -rescue LoadError - puts "chefstyle is not available. (sudo) gem install chefstyle to do style checking." +RSpec::Core::RakeTask.new do |task| + # test_dir = Rake.application.original_dir + # task.pattern = "#{test_dir}/*_spec.rb" + # task.rspec_opts = [ "-I#{test_dir}", "-I#{test_dir}/source", '-f documentation', '-r ./rspec_config'] + task.verbose = false end -desc "Run all quality tasks" -task quality: :style - -begin - require "yard" unless defined?(YARD) - YARD::Rake::YardocTask.new -rescue LoadError - puts "yard is not available. (sudo) gem install yard to generate yard documentation." -end - -task default: %i{test quality} - -begin - require "github_changelog_generator/task" - require "kitchen/verifier/pester_version" - - GitHubChangelogGenerator::RakeTask.new :changelog do |config| - config.future_release = "v#{Kitchen::Verifier::PESTER_VERSION}" - config.issues = false - config.pulls = true - config.user = "test-kitchen" - config.project = "kitchen-pester" - end -rescue LoadError - puts "github_changelog_generator is not available." \ - " (sudo) gem install github_changelog_generator to generate changelogs" -end - -namespace :docs do - desc "Deploy docs" - task :deploy do - sh "cd docs && hugo" - sh "aws --profile chef-cd s3 sync docs/public s3://test-kitchen-legacy.cd.chef.co --delete --acl public-read" - sh "aws --profile chef-cd cloudfront create-invalidation --distribution-id EQD8MRW086SRT --paths '/*'" - end -end +task default: %i{test style} diff --git a/azure-pipelines.yml b/azure-pipelines.yml index aaa389e..d488f1f 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -6,7 +6,7 @@ trigger: batch: true branches: include: - - main + - main pr: autoCancel: true @@ -22,7 +22,7 @@ stages: matrix: Windows_Integration: version: 2.6 - imageName: 'windows-2019' + imageName: "windows-2019" task: windows_integration.bat machine_user: test_user machine_pass: Pass@word1 @@ -62,12 +62,12 @@ stages: - task: PublishTestResults@2 inputs: testResultsFormat: NUnit - testResultsFiles: 'testresults/**/PesterTestResults.xml' + testResultsFiles: "testresults/**/PesterTestResults.xml" - job: Package dependsOn: Validate condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/main'), notIn(variables['Build.Reason'], 'PullRequest')) pool: - imageName: 'ubuntu-16.04' + imageName: "ubuntu-16.04" steps: - task: UseRubyVersion@0 inputs: diff --git a/kitchen-pester.gemspec b/kitchen-pester.gemspec index ff8498a..f06b368 100644 --- a/kitchen-pester.gemspec +++ b/kitchen-pester.gemspec @@ -16,9 +16,6 @@ Gem::Specification.new do |spec| spec.files = %w{LICENSE kitchen-pester.gemspec Gemfile Rakefile} + Dir.glob("lib/**/*") spec.require_paths = ["lib"] - spec.add_development_dependency "rake" - spec.add_development_dependency "minitest", "~> 5.3", "< 5.16" - spec.add_development_dependency "mocha", "~> 1.1" - + spec.required_ruby_version = ">= 2.7" spec.add_dependency "test-kitchen", ">= 1.10", "< 4" end diff --git a/spec/pester/pester_spec.rb b/spec/pester/pester_spec.rb index 345b9a1..a724730 100644 --- a/spec/pester/pester_spec.rb +++ b/spec/pester/pester_spec.rb @@ -1,18 +1,18 @@ -gem "minitest" -require "minitest/autorun" -require "mocha/setup" +# gem "minitest" +# require "minitest/autorun" +# require "mocha/setup" require_relative "../../lib/kitchen/verifier/pester" -class MockPester < Kitchen::Verifier::Pester - def sandbox_path - "C:/users/jdoe/temp/kitchen-temp" - end +# class MockPester < Kitchen::Verifier::Pester +# def sandbox_path +# "C:/users/jdoe/temp/kitchen-temp" +# end - def suite_test_folder - "C:/lowercasedpath/pester/tests" - end -end +# def suite_test_folder +# "C:/lowercasedpath/pester/tests" +# end +# end # describe "when sandboxifying a path" do # let(:sandboxifiedPath) do