Skip to content

Commit

Permalink
Add conf to run kitchen tests on CircleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
kbogtob committed Jan 22, 2020
1 parent a7a33a0 commit 339a2f8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -297,3 +319,4 @@ workflows:
- specs-ruby26-puppet60
- specs-ruby26-puppet65
- verify-gemfile-lock-dependencies
- kitchen-tests
30 changes: 30 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/**/*",
Expand All @@ -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

0 comments on commit 339a2f8

Please sign in to comment.