Class: Fastlane::Actions::VerifyBuildAction

Inherits:
Fastlane::Action show all
Defined in:
lib/fastlane/actions/verify_build.rb

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, lane_context, method_missing, other_action, sample_return_value, sh, step_text

Class Method Details

.app_path(params, dir) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fastlane/actions/verify_build.rb', line 24

def self.app_path(params, dir)
  ipa_path = params[:ipa_path] || Actions.lane_context[SharedValues::IPA_OUTPUT_PATH] || ''
  UI.user_error!("Unable to find ipa file '#{ipa_path}'.") unless File.exist?(ipa_path)
  ipa_path = File.expand_path(ipa_path)

  `unzip '#{ipa_path}' -d #{dir}`
  UI.user_error!("Unable to unzip ipa") unless $? == 0

  app_path = File.expand_path("#{dir}/Payload/*.app")

  app_path
end

.authorsObject



182
183
184
# File 'lib/fastlane/actions/verify_build.rb', line 182

def self.authors
  ["CodeReaper"]
end

.available_optionsObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/fastlane/actions/verify_build.rb', line 139

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :provisioning_type,
                                 env_name: "FL_VERIFY_BUILD_PROVISIONING_TYPE",
                                 description: "Required type of provisioning",
                                 optional: true,
                                 verify_block: proc do |value|
                                   av = %w(distribution development)
                                   UI.user_error!("Unsupported provisioning_type, must be: #{av}") unless av.include?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :provisioning_uuid,
                                 env_name: "FL_VERIFY_BUILD_PROVISIONING_UUID",
                                 description: "Required UUID of provisioning profile",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :team_identifier,
                                 env_name: "FL_VERIFY_BUILD_TEAM_IDENTIFIER",
                                 description: "Required team identifier",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :team_name,
                                 env_name: "FL_VERIFY_BUILD_TEAM_NAME",
                                 description: "Required team name",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :app_name,
                                 env_name: "FL_VERIFY_BUILD_APP_NAME",
                                 description: "Required app name",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :bundle_identifier,
                                 env_name: "FL_VERIFY_BUILD_BUNDLE_IDENTIFIER",
                                 description: "Required bundle identifier",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :ipa_path,
                                 env_name: "FL_VERIFY_BUILD_IPA_PATH",
                                 description: "Explicitly set the ipa path",
                                 optional: true)
  ]
end

.categoryObject



199
200
201
# File 'lib/fastlane/actions/verify_build.rb', line 199

def self.category
  :misc
end

.descriptionObject



131
132
133
# File 'lib/fastlane/actions/verify_build.rb', line 131

def self.description
  "Able to verify various settings in ipa file"
end

.detailsObject



135
136
137
# File 'lib/fastlane/actions/verify_build.rb', line 135

def self.details
  "Verifies that the built app was built using the expected build resources. This is relevant for people who build on machines that are used to build apps with different profiles, certificates and/or bundle identifiers to guard against configuration mistakes."
end

.evaulate(params, values) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/fastlane/actions/verify_build.rb', line 104

def self.evaulate(params, values)
  if params[:provisioning_type]
    UI.user_error!("Mismatched provisioning_type. Required: '#{params[:provisioning_type]}''; Found: '#{values['provisioning_type']}'") unless params[:provisioning_type] == values['provisioning_type']
  end
  if params[:provisioning_uuid]
    UI.user_error!("Mismatched provisioning_uuid. Required: '#{params[:provisioning_uuid]}'; Found: '#{values['provisioning_uuid']}'") unless params[:provisioning_uuid] == values['provisioning_uuid']
  end
  if params[:team_identifier]
    UI.user_error!("Mismatched team_identifier. Required: '#{params[:team_identifier]}'; Found: '#{values['team_identifier']}'") unless params[:team_identifier] == values['team_identifier']
  end
  if params[:team_name]
    UI.user_error!("Mismatched team_name. Required: '#{params[:team_name]}'; Found: 'values['team_name']'") unless params[:team_name] == values['team_name']
  end
  if params[:app_name]
    UI.user_error!("Mismatched app_name. Required: '#{params[:app_name]}'; Found: '#{values['app_name']}'") unless params[:app_name] == values['app_name']
  end
  if params[:bundle_identifier]
    UI.user_error!("Mismatched bundle_identifier. Required: '#{params[:bundle_identifier]}'; Found: '#{values['bundle_identifier']}'") unless params[:bundle_identifier] == values['bundle_identifier']
  end

  UI.success "Build is verified, have a 🍪."
