Sha256: 05cb729d7512056cd101a77120499ca03db057ca21609afbe5322af92ff73124

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

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

    def package(project_folder)
      validate_project
      build_output_location = generate_build_output_location
      `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?) and (not @options[:ignore_git_checks])
        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
      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

2 entries across 2 versions & 1 rubygems

Version Path
soaring-0.1.3 lib/soaring/packager.rb
soaring-0.1.2 lib/soaring/packager.rb