Class: Deliver::DeliverProcess

Inherits:
Object
  • Object
show all
Defined in:
lib/deliver/deliver_process.rb

Overview

This class takes care of verifying all inputs and triggering the upload process

Defined Under Namespace

Classes: DeliverUnitTestsError

Instance Attribute Summary collapse

All the methods collapse

Instance Method Summary collapse

Constructor Details

#initialize(deploy_information = nil) ⇒ DeliverProcess

Returns a new instance of DeliverProcess.



22
23
24
25
# File 'lib/deliver/deliver_process.rb', line 22

def initialize(deploy_information = nil)
  @deploy_information = deploy_information || {}
  @deploy_information[:blocks] ||= {}
end

Instance Attribute Details

#appDeliver::App

Returns The App that is currently being edited.

Returns:

  • (Deliver::App)

    The App that is currently being edited.



10
11
12
# File 'lib/deliver/deliver_process.rb', line 10

def app
  @app
end

#app_identifierString

Returns : The app identifier of the currently used app (e.g. com.krausefx.app).

Returns:

  • (String)

    : The app identifier of the currently used app (e.g. com.krausefx.app)



20
21
22
# File 'lib/deliver/deliver_process.rb', line 20

def app_identifier
  @app_identifier
end

#deploy_informationHash

Returns All the updated/new information we got from the Deliverfile. is used to store the deploy information until the Deliverfile finished running.

Returns:

  • (Hash)

    All the updated/new information we got from the Deliverfile. is used to store the deploy information until the Deliverfile finished running.



17
18
19
# File 'lib/deliver/deliver_process.rb', line 17

def deploy_information
  @deploy_information
end

#ipaDeliver::IpaUploader

Returns The IPA uploader that is currently being used.

Returns:



13
14
15
# File 'lib/deliver/deliver_process.rb', line 13

def ipa
  @ipa
end

Instance Method Details

#additional_itc_informationObject



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/deliver/deliver_process.rb', line 240

def additional_itc_information
  # e.g. rating or copyright
  itc = ItunesConnect.new
  itc.set_copyright!(@app, @deploy_information[Deliverer::ValKey::COPYRIGHT]) if @deploy_information[Deliverer::ValKey::COPYRIGHT]
  itc.set_app_review_information!(@app, @deploy_information[Deliverer::ValKey::APP_REVIEW_INFORMATION]) if @deploy_information[Deliverer::ValKey::APP_REVIEW_INFORMATION]
  itc.set_release_after_approval!(@app, @deploy_information[Deliverer::ValKey::AUTOMATIC_RELEASE]) if @deploy_information[Deliverer::ValKey::AUTOMATIC_RELEASE]

  # Categories
  primary = @deploy_information[Deliverer::ValKey::PRIMARY_CATEGORY]
  secondary = @deploy_information[Deliverer::ValKey::SECONDARY_CATEGORY]
  itc.set_categories!(@app, primary, secondary) if (primary or secondary)

  # App Rating
  itc.set_app_rating!(@app, @deploy_information[Deliverer::ValKey::RATINGS_CONFIG_PATH]) if @deploy_information[Deliverer::ValKey::RATINGS_CONFIG_PATH]

  # App Icon
  itc.upload_app_icon!(@app, @deploy_information[Deliverer::ValKey::APP_ICON]) if @deploy_information[Deliverer::ValKey::APP_ICON]
end

#call_error_block(ex) ⇒ Object



275
276
277
278
279
280
281
282
283
# File 'lib/deliver/deliver_process.rb', line 275

def call_error_block(ex)
  if @deploy_information[:blocks][:error]
    # Custom error handling, we just call this one
    @deploy_information[:blocks][:error].call(hash_for_callback(ex))
  end
  
  # Re-Raise the exception
  raise ex
end

#call_success_blockObject



269
270
271
272
273
# File 'lib/deliver/deliver_process.rb', line 269

def call_success_block
  if @deploy_information[:blocks][:success]
    @deploy_information[:blocks][:success].call(hash_for_callback)
  end
end

#create_appObject



129
130
131
132
# File 'lib/deliver/deliver_process.rb', line 129

def create_app
  @app = Deliver::App.new(app_identifier: @app_identifier,
                                apple_id: @deploy_information[Deliverer::ValKey::APPLE_ID])
end

#fetch_app_identifier_from_app_fileObject



119
120
121
# File 'lib/deliver/deliver_process.rb', line 119

def fetch_app_identifier_from_app_file
  @app_identifier = (CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier) rescue nil)
end

#fetch_information_from_ipa_fileObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/deliver/deliver_process.rb', line 77

