Class: Fastlane::Actions::HockeyAction

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

Class Method Summary collapse

Methods inherited from Fastlane::Action

details, sh

Class Method Details

.authorObject



89
90
91
# File 'lib/fastlane/actions/hockey.rb', line 89

def self.author
  "KrauseFx"
end

.available_optionsObject



71
72
73
74
75
76
77
78
79
80
# File 'lib/fastlane/actions/hockey.rb', line 71

def self.available_options
  [
    ['api_token', 'API Token for Hockey Access'],
    ['ipa', 'Path to the ipa file. Optional if you use the `ipa` or `xcodebuild` action'],
    ['notes', 'The changelog for this build'],
    ['dsym', 'Path to the dsym file. Optional if you use the `ipa` or `xcodebuild` action'],
    ['status', 'Download status: 1 = No user can download; 2 = Available for download'],
    ['notify', 'Notify testers? 1 for yes'],
  ]
end

.descriptionObject



67
68
69
# File 'lib/fastlane/actions/hockey.rb', line 67

def self.description
  "Upload a new build to HockeyApp"
end

.outputObject



82
83
84
85
86
87
# File 'lib/fastlane/actions/hockey.rb', line 82

def self.output
  [
    ['HOCKEY_DOWNLOAD_LINK', 'The newly generated download link for this build'],
    ['HOCKEY_BUILD_INFORMATION', 'contains all keys/values from the HockeyApp API, like :title, :bundle_identifier']
  ]
end

.run(params) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
61
62
63
64
65
# File 'lib/fastlane/actions/hockey.rb', line 13

def self.run(params)
  # Available options: http://support.hockeyapp.net/kb/api/api-versions#upload-version
  options = {
    notes: 'No changelog given',
    status: 2,
    notify: 1
  }.merge(params.first)

  options[:ipa] ||= Actions.lane_context[SharedValues::IPA_OUTPUT_PATH]
  options[:dsym] ||= Actions.lane_context[SharedValues::DSYM_OUTPUT_PATH]

  require 'shenzhen'
  require 'shenzhen/plugins/hockeyapp'

  raise "No API Token for Hockey given, pass using `api_token: 'token'`. Open https://rink.hockeyapp.net/manage/auth_tokens to get one".red unless options[:api_token].to_s.length > 0
  raise "No IPA file given or found, pass using `ipa: 'path.ipa'`".red unless options[:ipa]
  raise "IPA file on path '#{File.expand_path(options[:ipa])}' not found".red unless File.exist?(options[:ipa])

  if options[:dsym]
    options[:dsym_filename] = options[:dsym]
  else
    dsym_path = options[:ipa].gsub('ipa', 'app.dSYM.zip')
    if File.exist?(dsym_path)
      options[:dsym_filename] = dsym_path
    else
      Helper.log.info "Symbols not found on path #{File.expand_path(dsym_path)}. Crashes won't be symbolicated properly".yellow
    end
  end

  raise "Symbols on path '#{File.expand_path(options[:dsym_filename])}' not found".red if (options[:dsym_filename] &&
                                                                                          !File.exist?(options[:dsym_filename]))

  Helper.log.info 'Starting with ipa upload to HockeyApp... this could take some time.'.green

  client = Shenzhen::Plugins::HockeyApp::Client.new(options[:api_token])

  return if Helper.test?

  response = client.upload_build(options[:ipa], options)
  case response.status
    when 200...300
      url = response.body['public_url']

      Actions.lane_context[SharedValues::HOCKEY_DOWNLOAD_LINK] = url
      Actions.lane_context[SharedValues::HOCKEY_BUILD_INFORMATION] = response.body

      Helper.log.info "Public Download URL: #{url}" if url
      Helper.log.info 'Build successfully uploaded to HockeyApp!'.green
    else
      Helper.log.fatal "Error uploading to HockeyApp: #{response.body}"
      raise 'Error when trying to upload ipa to HockeyApp'.red
    end
end