Class: Match::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/match/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#changes_to_commitObject

Returns the value of attribute changes_to_commit.



3
4
5
# File 'lib/match/runner.rb', line 3

def changes_to_commit
  @changes_to_commit
end

Instance Method Details

#certificate(params: nil) ⇒ Object



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
67
# File 'lib/match/runner.rb', line 38

def certificate(params: nil)
  cert_type = :distribution
  cert_type = :development if params[:type] == "development"
  cert_type = :enterprise if Match.enterprise? && params[:type] == "enterprise"

  certs = Dir[File.join(params[:workspace], "certs", cert_type.to_s, "*.cer")]
  keys = Dir[File.join(params[:workspace], "certs", cert_type.to_s, "*.p12")]

  if certs.count == 0 or keys.count == 0
    UI.important "Couldn't find a valid code signing identity in the git repo for #{cert_type}... creating one for you now"
    UI.crash!("No code signing identity found and can not create a new one because you enabled `readonly`") if params[:readonly]
    cert_path = Generator.generate_certificate(params, cert_type)
    self.changes_to_commit = true
  else
    cert_path = certs.last
    UI.message "Installing certificate..."

    if FastlaneCore::CertChecker.installed?(cert_path)
      UI.verbose "Certificate '#{File.basename(cert_path)}' is already installed on this machine"
    else
      Utils.import(cert_path, params[:keychain_name])
    end

    # Import the private key
    # there seems to be no good way to check if it's already installed - so just install it
    Utils.import(keys.last, params[:keychain_name])
  end

  return File.basename(cert_path).gsub(".cer", "") # Certificate ID
end

#profile(params: nil, certificate_id: nil) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/match/runner.rb', line 69

def profile(params: nil, certificate_id: nil)
  prov_type = params[:type].to_sym

  profile_name = [prov_type.to_s, params[:app_identifier]].join("_").gsub("*", '\*') # this is important, as it shouldn't be a wildcard
  profiles = Dir[File.join(params[:workspace], "profiles", prov_type.to_s, "#{profile_name}.mobileprovision")]

  # Install the provisioning profiles
  profile = profiles.last
  if profile.nil? or params[:force]
    UI.crash!("No matching provisioning profiles found and can not create a new one because you enabled `readonly`") if params[:readonly]
    profile = Generator.generate_provisioning_profile(params: params,
                                                   prov_type: prov_type,
                                              certificate_id: certificate_id)
    self.changes_to_commit = true
  end

  FastlaneCore::ProvisioningProfile.install(profile)

  parsed = FastlaneCore::ProvisioningProfile.parse(profile)
  uuid = parsed["UUID"]
  Utils.fill_environment(params, uuid)

  return uuid
end

#run(params) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/match/runner.rb', line 5

def run(params)
  FastlaneCore::PrintTable.print_values(config: params,
                                     hide_keys: [:workspace],
                                         title: "Summary for match #{Match::VERSION}")

  params[:workspace] = GitHelper.clone(params[:git_url], params[:shallow_clone])
  spaceship = SpaceshipEnsure.new(params[:username]) unless params[:readonly]

  # Verify the App ID (as we don't want 'match' to fail at a later point)
  spaceship.bundle_identifier_exists(params) if spaceship

  # Certificate
  cert_id = certificate(params: params)
  spaceship.certificate_exists(params, cert_id) if spaceship

  # Provisioning Profile
  uuid = profile(params: params,
                 certificate_id: cert_id)
  spaceship.profile_exists(params, uuid) if spaceship

  # Done
  if self.changes_to_commit
    message = GitHelper.generate_commit_message(params)
    GitHelper.commit_changes(params[:workspace], message, params[:git_url])
  end

  TablePrinter.print_summary(params, uuid)

  UI.success "All required keys, certificates and provisioning profiles are installed 🙌".green
ensure
  GitHelper.clear_changes
end