class Tasks::Toolbelt::Build::Tarball < Tasks::Toolbelt around_ensure :cleanup def call # checkout requested revision checkout_revision # clean directories clean # copy files into release copy_files_into_release add_quandl_executable # add revision when given append_revision_to_release_version unless git_branch == 'master' # vendorize the bundle copy_vendored_gems # build tar package_release_into_tar end protected def add_quandl_executable resource_path = options.platform.present? ? "#{options.platform}/quandl" : "pkg/quandl" mkdir_p("#{release_path}/pkg") unless Dir.exists?("#{release_path}/pkg") cp resource(resource_path), "#{release_path}/pkg/quandl" end def checkout_revision raise "You have unstaged commits." if %x{git status} =~ /Changes not staged for commit/ sh "git checkout #{options.revision}" raise "Unable to checkout #{options.revision}" unless %x{git branch | grep '*'} =~ /#{options.revision}/ end def copy_files_into_release # for each path ['lib', 'bin', 'config', 'VERSION'].each do |path| # recursively copy into release cp_r File.join( root_path, path ), File.join( release_path, path ) end end def clean rm_rf tarball_path # create release mkdir_p release_path end def append_revision_to_release_version version_file = File.join( release_path, 'VERSION') IO.write(version_file, File.open(version_file) do |f| f.read.gsub(version, "#{version} #{prerelease_information}") end ) end def copy_vendored_gems Bundler.with_clean_env do sh( "bundle install --without development test --path #{release_path}/vendor" ) mv File.join(release_path, "vendor/ruby/1.9.1/gems"), File.join(release_path, "vendor") rm_rf File.join(release_path, "vendor/ruby") end end def package_release_into_tar # path to tarball tarball_filename = File.basename([ release_path, revision, 'tar.gz' ].compact.join(".")) # enter tarball build directory Dir.chdir(tarball_path) do # create targz Tar.pack( 'quandl-command', File.join(tarball_path, tarball_filename) ) end end def cleanup rm_rf File.join( root_path, '.bundle') end end