def fetch_information_from_ipa_file
  @app_version = @deploy_information[Deliverer::ValKey::APP_VERSION]
  @app_identifier = @deploy_information[Deliverer::ValKey::APP_IDENTIFIER]

  if is_release_build?
    used_ipa_file = @deploy_information[:ipa]
  elsif is_beta_build?
    used_ipa_file = @deploy_information[:beta_ipa]
  end

  if used_ipa_file.kind_of?Proc
    # The user provided a block. We only want to execute the block now, since it might be a long build step
    used_ipa_file = used_ipa_file.call

    Deliverfile::Deliverfile::DSL.validate_ipa!(used_ipa_file)
  end
  
  if (used_ipa_file || '').length == 0 and is_beta_build?
    # Beta Release but no ipa given
    raise "Could not find an ipa file for 'beta' mode. Provide one using `beta_ipa do ... end` in your Deliverfile.".red
  end

  ENV["DELIVER_IPA_PATH"] = used_ipa_file

  if used_ipa_file
    upload_strategy = Deliver::IPA_UPLOAD_STRATEGY_APP_STORE
    if is_beta_build?
      upload_strategy = Deliver::IPA_UPLOAD_STRATEGY_BETA_BUILD
    end
    if skip_deployment?
      upload_strategy = Deliver::IPA_UPLOAD_STRATEGY_JUST_UPLOAD
    end

    @ipa = Deliver::IpaUploader.new(Deliver::App.new, '/tmp/', used_ipa_file, upload_strategy)

    # We are able to fetch some metadata directly from the ipa file
    # If they were also given in the Deliverfile, we will compare the values
    @app_identifier = verify_app_identifier(@app_identifier)
    @app_version = verify_app_version(@app_version)
  end
end

#load_metadata_from_config_json_folderObject



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
# File 'lib/deliver/deliver_process.rb', line 142

def 
  return unless @deploy_information[Deliverer::ValKey::CONFIG_JSON_FOLDER]

  matching = {
    'title' => Deliverer::ValKey::TITLE,
    'description' => Deliverer::ValKey::DESCRIPTION,
    'version_whats_new' => Deliverer::ValKey::CHANGELOG,
    'keywords' => Deliverer::ValKey::KEYWORDS,
    'privacy_url' => Deliverer::ValKey::PRIVACY_URL,
    'software_url' => Deliverer::ValKey::MARKETING_URL,
    'support_url' => Deliverer::ValKey::SUPPORT_URL
  }

  file_path = @deploy_information[:config_json_folder]
  unless file_path.split("/").last.include?"metadata.json"
    file_path += "/metadata.json"
  end

  raise "Could not find metadatafile at path '#{file_path}'".red unless File.exists?file_path

  content = JSON.parse(File.read(file_path))
  content.each do |language, current|

    matching.each do |key, value|
      if current[key]
        @deploy_information[value] ||= {}
        @deploy_information[value][language] ||= current[key]
      end
    end
  end
end

#runObject



27
28
29
30
31
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
# File 'lib/deliver/deliver_process.rb', line 27

def run
  begin
    run_unit_tests
    fetch_information_from_ipa_file

    verify_ipa_file

    Helper.log.info("Got all information needed to deploy a new update ('#{@app_version}') for app '#{@app_identifier}'")

    create_app
    verify_app_on_itunesconnect

    unless is_beta_build?
      # App Metdata will not be updated for beta builds

       # the json file generated from the quick start
      
      set_screenshots

      verify_pdf_file

      additional_itc_information # e.g. copyright, age rating

      
    end

    # Always upload a new ipa (except if none was given)
    trigger_ipa_upload

    call_success_block
  rescue => ex
    call_error_block(ex)
  end
end

#run_unit_testsObject



66
67
68
69
70
71
72
73
74
75
# File 'lib/deliver/deliver_process.rb', line 66

def run_unit_tests
  if @deploy_information[:blocks][:unit_tests]
    result = @deploy_information[:blocks][:unit_tests].call
    if result
      Helper.log.debug("Unit tests successful".green)
    else
      raise DeliverUnitTestsError.new("Unit tests failed. Got result: '#{result}'. Need 'true' or 1 to succeed.".red)
    end
  end
end

#set_app_metadataObject



174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/deliver/deliver_process.rb', line 174

