# frozen_string_literal: true # DeployRubygem - deploy a gem using rake # Containing a class module DeployRubygem # Using Project to deploy and manage Project class Project 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 = Inspec.new(project_options[:compliance_profile]) end # Wrapping GVB to fetch project version class DeployVersion attr_reader :path def initialize(git_path) @path = git_path end def execute_in_folder current_folder = Dir.pwd Dir.chdir path get_gvb = yield if block_given? Dir.chdir current_folder get_gvb end def method_missing(method_name) execute_in_folder { GVB.send(method_name) } end def respond_to_missing?(method_name) GVB.methods.include?(method_name) end def patch_bump execute_in_folder { system('git version-bump patch') } end def short_version Gem::Version.new("#{major_version}.#{minor_version}.#{patch_version}") end 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 def gvb_version @gvb_version ||= DeployVersion.new(path) @gvb_version end end end