Created
January 10, 2017 19:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from jamescarr on hangops