def 
  @app..update_title(@deploy_information[Deliverer::ValKey::TITLE]) if @deploy_information[Deliverer::ValKey::TITLE]
  @app..update_description(@deploy_information[Deliverer::ValKey::DESCRIPTION]) if @deploy_information[Deliverer::ValKey::DESCRIPTION]

  @app..update_support_url(@deploy_information[Deliverer::ValKey::SUPPORT_URL]) if @deploy_information[Deliverer::ValKey::SUPPORT_URL]
  @app..update_changelog(@deploy_information[Deliverer::ValKey::CHANGELOG]) if @deploy_information[Deliverer::ValKey::CHANGELOG]
  @app..update_marketing_url(@deploy_information[Deliverer::ValKey::MARKETING_URL]) if @deploy_information[Deliverer::ValKey::MARKETING_URL]
  @app..update_privacy_url(@deploy_information[Deliverer::ValKey::PRIVACY_URL]) if @deploy_information[Deliverer::ValKey::PRIVACY_URL]

  @app..update_keywords(@deploy_information[Deliverer::ValKey::KEYWORDS]) if @deploy_information[Deliverer::ValKey::KEYWORDS]

  @app..update_price_tier(@deploy_information[Deliverer::ValKey::PRICE_TIER]) if @deploy_information[Deliverer::ValKey::PRICE_TIER]
end

#set_screenshotsObject



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/deliver/deliver_process.rb', line 189

def set_screenshots
  screens_path = @deploy_information[Deliverer::ValKey::SCREENSHOTS_PATH]

  if (ENV["DELIVER_SCREENSHOTS_PATH"] || '').length > 0
    Helper.log.warn "Overwriting screenshots path from config (#{screens_path}) with (#{ENV["DELIVER_SCREENSHOTS_PATH"]})".yellow
    screens_path = ENV["DELIVER_SCREENSHOTS_PATH"]
  end
  
  if screens_path
    # Not using Snapfile. Not a good user.
    if not @app..set_all_screenshots_from_path(screens_path)
      # This path does not contain folders for each language
      if screens_path.kind_of?String
        if @deploy_information[Deliverer::ValKey::DEFAULT_LANGUAGE]
          screens_path = { @deploy_information[Deliverer::ValKey::DEFAULT_LANGUAGE] => screens_path } # use the default language
          @deploy_information[Deliverer::ValKey::SCREENSHOTS_PATH] = screens_path
        else
          Helper.log.error "You must have folders for the screenshots (#{screens_path}) for each language (e.g. en-US, de-DE)."
          screens_path = nil
        end
      end
      @app..set_screenshots_for_each_language(screens_path) if screens_path
    end
  end
end

#trigger_ipa_uploadObject



259
260
261
262
263
264
265
266
267
# File 'lib/deliver/deliver_process.rb', line 259

def trigger_ipa_upload
  if @ipa
    @ipa.app = @app # we now have the resulting app
    result = @ipa.upload! # Important: this will also actually deploy the app on iTunesConnect
    raise "Error uploading ipa file".red unless result == true
  else
    Helper.log.warn "No IPA file given. Only the metadata was uploaded. If you want to deploy a full update, provide an ipa file."
  end
end

#trigger_metadata_uploadObject



235
236
237
238
# File 'lib/deliver/deliver_process.rb', line 235

def 
  result = @app..upload!
  raise "Error uploading app metadata".red unless result == true
end

#verify_app_on_itunesconnectObject



134
135
136
137
138
139
140
# File 'lib/deliver/deliver_process.rb', line 134

def verify_app_on_itunesconnect
  if @ipa and is_release_build?
    # This is a real release, which should also upload the ipa file onto production
    @app.create_new_version!(@app_version) unless Helper.is_test?
    @app..verify_version(@app_version)
  end
end

#verify_ipa_fileObject



123
124
125
126
127
# File 'lib/deliver/deliver_process.rb', line 123

def verify_ipa_file
  fetch_app_identifier_from_app_file unless @app_identifier
  raise Deliverfile::Deliverfile::DeliverfileDSLError.new(Deliverfile::Deliverfile::MISSING_APP_IDENTIFIER_MESSAGE.red) unless @app_identifier
  raise Deliverfile::Deliverfile::DeliverfileDSLError.new(Deliverfile::Deliverfile::MISSING_VERSION_NUMBER_MESSAGE.red) unless @app_version
end

#verify_pdf_fileObject



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/deliver/deliver_process.rb', line 215

def verify_pdf_file
  if @deploy_information[Deliverer::ValKey::SKIP_PDF]
    Helper.log.debug "PDF verify was skipped"
  else
    # Everything is prepared for the upload
    # We may have to ask the user if that's okay
    pdf_path = PdfGenerator.new.render(self)
    unless Helper.is_test?
      puts "----------------------------------------------------------------------------"
      puts "Verifying the upload via the PDF file can be disabled by either adding"
      puts "'skip_pdf true' to your Deliverfile or using the flag --force."
      puts "----------------------------------------------------------------------------"

      system("open '#{pdf_path}'")
      okay = agree("Does the PDF on path '#{pdf_path}' look okay for you? (blue = updated) (y/n)", true)
      raise "Did not upload the metadata, because the PDF file was rejected by the user".yellow unless okay
    end
  end
end