Class: Pfm::Command::ValidatorCommands::ServerBuild
- Inherits:
-
Base
- Object
- Base
- Base
- Pfm::Command::ValidatorCommands::ServerBuild
show all
- Defined in:
- lib/idlc-sdk-pfm/command/validator_commands/server_build.rb
Instance Attribute Summary
Attributes inherited from Base
#errors, #params
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #params_valid?, #read_and_validate_params, #setup_artifacts_dirs, #setup_context, #use_circle_ci?
Methods inherited from Base
#build_base_dir, #build_dir, #build_exists?, #build_setup, #deploy_setup, #deploy_setupv2, #inf_base_dir, #initialize, #needs_help?, #needs_version?, #run_with_default_options, #templates_dir, #verbose?
Methods included from Helpers
debug, err, msg, system_command
Instance Method Details
#lint_chef ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/idlc-sdk-pfm/command/validator_commands/server_build.rb', line 62
def lint_chef
base_path = 'chef'
cookbooks_dir = 'cookbooks'
Dir.entries(base_path).each do |dir|
next unless File.directory? "#{base_path}/#{dir}/#{cookbooks_dir}"
next if dir.to_s == 'vendor'
Dir.entries("#{base_path}/#{dir}/#{cookbooks_dir}").each do |cookbook|
next unless File.directory? "#{base_path}/#{dir}/#{cookbooks_dir}/#{cookbook}"
next if cookbook.to_s == '.' || cookbook.to_s == '..'
msg("\nRunning Rubocop on #{cookbook} cookbook")
debug("copying #{SETTINGS['RUBOCOP_RULES_FILE']} to #{Dir.pwd}")
system("cp #{SETTINGS['RUBOCOP_RULES_FILE']} #{Dir.pwd}") if File.exist? SETTINGS['RUBOCOP_RULES_FILE']
gem_path = `bundle show rubocop-junit-formatter`.strip!
system("rubocop \\
--format html -o #{@artifacts_dir}/rubocop/#{cookbook}_rubocop_output.html \\
-r #{gem_path}/lib/rubocop/formatter/junit_formatter.rb \\
--format RuboCop::Formatter::JUnitFormatter -o #{@reports_dir}/rubocop/#{cookbook}_junit.xml \\
#{base_path}/#{dir}/#{cookbooks_dir}/#{cookbook}") || @failure = true
msg("Running Foodcritic on #{cookbook} cookbook")
ENV['FOODCRITIC_JUNIT_OUTPUT_DIR'] = "#{@reports_dir}/foodcritic"
ENV['FOODCRITIC_JUNIT_OUTPUT_FILE'] = "#{cookbook}_foodcritic_junit.xml"
debug("copying #{SETTINGS['FOODCRITIC_RULES_FILE']} to #{Dir.pwd}")
system("cp #{SETTINGS['FOODCRITIC_RULES_FILE']} #{base_path}/#{dir}/#{cookbooks_dir}/#{cookbook}") if File.exist? SETTINGS['FOODCRITIC_RULES_FILE']
system("foodcritic #{base_path}/#{dir}/#{cookbooks_dir}/#{cookbook} -C > #{cookbook}_foodcritic.out") || @failure = true
system("foodcritic-junit < #{cookbook}_foodcritic.out")
end
end
end
|
#lint_packer ⇒ Object
56
57
58
59
60
|
# File 'lib/idlc-sdk-pfm/command/validator_commands/server_build.rb', line 56
def lint_packer
Packer::Binary.validate("#{@build_config.dump_build_vars} #{@config[:build_template]}")
rescue Packer::Binary::Command::CommandFailure
@failure = true
end
|
#run ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/idlc-sdk-pfm/command/validator_commands/server_build.rb', line 27
def run
read_and_validate_params
setup_artifacts_dirs
if params_valid?
build_setup
validate
0
else
errors.each { |error| err("Error: #{error}") }
parse_options(params)
msg(opt_parser)
1
end
rescue ValidationError => e
err("ERROR: #{e}")
1
end
|
#unit_test ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/idlc-sdk-pfm/command/validator_commands/server_build.rb', line 106
def unit_test
require 'chefspec'
base_path = 'chef'
cookbooks_dir = 'cookbooks'
Dir.entries(base_path).each do |dir|
next unless File.directory? "#{base_path}/#{dir}/#{cookbooks_dir}"
next if dir.to_s == 'vendor'
Dir.entries("#{base_path}/#{dir}/#{cookbooks_dir}").each do |cookbook|
next unless File.directory? "#{base_path}/#{dir}/#{cookbooks_dir}/#{cookbook}"
next if cookbook.to_s == '.' || cookbook.to_s == '..'
Dir.chdir("#{base_path}/#{dir}/#{cookbooks_dir}/#{cookbook}") do
msg("\nRunning unit tests for #{cookbook} cookbook")
system("rspec -r rspec_junit_formatter --format progress --format RspecJunitFormatter -o #{@reports_dir}/rspec/#{cookbook}_junit.xml") || @failure = true
end
end
end
end
|
#validate ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/idlc-sdk-pfm/command/validator_commands/server_build.rb', line 47
def validate
lint_packer
lint_chef
unit_test
raise ValidationError, 'Failures reported during validation!' if @failure
msg('Verified repository..')
end
|