Skip to content

Instantly share code, notes, and snippets.

@unixorn
Created January 10, 2017 19:10
Show Gist options
  • Save unixorn/beefeb71cd6d3d8fbf039343cffa18e1 to your computer and use it in GitHub Desktop.
Save unixorn/beefeb71cd6d3d8fbf039343cffa18e1 to your computer and use it in GitHub Desktop.
Make it easier to specify a directory's contents in a Berksfile for test-kitchen
# Scan a directory in the gitroot for cookbook directories
def cookbook_search(book_directory, exclusions=[])
git_root = %x[ git rev-parse --show-toplevel ].chomp
Dir.entries("#{git_root}/#{book_directory}")
.reject { |i| %w(. ..).include?(i) }
.select { |i| File.directory?(File.join("#{git_root}/#{book_directory}", i)) }
.each do |cb|
if cb != File.basename(Dir.pwd) # Don't add an entry for ourself or Berks will error
if not exclusions.include?(cb)
if File.exists?("#{git_root}/#{book_directory}/#{cb}/metadata.rb")
cb_name = %x[ grep '^name' #{git_root}/#{book_directory}/#{cb}/metadata.rb].chomp.split[1].tr("'",'').tr('"','')
cookbook cb_name, path: "#{git_root}/#{book_directory}/#{cb}"
end
end
end
end
end
@unixorn
Copy link
Author

unixorn commented Jan 10, 2017

from jamescarr on hangops

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment