halite 1.0.0.rc.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +20 -0
- data/.travis.yml +14 -4
- data/.yardopts +7 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +30 -8
- data/LICENSE +202 -202
- data/README.md +104 -2
- data/Rakefile +25 -5
- data/gemfiles/default.gemfile +17 -0
- data/gemfiles/master.gemfile +21 -0
- data/halite.gemspec +21 -10
- data/lib/berkshelf/halite.rb +25 -0
- data/lib/berkshelf/locations/gem.rb +84 -0
- data/lib/halite.rb +34 -4
- data/lib/halite/berkshelf/helper.rb +8 -2
- data/lib/halite/berkshelf/source.rb +9 -1
- data/lib/halite/converter.rb +34 -10
- data/lib/halite/converter/chef.rb +43 -0
- data/lib/halite/converter/libraries.rb +93 -26
- data/lib/halite/converter/metadata.rb +48 -10
- data/lib/halite/converter/misc.rb +43 -0
- data/lib/halite/dependencies.rb +48 -8
- data/lib/halite/error.rb +20 -0
- data/lib/halite/gem.rb +106 -21
- data/lib/halite/helper_base.rb +129 -0
- data/lib/halite/rake_helper.rb +46 -60
- data/lib/halite/rake_tasks.rb +17 -1
- data/lib/halite/spec_helper.rb +403 -54
- data/lib/halite/spec_helper/patcher.rb +130 -0
- data/lib/halite/spec_helper/runner.rb +57 -9
- data/lib/halite/version.rb +19 -1
- data/spec/converter/chef_spec.rb +54 -0
- data/spec/converter/libraries_spec.rb +131 -123
- data/spec/converter/metadata_spec.rb +61 -8
- data/spec/converter/misc_spec.rb +61 -0
- data/spec/converter_spec.rb +21 -6
- data/spec/dependencies_spec.rb +64 -10
- data/spec/example_resources/poise.rb +42 -0
- data/spec/example_resources/simple.rb +48 -0
- data/spec/{data/gems/test1/lib → fixtures/cookbooks/test1/files/halite_gem}/test1.rb +0 -0
- data/spec/{data/gems/test1/lib → fixtures/cookbooks/test1/files/halite_gem}/test1/version.rb +0 -0
- data/spec/fixtures/cookbooks/test1/libraries/default.rb +4 -0
- data/spec/{data/integration_cookbooks → fixtures/cookbooks}/test1/metadata.rb +0 -0
- data/spec/{data/gems/test2/chef → fixtures/cookbooks/test2}/attributes.rb +0 -0
- data/spec/{data/gems/test2/lib → fixtures/cookbooks/test2/files/halite_gem}/test2.rb +0 -0
- data/spec/{data/gems/test2/lib → fixtures/cookbooks/test2/files/halite_gem}/test2/resource.rb +0 -0
- data/spec/{data/gems/test2/lib → fixtures/cookbooks/test2/files/halite_gem}/test2/version.rb +0 -0
- data/spec/fixtures/cookbooks/test2/libraries/default.rb +3 -0
- data/spec/{data/integration_cookbooks → fixtures/cookbooks}/test2/metadata.rb +1 -1
- data/spec/{data/gems/test2/chef → fixtures/cookbooks/test2}/recipes/default.rb +0 -0
- data/spec/{data/gems/test2/chef → fixtures/cookbooks/test2}/templates/default/conf.erb +0 -0
- data/spec/{data/gems/test3/lib → fixtures/cookbooks/test3/files/halite_gem}/test3.rb +0 -0
- data/spec/{data/gems/test3/lib → fixtures/cookbooks/test3/files/halite_gem}/test3/dsl.rb +0 -0
- data/spec/{data/gems/test3/lib → fixtures/cookbooks/test3/files/halite_gem}/test3/version.rb +0 -0
- data/spec/fixtures/cookbooks/test3/libraries/default.rb +4 -0
- data/spec/{data/integration_cookbooks → fixtures/cookbooks}/test3/metadata.rb +0 -0
- data/spec/{data/gems/test3/chef → fixtures/cookbooks/test3}/recipes/default.rb +0 -0
- data/spec/{data → fixtures}/gems/test1/Rakefile +0 -0
- data/spec/fixtures/gems/test1/lib/test1.rb +2 -0
- data/spec/fixtures/gems/test1/lib/test1/version.rb +3 -0
- data/spec/{data → fixtures}/gems/test1/test1.gemspec +0 -0
- data/spec/{data → fixtures}/gems/test2/Rakefile +0 -0
- data/spec/{data/integration_cookbooks/test2 → fixtures/gems/test2/chef}/attributes.rb +0 -0
- data/spec/{data/integration_cookbooks/test2 → fixtures/gems/test2/chef}/recipes/default.rb +0 -0
- data/spec/{data/integration_cookbooks/test2 → fixtures/gems/test2/chef}/templates/default/conf.erb +0 -0
- data/spec/fixtures/gems/test2/lib/test2.rb +4 -0
- data/spec/{data/integration_cookbooks/test2/libraries/test2__resource.rb → fixtures/gems/test2/lib/test2/resource.rb} +1 -2
- data/spec/fixtures/gems/test2/lib/test2/version.rb +3 -0
- data/spec/{data → fixtures}/gems/test2/test2.gemspec +0 -0
- data/spec/{data → fixtures}/gems/test3/Rakefile +0 -0
- data/spec/{data/integration_cookbooks/test3 → fixtures/gems/test3/chef}/recipes/default.rb +0 -0
- data/spec/fixtures/gems/test3/lib/test3.rb +4 -0
- data/spec/{data/integration_cookbooks/test3/libraries/test3__dsl.rb → fixtures/gems/test3/lib/test3/dsl.rb} +1 -2
- data/spec/fixtures/gems/test3/lib/test3/version.rb +3 -0
- data/spec/{data → fixtures}/gems/test3/test3.gemspec +1 -0
- data/spec/gem_spec.rb +41 -31
- data/spec/integration_spec.rb +58 -82
- data/spec/runner_spec.rb +108 -0
- data/spec/spec_helper.rb +19 -26
- data/spec/spec_helper_spec.rb +238 -0
- metadata +124 -151
- data/lib/halite/converter/other.rb +0 -19
- data/lib/halite/converter/readme.rb +0 -20
- data/spec/converter/other_spec.rb +0 -56
- data/spec/converter/readme_spec.rb +0 -55
- data/spec/data/integration_cookbooks/test1/libraries/test1.rb +0 -3
- data/spec/data/integration_cookbooks/test1/libraries/test1__version.rb +0 -4
- data/spec/data/integration_cookbooks/test2/libraries/test2.rb +0 -5
- data/spec/data/integration_cookbooks/test2/libraries/test2__version.rb +0 -4
- data/spec/data/integration_cookbooks/test3/libraries/test3.rb +0 -5
- data/spec/data/integration_cookbooks/test3/libraries/test3__version.rb +0 -4
data/lib/halite/gem.rb
CHANGED
@@ -1,10 +1,38 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'chef/cookbook_version'
|
18
|
+
|
1
19
|
require 'halite/dependencies'
|
2
20
|
|
21
|
+
|
3
22
|
module Halite
|
23
|
+
# A model for a gem/cookbook within Halite.
|
24
|
+
#
|
25
|
+
# @since 1.0.0
|
26
|
+
# @example
|
27
|
+
# g = Halite::Gem.new('chef-mycookbook', '1.1.0')
|
28
|
+
# puts(g.cookbook_name) #=> mycookbook
|
4
29
|
class Gem
|
30
|
+
attr_reader :name
|
31
|
+
|
5
32
|
# name can be either a string name, Gem::Dependency, or Gem::Specification
|
33
|
+
# @param name [String, Gem::Dependency, Gem::Specification]
|
6
34
|
def initialize(name, version=nil)
|
7
|
-
name = name.to_spec if name.is_a?(::Gem::Dependency) # Allow passing
|
35
|
+
name = name.to_spec if name.is_a?(::Gem::Dependency) # Allow passing a Dependency by just grabbing its spec.
|
8
36
|
if name.is_a?(::Gem::Specification)
|
9
37
|
raise Error.new("Cannot pass version when using an explicit specficiation") if version
|
10
38
|
@spec = name
|
@@ -20,10 +48,6 @@ module Halite
|
|
20
48
|
@spec ||= ::Gem::Dependency.new(@name, ::Gem::Requirement.new(@version)).to_spec
|
21
49
|
end
|
22
50
|
|
23
|
-
def method_missing(*args)
|
24
|
-
spec.send(*args)
|
25
|
-
end
|
26
|
-
|
27
51
|
def version
|
28
52
|
spec.version.to_s
|
29
53
|
end
|
@@ -36,7 +60,12 @@ module Halite
|
|
36
60
|
end
|
37
61
|
end
|
38
62
|
|
39
|
-
#
|
63
|
+
# Path to the .gemspec for this gem. This is different from
|
64
|
+
# Gem::Specification#spec_file because the Rubygems API is shit and just
|
65
|
+
# assumes the file layout matches normal, which is not the case with Bundler
|
66
|
+
# and path or git sources.
|
67
|
+
#
|
68
|
+
# @return [String]
|
40
69
|
def spec_file
|
41
70
|
File.join(spec.full_gem_path, spec.name + '.gemspec')
|
42
71
|
end
|
@@ -45,26 +74,42 @@ module Halite
|
|
45
74
|
IO.readlines(spec_file).take_while { |line| line.strip.empty? || line.strip.start_with?('#') }.join('')
|
46
75
|
end
|
47
76
|
|
77
|
+
# Iterate over all the files in the gem, with an optional prefix. Each
|
78
|
+
# element in the iterable will be [full_path, relative_path], where
|
79
|
+
# relative_path is relative to the prefix or gem path.
|
80
|
+
#
|
81
|
+
# @param prefix_paths [String, Array<String>, nil] Option prefix paths.
|
82
|
+
# @param block [Proc] Callable for iteration.
|
83
|
+
# @return [Array<Array<String>>]
|
84
|
+
# @example
|
85
|
+
# gem_data.each_file do |full_path, rel_path|
|
86
|
+
# # ...
|
87
|
+
# end
|
48
88
|
def each_file(prefix_paths=nil, &block)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
89
|
+
globs = if prefix_paths
|
90
|
+
Array(prefix_paths).map {|path| File.join(spec.full_gem_path, path) }
|
91
|
+
else
|
92
|
+
[spec.full_gem_path]
|
93
|
+
end
|
94
|
+
[].tap do |files|
|
95
|
+
globs.each do |glob|
|
96
|
+
Dir[File.join(glob, '**', '*')].each do |path|
|
97
|
+
next unless File.file?(path)
|
98
|
+
val = [path, path[glob.length+1..-1]]
|
99
|
+
block.call(*val) if block
|
100
|
+
files << val
|
101
|
+
end
|
55
102
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
path[prefix.length..-1], # Relative path
|
60
|
-
]
|
61
|
-
files << value
|
62
|
-
block.call(*value) if block
|
103
|
+
# Make sure the order is stable for my tests. Probably overkill, I think
|
104
|
+
# Dir#[] sorts already.
|
105
|
+
files.sort!
|
63
106
|
end
|
64
|
-
files.sort! # To be safe
|
65
107
|
end
|
66
108
|
|
67
|
-
# Special case of the
|
109
|
+
# Special case of the {#each_file} the gem's require paths.
|
110
|
+
#
|
111
|
+
# @param block [Proc] Callable for iteration.
|
112
|
+
# @return [Array<Array<String>>]
|
68
113
|
def each_library_file(&block)
|
69
114
|
each_file(spec.require_paths, &block)
|
70
115
|
end
|
@@ -78,5 +123,45 @@ module Halite
|
|
78
123
|
spec.dependencies.any? {|subdep| subdep.name == 'halite'} && !spec.metadata.include?('halite_ignore')
|
79
124
|
end
|
80
125
|
|
126
|
+
# Create a Chef::CookbookVersion object that represents this gem. This can
|
127
|
+
# be injected in to Chef to simulate the cookbook being available.
|
128
|
+
#
|
129
|
+
# @return [Chef::CookbookVersion]
|
130
|
+
# @example
|
131
|
+
# run_context.cookbook_collection[gem.cookbook_name] = gem.as_cookbook_version
|
132
|
+
def as_cookbook_version
|
133
|
+
# Put this in a local variable for a closure below.
|
134
|
+
path = spec.full_gem_path
|
135
|
+
Chef::CookbookVersion.new(cookbook_name, File.join(path, 'chef')).tap do |c|
|
136
|
+
c.attribute_filenames = each_file('chef/attributes').map(&:first)
|
137
|
+
c.file_filenames = each_file('chef/files').map(&:first)
|
138
|
+
c.recipe_filenames = each_file('chef/recipes').map(&:first)
|
139
|
+
c.template_filenames = each_file('chef/templates').map(&:first)
|
140
|
+
# Haxx, rewire the filevendor for this cookbook to look up in our folder.
|
141
|
+
# This is touching two different internal interfaces, but ¯\_(ツ)_/¯
|
142
|
+
c.send(:file_vendor).define_singleton_method(:get_filename) do |filename|
|
143
|
+
File.join(path, 'chef', filename)
|
144
|
+
end
|
145
|
+
# Store the true root for use in other tools.
|
146
|
+
c.define_singleton_method(:halite_root) { path }
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# Search for a file like README.md or LICENSE.txt in the gem.
|
151
|
+
#
|
152
|
+
# @param name [String] Basename to search for.
|
153
|
+
# @return [String, Array<String>]
|
154
|
+
# @example
|
155
|
+
# gem.misc_file('Readme') => /path/to/readme.txt
|
156
|
+
def find_misc_path(name)
|
157
|
+
[name, name.upcase, name.downcase].each do |base|
|
158
|
+
['.md', '', '.txt', '.html'].each do |suffix|
|
159
|
+
path = File.join(spec.full_gem_path, base+suffix)
|
160
|
+
return path if File.exist?(path)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
# Didn't find anything
|
164
|
+
nil
|
165
|
+
end
|
81
166
|
end
|
82
167
|
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
|
18
|
+
# Much inspiration from Bundler's GemHelper. Thanks!
|
19
|
+
require 'bundler'
|
20
|
+
require 'thor/shell'
|
21
|
+
|
22
|
+
require 'halite/error'
|
23
|
+
require 'halite/gem'
|
24
|
+
|
25
|
+
|
26
|
+
module Halite
|
27
|
+
# Base class for helpers like Rake tasks.
|
28
|
+
#
|
29
|
+
# @api semipublic
|
30
|
+
# @since 1.0.0
|
31
|
+
class HelperBase
|
32
|
+
# Class method helper to install the tasks.
|
33
|
+
#
|
34
|
+
# @param args Arguments to be passed to {#initialize}.
|
35
|
+
# @return [void]
|
36
|
+
# @example
|
37
|
+
# MyApp::RakeHelper.install(gem_name: 'otherapp')
|
38
|
+
def self.install(*args)
|
39
|
+
new(*args).install
|
40
|
+
end
|
41
|
+
|
42
|
+
# Name of the gem to use in these Rake tasks.
|
43
|
+
# @return [String]
|
44
|
+
attr_reader :gem_name
|
45
|
+
|
46
|
+
# Base folder of the gem.
|
47
|
+
# @return [String]
|
48
|
+
attr_reader :base
|
49
|
+
|
50
|
+
# Helper options.
|
51
|
+
# @return [Hash<Symbol, Object>]
|
52
|
+
attr_reader :options
|
53
|
+
|
54
|
+
# @param gem_name [String] Name of the gem to use in these Rake tasks.
|
55
|
+
# @param base [String] Base folder of the gem.
|
56
|
+
# @options options [Boolean] no_color Forcibly disable using colors in the output.
|
57
|
+
def initialize(gem_name: nil, base: nil, **options)
|
58
|
+
@base = base || if defined?(::Rake) && ::Rake.original_dir
|
59
|
+
::Rake.original_dir
|
60
|
+
else
|
61
|
+
Dir.pwd
|
62
|
+
end # rubocop:disable Lint/EndAlignment
|
63
|
+
@gem_name = gem_name || find_gem_name(@base)
|
64
|
+
@options = options
|
65
|
+
end
|
66
|
+
|
67
|
+
# Subclass hoook to provide the actual tasks or other helpers to install.
|
68
|
+
#
|
69
|
+
# @return [void]
|
70
|
+
# @example
|
71
|
+
# def install
|
72
|
+
# extend Rake::DSL
|
73
|
+
# desc 'My awesome task'
|
74
|
+
# task 'mytask' do
|
75
|
+
# # ...
|
76
|
+
# end
|
77
|
+
# end
|
78
|
+
def install
|
79
|
+
raise NotImplementedError
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
# Return a Thor::Shell object based on output settings.
|
85
|
+
#
|
86
|
+
# @return [Thor::Shell::Basic]
|
87
|
+
# @example
|
88
|
+
# shell.say('Operation completed', :green)
|
89
|
+
def shell
|
90
|
+
@shell ||= if options[:no_color] || !STDOUT.tty?
|
91
|
+
Thor::Shell::Basic
|
92
|
+
else
|
93
|
+
Thor::Base.shell
|
94
|
+
end.new
|
95
|
+
end
|
96
|
+
|
97
|
+
# Search a directory for a .gemspec file to determine the gem name.
|
98
|
+
# Returns nil if no gemspec is found.
|
99
|
+
#
|
100
|
+
# @param base [String] Folder to search.
|
101
|
+
# @return [String, nil]
|
102
|
+
def find_gem_name(base)
|
103
|
+
spec = Dir[File.join(base, '*.gemspec')].first
|
104
|
+
File.basename(spec, '.gemspec') if spec
|
105
|
+
end
|
106
|
+
|
107
|
+
# Gem specification for the current gem.
|
108
|
+
#
|
109
|
+
# @return [Gem::Specification]
|
110
|
+
def gemspec
|
111
|
+
@gemspec ||= begin
|
112
|
+
raise Error.new("Unable to automatically determine gem name from specs in #{base}. Please set the gem name via #{self.class.name}.install_tasks(gem_name: 'name')") unless gem_name
|
113
|
+
g = Bundler.load_gemspec(File.join(base, gem_name+'.gemspec'))
|
114
|
+
# This is returning the path it would be in if installed normally,
|
115
|
+
# override so we get the local path. Also for reasons that are entirely
|
116
|
+
# beyond me, #tap makes Gem::Specification flip out so do it old-school.
|
117
|
+
g.full_gem_path = base
|
118
|
+
g
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Cookbook model for the current gem.
|
123
|
+
#
|
124
|
+
# @return [Halite::Gem]
|
125
|
+
def cookbook
|
126
|
+
@cookbook ||= Halite::Gem.new(gemspec)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
data/lib/halite/rake_helper.rb
CHANGED
@@ -1,97 +1,83 @@
|
|
1
|
-
#
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
2
17
|
require 'tmpdir'
|
3
|
-
|
18
|
+
|
19
|
+
require 'chef/version'
|
4
20
|
|
5
21
|
require 'halite'
|
6
22
|
require 'halite/error'
|
23
|
+
require 'halite/helper_base'
|
7
24
|
|
8
|
-
module Halite
|
9
|
-
class RakeHelper
|
10
|
-
include Rake::DSL if defined? Rake::DSL
|
11
|
-
|
12
|
-
def self.install_tasks(*args)
|
13
|
-
new(*args).install
|
14
|
-
end
|
15
|
-
|
16
|
-
attr_accessor :gem_name, :base, :cookbook_name
|
17
|
-
|
18
|
-
def initialize(gem_name=nil, base=nil, no_gem=nil, no_foodcritic=nil, no_kitchen=nil)
|
19
|
-
if gem_name.is_a?(Hash)
|
20
|
-
opts = gem_name.inject({}) {|memo, (key, value)| memo[key.to_s] = value; memo }
|
21
|
-
gem_name = opts['gem_name']
|
22
|
-
base = opts['base']
|
23
|
-
no_gem = opts['no_gem']
|
24
|
-
no_foodcritic = opts['no_foodcritic']
|
25
|
-
no_kitchen = opts['no_kitchen']
|
26
|
-
end
|
27
|
-
# Order is important, find_gem_name needs base to be set
|
28
|
-
@base = base || if defined? Rake
|
29
|
-
Rake.original_dir
|
30
|
-
else
|
31
|
-
Dir.pwd
|
32
|
-
end
|
33
|
-
@gem_name = gem_name || find_gem_name
|
34
|
-
@gemspec = Bundler.load_gemspec(@gem_name+'.gemspec')
|
35
|
-
@no_gem = no_gem
|
36
|
-
@no_foodcritic = no_foodcritic
|
37
|
-
@no_kitchen = no_kitchen
|
38
|
-
end
|
39
|
-
|
40
|
-
def find_gem_name
|
41
|
-
specs = Dir[File.join(base, '*.gemspec')]
|
42
|
-
raise Error.new("Unable to automatically determine gem name from specs in #{base}. Please set the gem name via Halite::RakeHelper.install_tasks(gem_name: 'name').") if specs.length != 1
|
43
|
-
File.basename(specs.first, '.gemspec')
|
44
|
-
end
|
45
|
-
|
46
|
-
def pkg_path
|
47
|
-
@pkg_path ||= File.join(base, 'pkg', "#{@gem_name}-#{@gemspec.version}")
|
48
|
-
end
|
49
|
-
|
50
|
-
def shell
|
51
|
-
@shell ||= if @no_color || !STDOUT.tty?
|
52
|
-
Thor::Shell::Basic
|
53
|
-
else
|
54
|
-
Thor::Base.shell
|
55
|
-
end.new
|
56
|
-
end
|
57
25
|
|
26
|
+
module Halite
|
27
|
+
# Helper class to install Halite rake tasks.
|
28
|
+
#
|
29
|
+
# @since 1.0.0
|
30
|
+
# @example Rakefile
|
31
|
+
# require 'halite/rake_helper'
|
32
|
+
# Halite::RakeHelper.install
|
33
|
+
class RakeHelper < HelperBase
|
34
|
+
# Install all Rake tasks.
|
35
|
+
#
|
36
|
+
# @return [void]
|
58
37
|
def install
|
38
|
+
extend Rake::DSL
|
59
39
|
# Core Halite tasks
|
60
|
-
desc "Convert #{
|
40
|
+
desc "Convert #{gemspec.name}-#{gemspec.version} to a cookbook in the pkg directory"
|
61
41
|
task 'chef:build' do
|
62
42
|
build_cookbook
|
63
43
|
end
|
64
44
|
|
65
|
-
desc "Push #{
|
45
|
+
desc "Push #{gemspec.name}-#{gemspec.version} to Supermarket"
|
66
46
|
task 'chef:release' => ['chef:build'] do
|
67
47
|
release_cookbook
|
68
48
|
end
|
69
49
|
|
70
50
|
# Patch the core gem tasks to run ours too
|
71
|
-
|
51
|
+
unless options[:no_gem]
|
72
52
|
task 'build' => ['chef:build']
|
73
53
|
task 'release' => ['chef:release']
|
74
54
|
end
|
75
55
|
|
76
56
|
# Foodcritic doesn't have a config file, so just always try to add it.
|
77
|
-
|
57
|
+
unless options[:no_foodcritic]
|
78
58
|
install_foodcritic
|
79
59
|
end
|
80
60
|
|
81
61
|
# If a .kitchen.yml exists, install the Test Kitchen tasks.
|
82
|
-
|
62
|
+
unless options[:no_kitchen] || !File.exist?(File.join(@base, '.kitchen.yml'))
|
83
63
|
install_kitchen
|
84
64
|
end
|
85
65
|
end
|
86
66
|
|
67
|
+
private
|
68
|
+
|
69
|
+
def pkg_path
|
70
|
+
@pkg_path ||= File.join(base, 'pkg', "#{gemspec.name}-#{gemspec.version}")
|
71
|
+
end
|
72
|
+
|
87
73
|
def install_foodcritic
|
88
74
|
require 'foodcritic'
|
89
75
|
|
90
76
|
desc 'Run Foodcritic linter'
|
91
77
|
task 'chef:foodcritic' do
|
92
78
|
Dir.mktmpdir('halite_test') do |path|
|
93
|
-
Halite.convert(
|
94
|
-
sh("foodcritic -
|
79
|
+
Halite.convert(gemspec, path)
|
80
|
+
sh("foodcritic --chef-version #{Chef::VERSION} --epic-fail any --tags ~FC054 '#{path}'")
|
95
81
|
end
|
96
82
|
end
|
97
83
|
|
@@ -122,12 +108,12 @@ module Halite
|
|
122
108
|
FileUtils.mkdir_p(pkg_path)
|
123
109
|
remove_files_in_folder(pkg_path)
|
124
110
|
Halite.convert(gem_name, pkg_path)
|
125
|
-
shell.say("#{
|
111
|
+
shell.say("#{gemspec.name} #{gemspec.version} converted to pkg/#{gemspec.name}-#{gemspec.version}/.", :green)
|
126
112
|
end
|
127
113
|
|
128
114
|
def release_cookbook
|
129
115
|
Dir.chdir(pkg_path) do
|
130
|
-
|
116
|
+
sh('stove --no-git')
|
131
117
|
end
|
132
118
|
end
|
133
119
|
|