Sha256: 0dabfb5b9c538678d5485602edd6b3ca1484661e61cf275193d696204c112619

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module Soaring
  class Packager
    def initialize(options)
      @options = options
    end

    def package(project_folder)
      validate_project if not @options[:ignore_git_checks]
      build_output_location = generate_build_output_location(project_folder)
      `mkdir -p #{project_folder}/build`
      `zip -r #{build_output_location} * .ebextensions -x build -x config/environment.yml`
      puts "Build packaged at #{build_output_location}"
    end

    private

    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

    def generate_build_output_location(project_folder)
      service_name = File.split(project_folder)[-1]
      revision_hash = `git rev-parse --short HEAD`.chomp
      timestamp = Time.now.strftime("%F-%H%M%S")
      "#{project_folder}/build/build_#{service_name}_#{revision_hash}_#{timestamp}.zip"
    end

    def is_git_repo_up_to_date?
      git_response = `git status --porcelain`.chomp
      return true if '' == git_response
      false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
soaring-0.1.6 lib/soaring/packager.rb