Class: Yolo::Tasks::Ios::Release

Inherits:
BaseTask
  • Object
show all
Defined in:
lib/yolo/tasks/ios/release.rb

Overview

Executes all release related tasks

Author:

  • Alex Fish

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseTask

#name

Constructor Details

#initializeRelease

Initializes the class with default settings



25
26
27
28
29
30
31
32
33
# File 'lib/yolo/tasks/ios/release.rb', line 25

def initialize
  self.sdk = "iphoneos" unless sdk
  self.deployment = :OTA
  @error_formatter = Yolo::Formatters::ErrorFormatter.new
  @emailer = Yolo::Notify::Ios::OTAEmail.new
  @xcode = Yolo::Tools::Ios::Xcode.new
  @bundle_directory = Yolo::Config::Settings.instance.bundle_directory
  super
end

Instance Attribute Details

#deploymentObject

The deployment class to use when deploying



16
17
18
# File 'lib/yolo/tasks/ios/release.rb', line 16

def deployment
  @deployment
end

#github_repoObject

A Github repo to release to



20
21
22
# File 'lib/yolo/tasks/ios/release.rb', line 20

def github_repo
  @github_repo
end

#mail_toArray

Returns the release class’s mail_to attribute, if no attribute is set then check for the config env var

Returns:

  • (Array)

    The release class’s mail_to attribute



14
15
16
# File 'lib/yolo/tasks/ios/release.rb', line 14

def mail_to
  @mail_to
end

#optionsObject

A Hash of additional options



18
19
20
# File 'lib/yolo/tasks/ios/release.rb', line 18

def options
  @options
end

Instance Method Details

#app_pathString

Uses Xcode to find the full path to generated app file

Returns:

  • (String)

    the path to the generated .app file



85
86
87
88
89
90
91
92
# File 'lib/yolo/tasks/ios/release.rb', line 85

def app_path
  files = []
  Find.find(@xcode.build_path) do |path|
    files << path if path =~ /\/Build\/Products\/.*-iphoneos\/#{name}\.app$/
  end
  path = files.sort_by { |filename| File.mtime(filename)}.last # get the latest
  path
end

#bundle_pathString

The full path used when saving files for the build, the path is created using the bundle_directory, folder_name and version methods combined into a single path

Returns:

  • (String)

    the path to save bundle files to



113
114
115
# File 'lib/yolo/tasks/ios/release.rb', line 113

def bundle_path
  "#{@bundle_directory}/#{folder_name}/#{version}"
end

#configurationString

Returns the release class’s configuration attribute, if no attribute is set then check for the config env var

Returns:

  • (String)

    The release class’s configuration attribute



71
72
73
74
75
76
77
78
79
# File 'lib/yolo/tasks/ios/release.rb', line 71

def configuration
  config = @configuration
  
  if !config
    config = ENV['YOLO_RELEASE_CONFIG']
  end

  return config
end

#current_branchString

The current git branch

Returns:

  • (String)

    The current git branch



216
217
218
219
220
221
222
# File 'lib/yolo/tasks/ios/release.rb', line 216

def current_branch
  git = Yolo::Tools::Git.new
  branch = git.current_branch
  if git.current_branch != "(no branch)"
    return "(#{branch})"
  end
end

#defineObject

Defines the rake tasks available to the class



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/yolo/tasks/ios/release.rb', line 241

def define
  super
  namespace :yolo do
    namespace :release do
      desc "Builds and deploys a release ipa of specified scheme."
      task :ipa do
        xcodebuild :build
        Yolo::Tools::Ios::IPA.generate(app_path,dsym_path,bundle_path) do |ipa|
          deploy(ipa) if ipa and self.deployment
          release_to_github(bundle_path) if ipa and self.github_repo
        end
      end

      desc "Builds and packages a release build for the newest git tag"
      task :tag do
        git = Yolo::Tools::Git.new
        if git.has_new_tag(name)
          Rake::Task["yolo:release:ipa"].invoke
        end
      end

      desc "Builds and packages a release build for the newest commit"
      task :commit do
        git = Yolo::Tools::Git.new
        if git.has_new_commit(name)
          Rake::Task["yolo:release:ipa"].invoke
        end
      end

      desc "Generates a release notes file"
      task :notes do
        Yolo::Tools::Ios::ReleaseNotes.generate(info_plist_path)
      end
    end
  end
end

#deploy(ipa_path) ⇒ Object

Deploys the ipa using the defined deployment strategy, the deployment class is created using the deployment variable as the class name so it is crucial the correct class is in the project.

