Sha256: 28b6b4606c5c9e21eaa1126d36f1372813fd43a21bf6f8d4da1b69ecc4930c54

Contents?: true

Size: 1.52 KB

Versions: 10

Compression:

Stored size: 1.52 KB

Contents

module Shipit
  class EphemeralCommitChecks
    FINAL_STATUSES = %w(failed error success).freeze

    def initialize(commit)
      @commit = commit
    end

    attr_accessor :status
    attr_reader :output

    def run
      self.status = 'running'
      commands = StackCommands.new(stack)
      commands.with_temporary_working_directory(commit: commit) do |directory|
        deploy_spec = DeploySpec::FileSystem.new(directory, stack.environment)
        capture_all(build_commands(deploy_spec.dependencies_steps, chdir: directory))
        capture_all(build_commands(deploy_spec.review_checks, chdir: directory))
      end
      self
    rescue Command::Error
      self.status = 'failed'
      self
    rescue
      self.status = 'error'
      raise
    else
      self.status = 'success'
      self
    end

    def success?
      status == 'success'
    end

    def finished?
      FINAL_STATUSES.include?(status)
    end

    def write(output)
      @output ||= ''
      @output += output
    end

    private

    def build_commands(commands, chdir:)
      commands.map { |c| Command.new(c, env: Shipit.env, chdir: chdir) }
    end

    def capture_all(commands)
      commands.map { |c| capture(c) }
    end

    def capture(command)
      command.start
      write("$ #{command}\n")
      command.stream! do |line|
        write(line)
      end
    rescue Command::Error => error
      write(error.message)
      raise
    ensure
      write("\n")
    end

    attr_reader :commit

    def stack
      @stack ||= commit.stack
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
shipit-engine-0.31.0 app/models/shipit/ephemeral_commit_checks.rb
shipit-engine-0.30.0 app/models/shipit/ephemeral_commit_checks.rb
shipit-engine-0.29.0 app/models/shipit/ephemeral_commit_checks.rb
shipit-engine-0.28.1 app/models/shipit/ephemeral_commit_checks.rb
shipit-engine-0.28.0 app/models/shipit/ephemeral_commit_checks.rb
shipit-engine-0.27.1 app/models/shipit/ephemeral_commit_checks.rb
shipit-engine-0.27.0 app/models/shipit/ephemeral_commit_checks.rb
shipit-engine-0.26.0 app/models/shipit/ephemeral_commit_checks.rb
shipit-engine-0.25.1 app/models/shipit/ephemeral_commit_checks.rb
shipit-engine-0.25.0 app/models/shipit/ephemeral_commit_checks.rb