Sha256: 6e285a911b6febcadb0af5cb25bdb0a7a9955ed46829d25c2bef2c0f2b35fc49

Contents?: true

Size: 1.62 KB

Versions: 20

Compression:

Stored size: 1.62 KB

Contents

class TaskCommands < Commands
  delegate :fetch, to: :stack_commands

  def initialize(task)
    @task = task
    @stack = task.stack
  end

  def deploy_spec
    @deploy_spec ||= DeploySpec::FileSystem.new(@task.working_directory, @stack.environment)
  end

  def install_dependencies
    deploy_spec.dependencies_steps!.map do |command_line|
      Command.new(command_line, env: env, chdir: steps_directory)
    end
  end

  def perform
    steps.map do |command_line|
      Command.new(command_line, env: env, chdir: steps_directory)
    end
  end

  def steps
    @task.definition.steps
  end

  def env
    normalized_name = ActiveSupport::Inflector.transliterate(@task.author.name)
    super.merge(
      'ENVIRONMENT' => @stack.environment,
      'USER' => "#{@task.author.login} (#{normalized_name}) via Shipit",
      'EMAIL' => @task.author.email,
      'BUNDLE_PATH' => Rails.root.join('data', 'bundler').to_s,
      'SHIPIT_LINK' => permalink,
      'LAST_DEPLOYED_SHA' => @stack.last_deployed_commit.sha,
    ).merge(deploy_spec.machine_env).merge(@task.env)
  end

  def checkout(commit)
    git('checkout', commit.sha, chdir: @task.working_directory)
  end

  def clone
    git('clone', '--local', @stack.git_path, @task.working_directory, chdir: @stack.deploys_path)
  end

  def stack_commands
    @stack_commands = StackCommands.new(@stack)
  end

  protected

  def steps_directory
    if sub_directory = deploy_spec.directory.presence
      File.join(@task.working_directory, sub_directory)
    else
      @task.working_directory
    end
  end

  def permalink
    Shipit::Engine.routes.url_helpers.stack_task_url(@stack, @task)
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
shipit-engine-0.5.2 lib/task_commands.rb
shipit-engine-0.5.1 lib/task_commands.rb
shipit-engine-0.5.0 lib/task_commands.rb
shipit-engine-0.4.10 lib/task_commands.rb
shipit-engine-0.4.9 lib/task_commands.rb
shipit-engine-0.4.8 lib/task_commands.rb
shipit-engine-0.4.7 lib/task_commands.rb
shipit-engine-0.4.6 lib/task_commands.rb
shipit-engine-0.4.5 lib/task_commands.rb
shipit-engine-0.4.4 lib/task_commands.rb
shipit-engine-0.4.3 lib/task_commands.rb
shipit-engine-0.4.2 lib/task_commands.rb
shipit-engine-0.4.1 lib/task_commands.rb
shipit-engine-0.4.0 lib/task_commands.rb
shipit-engine-0.3.1 lib/task_commands.rb
shipit-engine-0.3.0 lib/task_commands.rb
shipit-engine-0.2.3 lib/task_commands.rb
shipit-engine-0.2.2 lib/task_commands.rb
shipit-engine-0.2.1 lib/task_commands.rb
shipit-engine-0.2.0 lib/task_commands.rb