From 3f51d13a5afc683f6f3c1c4816f37ec0c65c4d63 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Mon, 27 Nov 2023 16:01:02 +0000 Subject: [PATCH] feat: Workflows (#10) * fix: Configure renovate, Rubocop & release workflow - BREAKING CHANGE: Require Ruby 3.1 - Add test workflow - Add release workflow Signed-off-by: Dan Webb * feat: Add workflows Signed-off-by: Dan Webb --------- Signed-off-by: Dan Webb --- .github/CODEOWNERS | 1 + .github/workflows/lint.yaml | 9 +++++++ .github/workflows/publish.yaml | 35 ++++++++++++++++++++++++++ .markdownlint.yaml | 8 ++++++ .rubocop.yml | 26 ++++++++----------- .travis.yml | 15 ----------- Gemfile | 12 ++++++++- README.md | 42 ++++++++++++++++++------------- Rakefile | 20 ++++++++++----- kitchen-vro.gemspec | 29 ++++++++------------- lib/kitchen/driver/vro.rb | 30 +++++++++++----------- lib/kitchen/driver/vro_version.rb | 2 +- renovate.json | 8 ++++++ 13 files changed, 147 insertions(+), 90 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/lint.yaml create mode 100644 .github/workflows/publish.yaml create mode 100644 .markdownlint.yaml delete mode 100644 .travis.yml create mode 100644 renovate.json 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/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..dbccea7 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -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 diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..8489e14 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -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 }} diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 0000000..5df560a --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,8 @@ +default: true +MD013: false +MD024: false +MD026: false +MD036: false +MD012: false +MD029: false +MD004: false diff --git a/.rubocop.yml b/.rubocop.yml index b31d59a..8fd406e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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/**/*" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1ab4fba..0000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: ruby -cache: bundler -sudo: false -rvm: -- 2.1 -- 2.2 -branches: - only: - - master -notifications: - slack: - on_success: change - on_failure: always - rooms: - secure: DDrKE+td2eGF7eAPuESBcOoRAnzY/faXrX+HvM+Zpgke9ZE8y+ICYfkzr/DllQBIvIRrtwJgq5cPeBRH4hjgyACjv5HhJDR84KNL+apR6IGi+Z0LevS2DWaNaFWc5AEus5PdybRSHwHshQGl8k9s/HAnUAzuazPwZZNdCviuLMPViokX2r3+ecNM85psXHPC64Wxm3PhZzXXW+TsPgWG5mIgx2XriHxgnd7V/cBKA+6ldye27CaB2o9MS5uEFlfZj2PhqCRcBxvi82siziOnDyLjPxkjvNVPPf/QB4Lr+Zzi6rl7Gg1/qFoM83XuckfYbLUczYKYMOKjhkhBFvkzeJRUpRjK0TEZx3fRZ4we4PonprE66zZ1vAnOv/yHW26nKtUiMAZ+TCU8SAEgmAfHEiVazjvE9Ev+wbbsQtVskoVbnw1EJJwyKbVzMNCyZ4fVD6r6vBNFo2IWjL+6DJ21wMjR32a92DWYprGpkbwAaNzYe1zjPZsfAy/6JhW6Hd5qFgyEsq4ZjVDu3ELl2iN3B6DlCZEFyM/yrYCv9jlBZk6htkE3v3uXZOmld1Uxs636IQfYyRnY4BqnyYAxM7z88+N1LrOTXKj7RLLFF0WEWA9kOKvPiuQ3K+BOb0tv0hwulZJGXkeT1QKZtyItj5qSMeZvnVx+b1Y/b+5G5v09C+g= diff --git a/Gemfile b/Gemfile index 94e05c3..600e413 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/README.md b/README.md index 59acd3d..f800d23 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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: @@ -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 @@ -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 ``` @@ -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 ( ) 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`) diff --git a/Rakefile b/Rakefile index e16e990..f1c0104 100644 --- a/Rakefile +++ b/Rakefile @@ -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} diff --git a/kitchen-vro.gemspec b/kitchen-vro.gemspec index ad4f3d6..740edf4 100644 --- a/kitchen-vro.gemspec +++ b/kitchen-vro.gemspec @@ -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 diff --git a/lib/kitchen/driver/vro.rb b/lib/kitchen/driver/vro.rb index 0a853cf..6297bdb 100644 --- a/lib/kitchen/driver/vro.rb +++ b/lib/kitchen/driver/vro.rb @@ -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 @@ -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...") @@ -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 @@ -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 diff --git a/lib/kitchen/driver/vro_version.rb b/lib/kitchen/driver/vro_version.rb index c54800d..b23ac13 100644 --- a/lib/kitchen/driver/vro_version.rb +++ b/lib/kitchen/driver/vro_version.rb @@ -18,6 +18,6 @@ module Kitchen module Driver - VRO_VERSION = '1.0.0'.freeze + VRO_VERSION = "1.0.0".freeze end end diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..b65764b --- /dev/null +++ b/renovate.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:recommended", + ":disableDependencyDashboard", + "schedule:automergeEarlyMondays" + ] +}