Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Release workflow #98

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@test-kitchen/maintainers
19 changes: 10 additions & 9 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: CI

on:
"on":
pull_request:
push:
branches:
Expand All @@ -11,12 +11,12 @@ 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
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: bundle exec rake
- run: bundle exec rake
8 changes: 8 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: 'Test'
'on':
pull_request:

jobs:
lint-unit:
uses: test-kitchen/.github/.github/workflows/lint-unit.yml@main
16 changes: 16 additions & 0 deletions .github/workflows/please-release.yml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 1 addition & 1 deletion .kitchen.appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ provisioner:
script: provision.ps1

platforms:
- name: windows-2012R2
- name: windows-2012R2

verifier:
name: pester
Expand Down
6 changes: 3 additions & 3 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions .markdownlint-cli2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
config:
ul-indent: false # MD007
line-length: false # MD013
no-duplicate-heading: false # MD024
15 changes: 15 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)*
11 changes: 6 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
source "https://rubygems.org"

# Specify your gem's dependencies in kitchen-pester.gemspec
gemspec

group :integration do
Expand All @@ -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
Expand Down
39 changes: 26 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
# 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+.

## 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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -89,20 +98,22 @@ 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,
Force: true,
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: {
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
62 changes: 12 additions & 50 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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}
Loading
Loading