# frozen_string_literal: true require 'rake/dsl_definition' require_relative 'default' require_relative 'cookbook/chef' require_relative 'cookbook/inspec' require_relative 'cookbook/knife' # DeployRubygem module helper for rubygem module DeployRubygem # RakeTask to use with DeployRubygem projects class RakeCookbookTask < RakeDefaultTask include ChefCookbookTask include InspecCookbookTask include KnifeCookbookTask def initialize(task_name = 'cookbook', desc = 'Run DeployRubygem task') super end def define_tasks # :nodoc: super test_cookbook release_cookbook cookstyle build_cookbook install_policy release_policy install_cookbook report clean_cookbook chef_client end def test_framework # :nodoc: desc "@desc with #{__method__}" task test_framework: %i[build_cookbook spec clean_cookbook] end def default # :nodoc: desc "@desc with #{__method__}" task default: %i[test_framework build install:local] end def cycle # :nodoc: desc "@desc with #{__method__}" task cycle: %i[test_framework release_policy test_version] end def develop # :nodoc: desc "@desc with #{__method__}" task develop: %i[build_cookbook spec push install release_policy report] end def test_cookbook # :nodoc: desc "@desc with #{__method__}" task test_cookbook: %i[build_cookbook spec push install release_policy report] end def release_cookbook # :nodoc: desc "@desc with #{__method__}" task release_cookbook: %i[clean_cookbook release_policy release] end def clean_cookbook # :nodoc: desc "@desc with #{__method__}" task clean_cookbook: %i[clean] do system('kitchen destroy base') FileUtils.rm_f('Policyfile.lock.json') FileUtils.rm_f('Gemfile.lock') FileUtils.rm_f('.rspec_status') profiles_folder = File.join(%w[compliance profiles]) Dir.children(profiles_folder).each do |sub_folder| vendor_folder = File.join(profiles_folder, sub_folder, 'vendor') inspec_file = File.join(profiles_folder, sub_folder, 'inspec.lock') FileUtils.rm_rf(vendor_folder) FileUtils.rm_f(inspec_file) end end end end end