class Soaring::Packager
Public Class Methods
new(options)
click to toggle source
# File lib/soaring/packager.rb, line 5 def initialize(options) @options = options end
Public Instance Methods
package()
click to toggle source
# File lib/soaring/packager.rb, line 9 def package Dir.chdir(@options[:project_root]) do validate_project if not @options[:ignore_git_checks] build_output_location = generate_build_output_location(@options[:project_root]) update_project_release_information `mkdir -p #{@options[:project_root]}/build` `zip -r --symlinks #{build_output_location} -@ < build-package-manifest` puts "Packaged build to #{build_output_location}" end end
Private Instance Methods
generate_build_output_location(project_folder)
click to toggle source
# File lib/soaring/packager.rb, line 30 def generate_build_output_location(project_folder) service_name = File.split(project_folder)[-1] timestamp = Time.now.strftime("%F-%H%M%S") "#{project_folder}/build/build_#{service_name}_#{get_short_commit_hash}_#{timestamp}.zip" end
get_git_commit_date()
click to toggle source
# File lib/soaring/packager.rb, line 54 def get_git_commit_date `git show -s --format=%cI`.chomp end
get_git_commit_hash()
click to toggle source
# File lib/soaring/packager.rb, line 44 def get_git_commit_hash git_hash = `git rev-parse HEAD`.chomp git_hash = /\A[0-9a-f]{5,40}\z/.match(git_hash) if git_hash.nil? $stderr.puts 'Failed to package, unable to get commit hash from local git repository' exit 1 end git_hash[0] end
get_short_commit_hash()
click to toggle source
# File lib/soaring/packager.rb, line 64 def get_short_commit_hash response, exit_status = Executor::execute("git rev-parse --short HEAD") if not exit_status.success? puts 'Failed to package, unable to get short commit hash from local git repository' exit 1 end response.chomp end
is_git_repo_up_to_date?()
click to toggle source
# File lib/soaring/packager.rb, line 58 def is_git_repo_up_to_date? response, exit_status = Executor::execute("git status --porcelain") return true if ('' == response) and (exit_status.success?) false end
update_project_release_information()
click to toggle source
# File lib/soaring/packager.rb, line 36 def update_project_release_information release_information = { 'commit_hash' => get_git_commit_hash, 'commit_date' => get_git_commit_date } File.open(".release_information", "w") do |file| file.write release_information.to_yaml end end
validate_project()
click to toggle source
# File lib/soaring/packager.rb, line 22 def validate_project if not is_git_repo_up_to_date? puts "Local git repo is dirty and should not be packaged" exit 1 end puts 'Local git repo up to date.' if @options[:verbose] end