Once deploy is succesful this method will also trigger an email notification using the OTAEmail class

Parameters:

  • ipa_path (String)

    The full path to the IPA file to deploy



169
170
171
172
173
174
175
176
# File 'lib/yolo/tasks/ios/release.rb', line 169

def deploy(ipa_path)
  klass = deploy_class_from_string "#{self.deployment.to_s}"
  if klass
    klass.deploy(ipa_path, options) do |url, password|
      send_notification(url, password)
    end
  end
end

#deploy_class_from_string(string) ⇒ Object

Initlizes an object from a deployment string

Parameters:

  • string (String)

    the deployment class name string

Returns:

  • (Object)

    an object of type specified in the paramater



229
230
231
232
233
234
235
236
# File 'lib/yolo/tasks/ios/release.rb', line 229

def deploy_class_from_string(string)
  klass = Object.const_get("Yolo").const_get("Deployment").const_get("#{self.deployment.to_s}").new
  unless klass
    @error_formatter.deployment_class_error(self.deployment.to_s)
    return
  end
  klass
end

#dsym_pathString

The path to the applications dSYM folder, the dSYM path is calculated by manipulating the app_path

Returns:

  • (String)

    the full path to the dSYM folder



99
100
101
102
103
104
105
# File 'lib/yolo/tasks/ios/release.rb', line 99

def dsym_path
  paths = app_path.split("/")
  app_file = paths.last
  paths.pop
  path = paths.join("/")
  "#{path}/#{app_file}.dSYM"
end

#folder_nameString

The folder name to use for the build bundle directory, the name is created using the relevant scheme and build configuration

Returns:

  • (String)

    a folder name used in the bundle path



122
123
124
125
126
# File 'lib/yolo/tasks/ios/release.rb', line 122

def folder_name
  folder_name = name
  folder_name = "#{name}-#{self.configuration}" if self.configuration
  folder_name
end

#info_plist_pathString

The path to the info-plist file, the method persumes that the command is being called from the directory which contains the plist

Returns:

  • (String)

    the full path to the projects plist file



133
134
135
136
137
138
139
# File 'lib/yolo/tasks/ios/release.rb', line 133

def info_plist_path
  plist_path = ""
  Find.find(Dir.pwd) do |path|
    plist_path = path if path =~ /#{name}-Info.plist$/
  end
  plist_path
end

#release_to_github(bundle_path) ⇒ Object

Release the ipa using the github releases API, the ipa will be zipped and uploaded as well as the release notes used as the release body and version for the release title

Parameters:

  • ipa_path (String)

    The full path to the IPA file to deploy



185
186
187
188
189
190
191
192
# File 'lib/yolo/tasks/ios/release.rb', line 185

def release_to_github(bundle_path)
  if self.github_repo
    github = Yolo::Tools::Github.new
    notes = Yolo::Tools::Ios::ReleaseNotes.html
    github.repo = self.github_repo
    github.release(bundle_path, version, notes)
  end
end

#schemeString

Returns the release class’s scheme attribute, if no attribute is set then check for the scheme env var

Returns:

  • (String)

    The release class’s scheme attribute



56
57
58
59
60
61
62
63
64
# File 'lib/yolo/tasks/ios/release.rb', line 56

def scheme
  scheme = @scheme

  if !scheme
    scheme = ENV['YOLO_RELEASE_SCHEME']
  end

  return scheme
end

#send_notification(url, password) ⇒ Object

Sends a notificaiton email from a deployment

Parameters:

  • url (String)

    The URL which the build has been deplyed too

  • password (String)

    The password required to install the build



199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/yolo/tasks/ios/release.rb', line 199

def send_notification(url, password)
  if url
    mail_options = {
      :to => self.mail_to,
      :ota_url => url,
      :subject => "New #{name} build: #{version} #{current_branch}",
      :title => name
    }
    mail_options[:ota_password] = password if password
    @emailer.send(mail_options)
  end
end

#versionString

The version string of the built application if the version number can not be retrieved from Xcode the current date time will be used

Returns:

  • (String)

    the applications version number



147
148
149
150
151
152
153
154
155
156
157
# File 'lib/yolo/tasks/ios/release.rb', line 147

def version
  @xcode.info_plist_path = info_plist_path
  folder = ""
  folder << @xcode.version_number if @xcode.version_number
  folder << "-#{@xcode.build_number}" if @xcode.build_number
  if folder.length == 0
    time = Time.now
    folder = "#{time.day}-#{time.month}-#{time.year}-#{time.hour}-#{time.min}-#{time.sec}"
  end
  folder
end