# frozen_string_literal: true require_relative 'testing' # DeployRubygem - deploy a gem using rake # Containing a class module DeployRubygem # Using Project to deploy and manage Project class Project include RSpecTesting attr_reader :project_options, :cookbooks, :compliance_profile def initialize(new_project_options) @project_options = new_project_options @cookbooks = project_options[:cookbooks]&.map do |cookbook_name, cookbook_options| new_cookbook_option = cookbook_options.dup new_cookbook_option[:project_name] = cookbook_name new_cookbook_option[:chefrepo_path] = chefrepo_path Cookbook.new(new_cookbook_option) end @compliance_profile = InspecTestor.new(project_options[:compliance_profile]) end def project_name project_options[__method__] end def binaries project_options[__method__] end def dependencies project_options[__method__] end def path project_options[__method__] end def git project_options[__method__] end def chefrepo_git project_options[__method__] end def chefrepo_path project_options[__method__] end def deploy_cookbooks cookbooks.each(&:deploy) end def release_cookbooks project_options[:cookbooks].each(&:release) end def change_to_directory(git_path, git_url) system("git clone #{git_url}") unless Dir.exist?(chefrepo_path) Dir.chdir(git_path) git_path end def change_to_project_folder change_to_directory(path, git) end def change_to_chefrepo change_to_directory(chefrepo_path, chefrepo_git) end def test_compliance change_to_chefrepo compliance_profile.update compliance_profile.apply end def git_commit system('git add .') || return system("git commit -m 'Self validated for version #{GVB.version}'") || return system('git push') || abort("Cannot push #{project_name} #{GVB.version}") end end end