# Copyright (C) 2011 RightScale, Inc, All Rights Reserved Worldwide. # # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use, # reproduction, modification, or disclosure of this program is # strictly prohibited. Any use of this program by an authorized # licensee is strictly subject to the terms and conditions, # including confidentiality obligations, set forth in the applicable # License Agreement between RightScale.com, Inc. and # the licensee module RightConf class GitRepoConfigurator include Configurator register :git_repo description 'Clone git repository and build if needed' settings :repo => 'git repo URL', :tag => 'git tag or branch or sha that should be checked out', :install_path => 'Path where git repo should be cloned to', :build_commands => 'Comma separated list of commands to run in repo after clone', :only_if => 'Ruby lambda expression that should return true to proceed ' + 'with the cloning / build if defined' validate_has_settings :repo, :install_path # Clone git repo and run build commands if given # # === Return # true:: Always return true def run if only_if.nil? || only_if.call report_check("Cloning #{repo} into #{install_path}") if File.exist?(install_path) FileUtils.mv(install_path, "#{install_path}_old") post_note "Had to move pre-existing #{install_path} to #{install_path}_old" end Command.execute('git', 'clone', repo, install_path, :abort_on_failure => "Failed to clone #{repo} into #{install_path}") Command.execute('git', 'checkout', tag) if tag report_success if build_commands report_check "Building" Dir.chdir(install_path) do build_commands.split(',').each do |c| c.lstrip! args = c.split(' ') + [ { :abort_on_failure => "#{c} failed" } ] Command.execute(*args) end end report_success end end true end # Clone on Windows # # === Return # true:: Always return true def run_windows # TBD end end end