Skip to content

Commit

Permalink
feat: Workflows (#10)
Browse files Browse the repository at this point in the history
* fix: Configure renovate, Rubocop & release workflow

- BREAKING CHANGE: Require Ruby 3.1
- Add test workflow
- Add release workflow

Signed-off-by: Dan Webb <dan.webb@damacus.io>

* feat: Add workflows

Signed-off-by: Dan Webb <dan.webb@damacus.io>

---------

Signed-off-by: Dan Webb <dan.webb@damacus.io>
  • Loading branch information
damacus committed Nov 27, 2023
1 parent 1b5439b commit 3f51d13
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 90 deletions.
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
9 changes: 9 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name: Lint & Unit

"on":
pull_request:

jobs:
lint-unit:
uses: test-kitchen/.github/.github/workflows/lint-unit.yml@v0.1.2
35 changes: 35 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: release-please

"on":
push:
branches: [main]

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: ruby
package-name: kitchen-vro
version-file: lib/kitchen/driver/vro_version.rb
token: ${{ secrets.PORTER_GITHUB_TOKEN }}

- name: Checkout
uses: actions/checkout@v4
if: ${{ steps.release.outputs.release_created }}

- name: Build and publish to GitHub Package
uses: actionshub/publish-gem-to-github@main
if: ${{ steps.release.outputs.release_created }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
owner: ${{ secrets.OWNER }}

- name: Build and publish to RubyGems
uses: actionshub/publish-gem-to-rubygems@main
if: ${{ steps.release.outputs.release_created }}
with:
token: ${{ secrets.RUBYGEMS_API_KEY }}
8 changes: 8 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
default: true
MD013: false
MD024: false
MD026: false
MD036: false
MD012: false
MD029: false
MD004: false
26 changes: 10 additions & 16 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
Metrics/AbcSize:
Max: 50
Metrics/ClassLength:
Max: 125
Metrics/LineLength:
Max: 130
Metrics/MethodLength:
Max: 25
Metrics/BlockLength:
---
require:
- chefstyle

AllCops:
TargetRubyVersion: 3.1
Include:
- "**/*.rb"
Exclude:
- 'spec/vro_spec.rb'
Style/Documentation:
Enabled: false
Style/SignalException:
Enabled: false
Style/SpaceInsideBrackets:
Enabled: false
- "vendor/**/*"
- "spec/**/*"
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

12 changes: 11 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
source 'https://rubygems.org'

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

group :test do
gem 'bundler'
gem 'rake'
gem 'rspec', '~> 3.2'
gem 'webmock', '~> 1.21'
end

group :chefstyle do
gem 'chefstyle', '~> 2.2', '>= 2.2.3'
end
42 changes: 24 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ gem 'kitchen-vro'

And then execute:

$ bundle
```shell
bundle
```

Or install it yourself as:

$ gem install kitchen-vro
```shell
gem install kitchen-vro
```

Or even better, install it via ChefDK:

$ chef gem install kitchen-vro
```shell
chef gem install kitchen-vro
```

## Usage

Expand All @@ -43,21 +49,21 @@ driver:

Additionally, the following parameters are required, either globally or per-platform:

* **create_workflow_name**: The name of the vRO workflow to execute to create a server.
* **destroy_workflow_name**: The name of the vRO workflow to execute to destroy a server.
* **create_workflow_name**: The name of the vRO workflow to execute to create a server.
* **destroy_workflow_name**: The name of the vRO workflow to execute to destroy a server.

There are a number of optional parameters you can configure as well:

* **create_workflow_id**: If your create workflow name is not unique within vRO, you can use
* **create_workflow_id**: If your create workflow name is not unique within vRO, you can use
this parameter to specify the workflow unique ID.
* **destroy_workflow_id**: If your destroy workflow name is not unique within vRO, you can use
* **destroy_workflow_id**: If your destroy workflow name is not unique within vRO, you can use
this parameter to specify the workflow unique ID.
* **create_workflow_parameters**: A hash of key-value pairs of parameters to pass to your
* **create_workflow_parameters**: A hash of key-value pairs of parameters to pass to your
create workflow.
* **destroy_workflow_parameters**: A hash of key-value pairs of parameters to pass to your
* **destroy_workflow_parameters**: A hash of key-value pairs of parameters to pass to your
destroy workflow.
* **request_timeout**: Number of seconds to wait for a vRO workflow to execute. Default: 300
* **vro_disable_ssl_verify**: Disable SSL validation. Default: false
* **request_timeout**: Number of seconds to wait for a vRO workflow to execute. Default: 300
* **vro_disable_ssl_verify**: Disable SSL validation. Default: false

An example `.kitchen.yml` that uses a combination of global and per-platform
settings might look like this:
Expand Down Expand Up @@ -93,20 +99,20 @@ they must meet the following requirements.

### Create Workflow

* Must contain an output parameter called `ip_address` that Test Kitchen can
* Must contain an output parameter called `ip_address` that Test Kitchen can
connect to in order to bootstrap and test your node.
* Must contain an output parameter called `server_id` that is a unique ID of
* Must contain an output parameter called `server_id` that is a unique ID of
the server created. Test Kitchen will provide this value to the Destroy
Workflow in order to request the destruction of the server once testing is
complete.
* Must end the workflow with a raised exception if the creation did not
* Must end the workflow with a raised exception if the creation did not
succeed. The workflow status must not be 'completed.'

### Destroy Workflow

* Must contain an input parameter called `server_id` that Test Kitchen will
* Must contain an input parameter called `server_id` that Test Kitchen will
populate with the unique ID returned from the Create Workflow output.
* Must end the workflow with a raised exception if the creation did not
* Must end the workflow with a raised exception if the creation did not
succeed. The workflow status must not be 'completed.'

## License and Authors
Expand All @@ -120,7 +126,7 @@ License:: Apache License, Version 2.0
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the License at

```
```text
http://www.apache.org/licenses/LICENSE-2.0
```

Expand All @@ -133,7 +139,7 @@ and limitations under the License.

We'd love to hear from you if this doesn't perform in the manner you expect. Please log a GitHub issue, or even better, submit a Pull Request with a fix!

1. Fork it ( https://github.com/chef-partners/kitchen-vro/fork )
1. Fork it ( <https://github.com/chef-partners/kitchen-vro/fork> )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
Expand Down
20 changes: 14 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new(:style)
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."
end

task default: %i[spec style]
RSpec::Core::RakeTask.new(:test)

task default: %i{test style}
29 changes: 11 additions & 18 deletions kitchen-vro.gemspec
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
# coding: utf-8

lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'kitchen/driver/vro_version'
require "kitchen/driver/vro_version"

Gem::Specification.new do |spec|
spec.name = 'kitchen-vro'
spec.name = "kitchen-vro"
spec.version = Kitchen::Driver::VRO_VERSION
spec.authors = ['Chef Partner Engineering']
spec.email = ['partnereng@chef.io']
spec.summary = 'A Test Kitchen driver for VMware vRealize Orchestrator (vRO)'
spec.authors = ["Test Kitchen Team"]
spec.email = ["help@sous-chefs.org"]
spec.summary = "A Test Kitchen driver for VMware vRealize Orchestrator (vRO)"
spec.description = spec.summary
spec.homepage = 'https://github.com/chef-partners/kitchen-vro'
spec.license = 'Apache 2.0'
spec.homepage = "https://https://github.com/test-kitchen/kitchen-vro"
spec.license = "Apache 2.0"

spec.files = `git ls-files -z`.split("\x0")
spec.executables = []
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_dependency 'test-kitchen', '~> 1.4', '>= 1.4.1'
spec.add_dependency 'vcoworkflows', '~> 0.2'
spec.require_paths = ["lib"]

spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.2'
spec.add_development_dependency 'webmock', '~> 1.21'
spec.add_development_dependency 'rubocop', '~> 0.49.0'
spec.add_dependency "test-kitchen", "~> 1.4", "< 4"
spec.add_dependency "vcoworkflows", "~> 0.2"
end
30 changes: 15 additions & 15 deletions lib/kitchen/driver/vro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
# limitations under the License.
#

require 'kitchen'
require 'vcoworkflows'
require_relative 'vro_version'
require "kitchen"
require "vcoworkflows"
require_relative "vro_version"

module Kitchen
module Driver
Expand All @@ -42,13 +42,13 @@ class Vro < Kitchen::Driver::Base
default_config :request_timeout, 300

def name
'vRO'
"vRO"
end

def create(state)
return unless state[:server_id].nil?

info('Executing the create-server workflow...')
info("Executing the create-server workflow...")
execute_create_workflow(state)

info("Server #{state[:hostname]} (#{state[:server_id]}) created. Waiting for it to be ready...")
Expand Down Expand Up @@ -97,22 +97,22 @@ def execute_create_workflow(state)
execute_workflow
wait_for_workflow

raise 'The workflow did not complete successfully. Check the vRO UI for more info.' unless workflow_successful?
raise "The workflow did not complete successfully. Check the vRO UI for more info." unless workflow_successful?

validate_create_output_parameters!

state[:server_id] = output_parameter_value('server_id')
state[:hostname] = output_parameter_value('ip_address')
state[:server_id] = output_parameter_value("server_id")
state[:hostname] = output_parameter_value("ip_address")
end

def execute_destroy_workflow(state)
set_workflow_vars(config[:destroy_workflow_name], config[:destroy_workflow_id])
set_workflow_parameters(config[:destroy_workflow_parameters])
vro_client.parameter('server_id', state[:server_id])
vro_client.parameter("server_id", state[:server_id])
execute_workflow
wait_for_workflow

raise 'The workflow did not complete successfully. Check the vRO UI for more info.' unless workflow_successful?
raise "The workflow did not complete successfully. Check the vRO UI for more info." unless workflow_successful?
end

def execute_workflow
Expand Down Expand Up @@ -166,15 +166,15 @@ def output_parameter_empty?(key)
end

def validate_create_output_parameters!
raise 'The workflow output did not contain a server_id and ip_address parameter.' unless
output_parameters.key?('server_id') && output_parameters.key?('ip_address')
raise "The workflow output did not contain a server_id and ip_address parameter." unless
output_parameters.key?("server_id") && output_parameters.key?("ip_address")

raise 'The server_id parameter was empty.' if output_parameter_empty?('server_id')
raise 'The ip_address parameter was empty.' if output_parameter_empty?('ip_address')
raise "The server_id parameter was empty." if output_parameter_empty?("server_id")
raise "The ip_address parameter was empty." if output_parameter_empty?("ip_address")
end

def workflow_successful?
vro_client.token.state == 'completed'
vro_client.token.state == "completed"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/driver/vro_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

module Kitchen
module Driver
VRO_VERSION = '1.0.0'.freeze
VRO_VERSION = "1.0.0".freeze
end
end
8 changes: 8 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended",
":disableDependencyDashboard",
"schedule:automergeEarlyMondays"
]
}

0 comments on commit 3f51d13

Please sign in to comment.