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: DeliverUIAutomationError, 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.



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

def app
  @app
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.



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

def deploy_information
  @deploy_information
end

Instance Method Details

#call_error_block(ex) ⇒ Object



225
226
227
228
229
230
231
232
233
# File 'lib/deliver/deliver_process.rb', line 225

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

#call_success_blockObject



221
222
223
# File 'lib/deliver/deliver_process.rb', line 221

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

#create_appObject



92
93
94
95
# File 'lib/deliver/deliver_process.rb', line 92

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

#fetch_information_from_ipa_fileObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/deliver/deliver_process.rb', line 68

def fetch_information_from_ipa_file
  @app_version = @deploy_information[Deliverer::ValKey::APP_VERSION]
  @app_identifier = @deploy_information[Deliverer::ValKey::APP_IDENTIFIER]
  
  used_ipa_file = @deploy_information[:ipa] || @deploy_information[:beta_ipa]

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

    # 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



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/deliver/deliver_process.rb', line 105

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

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

    verify_ipa_file
    create_app
    verify_app_on_itunesconnect

     # the json file generated from the quick start
    
    set_screenshots
    
    verify_pdf_file

    
    trigger_ipa_upload

    call_success_block
  rescue Exception => ex
    call_error_block(ex)
  end
end

#run_unit_testsObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/deliver/deliver_process.rb', line 57

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



137
138
139
140
141
142
143
144
145
146
147
# File 'lib/deliver/deliver_process.rb', line 137

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]
end

#set_screenshotsObject



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
175
176
177
178
179
180
181
182
183
184
# File 'lib/deliver/deliver_process.rb', line 149

def set_screenshots
  screens_path = @deploy_information[Deliverer::ValKey::SCREENSHOTS_PATH]
  
  # Check if there is a Snapfile
  if File.exists?('./Snapfile') and not screens_path

    Helper.log.info("Found a Snapfile, using it to create new screenshots.".green)
    begin
      Snapshot::Runner.new.work
      Helper.log.info("Looking for screenshots in './screenshots'.".yellow)
      @app..set_all_screenshots_from_path('./screenshots')
    rescue Exception => ex
      # There were some UI Automation errors
      raise DeliverUIAutomationError.new(ex)
    end

  elsif screens_path
    if File.exists?('./Snapfile')
      Helper.log.info("Found a Snapfile. Ignoring it. If you want 'deliver' to automatically take new screenshots for you, remove 'screenshots_path' from your 'Deliverfile'.".yellow)
    end
    # 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



211
212
213
214
215
216
217
218
219
# File 'lib/deliver/deliver_process.rb', line 211

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



206
207
208
209
# File 'lib/deliver/deliver_process.rb', line 206

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

#verify_app_on_itunesconnectObject



97
98
99
100
101
102
103
# File 'lib/deliver/deliver_process.rb', line 97

def verify_app_on_itunesconnect
  if @ipa and not is_beta_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



84
85
86
87
88
89
90
# File 'lib/deliver/deliver_process.rb', line 84

def verify_ipa_file
  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
  if (@deploy_information[Deliverer::ValKey::IPA] and @deploy_information[Deliverer::ValKey::BETA_IPA])
    raise Deliverfile::Deliverfile::DeliverfileDSLError.new("You can not set both ipa and beta_ipa in one file. Either it's a beta build or a release build".red) 
  end
end

#verify_pdf_fileObject



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/deliver/deliver_process.rb', line 186

def verify_pdf_file
  if @deploy_information[Deliverer::ValKey::SKIP_PDF] or is_beta_build?
    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