Class: Everywhere::Commands::PlatformBuild

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/everywhere/commands/platform/build.rb

Overview

every platform build — hosted build (Model B): snapshot the source, upload it straight to storage, submit a build for the configured targets, then tail logs and pull the finished artifacts. No local toolchain needed.

Defined Under Namespace

Classes: TargetSpec

Instance Method Summary collapse

Instance Method Details

#call(root: ".", url: nil, target: nil, channel: "direct", ruby: nil, output: nil, wait: true, download: true) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/everywhere/commands/platform/build.rb', line 32

def call(root: ".", url: nil, target: nil, channel: "direct", ruby: nil, output: nil,
         wait: true, download: true, **)
  root_path = File.expand_path(root)
  config = Everywhere::Config.load(root_path)
  base = Everywhere::Platform::Client.base_url(url)
  creds = Everywhere::Platform::Credentials.load.for(base)
  UI.die!("not logged in to #{base} — run `every platform login`") unless creds

  client = Everywhere::Platform::Client.new(base, token: creds["token"])
  framework = config.remote? ? nil : Everywhere::Framework.detect(root_path)
  specs = resolve_targets(target, config, channel)
  ruby ||= config.build_ruby || "4.0.6"

  Dir.mktmpdir("every-snapshot") do |tmp|
    signed_id = snapshot_and_upload(client, root_path, tmp)
    manifests = build_manifests(root_path, config, framework, ruby, specs)

    build = submit(client, specs, channel, signed_id, manifests)
    UI.success("submitted #{UI.bold(build["id"])} for #{specs.map(&:display_label).join(", ")}")
    if (build_url = build["url"] || "#{client.base_url}/builds/#{build["id"]}")
      UI.substep("watch it live → #{UI.cyan(build_url)}")
    end

    return unless wait

    # Set expectations before the quiet part: a hosted runner is not
    # instant, and knowing that up front is the difference between "slow"
    # and "broken".
    UI.substep(UI.dim("#{runner_wait_subject(specs)} usually start within a few minutes"))
    final = poll_and_tail(client, build["id"], build_url)
    report(client, final, output || File.join(root_path, "dist"), download)
  end
rescue Everywhere::Error => e
  UI.die!(e.message)
end