class Envirobly::Deployment

def perform(dry_run:)

def perform(dry_run:)
  puts [ "Deploying commit", yellow(@commit.short_ref), faint("→"), green(@environ_name) ].join(" ")
  puts
  puts "    #{@commit.message}"
  puts
  if dry_run
    puts YAML.dump(@params)
    return
  end
  # Create deployment
  api = Envirobly::Api.new
  Envirobly::Duration.measure do
    response = api.create_deployment @params
    unless response.success?
      display_config_errors response.object.fetch("errors")
      exit 1
    end
    print "Preparing project..."
    @default_account.save_if_none response.object.fetch("account_id")
    @default_project.save_if_none response.object.fetch("project_id")
    @default_region.save_if_none response.object.fetch("region")
    # Fetch credentials for build context upload
    @deployment_url = response.object.fetch("url")
    @credentials_response = api.get_deployment_with_delay_and_retry @deployment_url
  end
  credentials = @credentials_response.object.fetch("credentials")
  region = @credentials_response.object.fetch("region")
  bucket = @credentials_response.object.fetch("bucket")
  watch_deployment_url = @credentials_response.object.fetch("deployment_url")
  Envirobly::Duration.measure do
    # Upload build context
    Envirobly::Aws::S3.new(bucket:, region:, credentials:).push @commit
    # Perform deployment
    api.put_as_json @deployment_url
  end
  puts "Follow at #{watch_deployment_url}"
end