From 339a2f8eb5fdd0eb25a82bd9e23caec8a44f5550 Mon Sep 17 00:00:00 2001 From: Karim Bogtob Date: Tue, 21 Jan 2020 14:00:35 -0500 Subject: [PATCH] Add conf to run kitchen tests on CircleCI --- .circleci/config.yml | 23 +++++++++++++++++++++++ Rakefile | 30 ++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3b67d4f9..7ab0d6d6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -263,6 +263,28 @@ jobs: name: Run tests command: rvm $RUBY_VERSION --verbose do bundle exec rake test + kitchen-tests: + machine: true + environment: + KITCHEN_LOCAL_YAML: .kitchen.docker.yml + STRICT_VARIABLES: 'yes' + RUBY_VERSION: '2.5.3' + steps: + - checkout + - run: + name: Install Ruby versions + command: rvm install $RUBY_VERSION + - run: + name: Install bundler + command: rvm $RUBY_VERSION --verbose do gem install bundler:1.17.3 + - run: + name: Install gem dependencies + command: rvm $RUBY_VERSION --verbose do bundle install --path .bundle + - run: + name: Execute Kitchen tests + command: rvm $RUBY_VERSION --verbose do bundle exec rake circle + no_output_timeout: 900 + workflows: version: 2 build_and_test: @@ -297,3 +319,4 @@ workflows: - specs-ruby26-puppet60 - specs-ruby26-puppet65 - verify-gemfile-lock-dependencies + - kitchen-tests diff --git a/Rakefile b/Rakefile index 9cf1b316..7c1fd16d 100644 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,7 @@ require 'puppet-syntax/tasks/puppet-syntax' require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? require 'puppet-lint/tasks/puppet-lint' require 'rubocop/rake_task' +require 'kitchen/rake_tasks' exclude_paths = [ "pkg/**/*", @@ -23,3 +24,32 @@ task :test => [ 'rubocop', 'spec', ] + +desc 'Run Kitchen tests using CircleCI parallelism mode, split by worker' +task :circle do + def kitchen_config + raw_config = Kitchen::Loader::YAML.new( + local_config: ENV['KITCHEN_LOCAL_YAML'] + ) + + Kitchen::Config.new(loader: raw_config) + end + + def total_workers + ENV.fetch('CIRCLE_NODE_TOTAL', 1).to_i + end + + def current_worker + ENV.fetch('CIRCLE_NODE_INDEX', 0).to_i + end + + def command + kitchen_config.instances.sort_by(&:name).each_with_object([]).with_index do |(instance, commands), index| + next unless index % total_workers == current_worker + + commands << "kitchen test #{instance.name}" + end.join(' && ') + end + + sh command unless command.empty? +end