end

.example_codeObject



190
191
192
193
194
195
196
197
# File 'lib/fastlane/actions/verify_build.rb', line 190

def self.example_code
  [
    'verify_build(
      provisioning_type: "distribution",
      bundle_identifier: "com.example.myapp"
    )'
  ]
end

.gather_cert_info(app_path) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fastlane/actions/verify_build.rb', line 37

def self.gather_cert_info(app_path)
  cert_info = `codesign -vv -d #{app_path} 2>&1`
  UI.user_error!("Unable to verify code signing") unless $? == 0

  values = {}

  parts = cert_info.strip.split(/\r?\n/)
  parts.each do |part|
    if part =~ /\AAuthority=i(Phone|OS)/
      type = part.split('=')[1].split(':')[0]
      values['provisioning_type'] = type.downcase =~ /distribution/i ? "distribution" : "development"
    end
    if part.start_with? "TeamIdentifier"
      values['team_identifier'] = part.split('=')[1]
    end
    if part.start_with? "Identifier"
      values['bundle_identifier'] = part.split('=')[1]
    end
  end

  values
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


186
187
188
# File 'lib/fastlane/actions/verify_build.rb', line 186

def self.is_supported?(platform)
  platform == :ios
end

.outputObject



176
177
# File 'lib/fastlane/actions/verify_build.rb', line 176

def self.output
end


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/fastlane/actions/verify_build.rb', line 79

def self.print_values(values)
  table = Terminal::Table.new do |t|
    t.title = 'Summary for VERIFY_BUILD'.green
    t.headings = 'Key', 'Value'
    values.each do |key, value|
      columns = []
      columns << key
      columns << case value
                 when Hash
                   value.map { |k, v| "#{k}: #{v}" }.join("\n")
                 when Array
                   value.join("\n")
                 else
                   value.to_s
                 end

      t << columns
    end
  end

  puts ""
  puts table
  puts ""
end

.return_valueObject



179
180
# File 'lib/fastlane/actions/verify_build.rb', line 179

def self.return_value
end

.run(params) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fastlane/actions/verify_build.rb', line 10

def self.run(params)
  Dir.mktmpdir do |dir|
    app_path = self.app_path(params, dir)

    values = self.gather_cert_info(app_path)

    values = self.update_with_profile_info(app_path, values)

    self.print_values(values)

    self.evaulate(params, values)
  end
end

.update_with_profile_info(app_path, values) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/fastlane/actions/verify_build.rb', line 60

def self.update_with_profile_info(app_path, values)
  profile = `cat #{app_path}/embedded.mobileprovision | security cms -D`
  UI.user_error!("Unable to extract profile") unless $? == 0

  plist = Plist.parse_xml(profile)

  values['app_name'] = plist['AppIDName']
  values['provisioning_uuid'] = plist['UUID']
  values['team_name'] = plist['TeamName']

  application_identifier_prefix = plist['ApplicationIdentifierPrefix'][0]
  full_bundle_identifier = "#{application_identifier_prefix}.#{values['bundle_identifier']}"

  UI.user_error!("Inconsistent identifier found; #{plist['Entitlements']['application-identifier']}, found in the embedded.mobileprovision file, should match #{full_bundle_identifier}, which is embedded in the codesign identity") unless plist['Entitlements']['application-identifier'] == full_bundle_identifier
  UI.user_error!("Inconsistent identifier found") unless plist['Entitlements']['com.apple.developer.team-identifier'] == values['team_identifier']

  values
end