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

action_name, authors, details, return_value, sh, step_text

Class Method Details

.authorObject



192
193
194
# File 'lib/fastlane/actions/hockey.rb', line 192

def self.author
  ["KrauseFx", "modzelewski"]
end

.available_optionsObject



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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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
175
176
177
178
179
180
181
182
183
# File 'lib/fastlane/actions/hockey.rb', line 81

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :apk,
                                 env_name: "FL_HOCKEY_APK",
                                 description: "Path to your APK file",
                                 default_value: Actions.lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH],
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find apk file at path '#{value}'") unless File.exist?(value)
                                 end,
                                 conflicting_options: [:ipa],
                                 conflict_block: proc do |value|
                                   UI.user_error!("You can't use 'apk' and '#{value.key}' options in one run")
                                 end),
    FastlaneCore::ConfigItem.new(key: :api_token,
                                 env_name: "FL_HOCKEY_API_TOKEN",
                                 description: "API Token for Hockey Access",
                                 verify_block: proc do |value|
                                   UI.user_error!("No API token for Hockey given, pass using `api_token: 'token'`") unless value and !value.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :ipa,
                                 env_name: "FL_HOCKEY_IPA",
                                 description: "Path to your IPA file. Optional if you use the `gym` or `xcodebuild` action. For Mac zip the .app. For Android provide path to .apk file",
                                 default_value: Actions.lane_context[SharedValues::IPA_OUTPUT_PATH],
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find ipa file at path '#{value}'") unless File.exist?(value)
                                 end,
                                 conflicting_options: [:apk],
                                 conflict_block: proc do |value|
                                   UI.user_error!("You can't use 'ipa' and '#{value.key}' options in one run")
                                 end),
    FastlaneCore::ConfigItem.new(key: :dsym,
                                 env_name: "FL_HOCKEY_DSYM",
                                 description: "Path to your symbols file. For iOS and Mac provide path to app.dSYM.zip. For Android provide path to mappings.txt file",
                                 default_value: Actions.lane_context[SharedValues::DSYM_OUTPUT_PATH],
                                 optional: true,
                                 verify_block: proc do |value|
                                   # validation is done in the action
                                 end),
    FastlaneCore::ConfigItem.new(key: :notes,
                                 env_name: "FL_HOCKEY_NOTES",
                                 description: "Beta Notes",
                                 default_value: Actions.lane_context[SharedValues::FL_CHANGELOG] || "No changelog given"),
    FastlaneCore::ConfigItem.new(key: :notify,
                                 env_name: "FL_HOCKEY_NOTIFY",
                                 description: "Notify testers? 1 for yes",
                                 default_value: "1"),
    FastlaneCore::ConfigItem.new(key: :status,
                                 env_name: "FL_HOCKEY_STATUS",
                                 description: "Download status: 1 = No user can download; 2 = Available for download",
                                 default_value: "2"),
    FastlaneCore::ConfigItem.new(key: :notes_type,
                                env_name: "FL_HOCKEY_NOTES_TYPE",
                                description: "Notes type for your :notes, 0 = Textile, 1 = Markdown (default)",
                                default_value: "1"),
    FastlaneCore::ConfigItem.new(key: :release_type,
                                env_name: "FL_HOCKEY_RELEASE_TYPE",
                                description: "Release type of the app: 0 = Beta (default), 1 = Store, 2 = Alpha, 3 = Enterprise",
                                default_value: "0"),
    FastlaneCore::ConfigItem.new(key: :mandatory,
                                env_name: "FL_HOCKEY_MANDATORY",
                                description: "Set to 1 to make this update mandatory",
                                default_value: "0"),
    FastlaneCore::ConfigItem.new(key: :teams,
                                env_name: "FL_HOCKEY_TEAMS",
                                description: "Comma separated list of team ID numbers to which this build will be restricted",
                                optional: true),
    FastlaneCore::ConfigItem.new(key: :users,
                                env_name: "FL_HOCKEY_USERS",
                                description: "Comma separated list of user ID numbers to which this build will be restricted",
                                optional: true),
    FastlaneCore::ConfigItem.new(key: :tags,
                                env_name: "FL_HOCKEY_TAGS",
                                description: "Comma separated list of tags which will receive access to the build",
                                optional: true),
    FastlaneCore::ConfigItem.new(key: :public_identifier,
                                env_name: "FL_HOCKEY_PUBLIC_IDENTIFIER",
                                description: "Public identifier of the app you are targeting, usually you won't need this value",
                                optional: true),
    FastlaneCore::ConfigItem.new(key: :commit_sha,
                                env_name: "FL_HOCKEY_COMMIT_SHA",
                                description: "The Git commit SHA for this build",
                                optional: true),
    FastlaneCore::ConfigItem.new(key: :repository_url,
                                env_name: "FL_HOCKEY_REPOSITORY_URL",
                                description: "The URL of your source repository",
                                optional: true),
    FastlaneCore::ConfigItem.new(key: :build_server_url,
                                env_name: "FL_HOCKEY_BUILD_SERVER_URL",
                                description: "The URL of the build job on your build server",
                                optional: true),
    FastlaneCore::ConfigItem.new(key: :upload_dsym_only,
                                env_name: "FL_HOCKEY_UPLOAD_DSYM_ONLY",
                                description: "Flag to upload only the dSYM file to hockey app",
                                is_string: false,
                                default_value: false),
    FastlaneCore::ConfigItem.new(key: :owner_id,
                                env_name: "FL_HOCKEY_OWNER_ID",
                                description: "ID for the owner of the app",
                                optional: true)
  ]
end

.descriptionObject



77
78
79
# File 'lib/fastlane/actions/hockey.rb', line 77

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

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


196
197
198
# File 'lib/fastlane/actions/hockey.rb', line 196

def self.is_supported?(platform)
  [:ios, :mac, :android].include? platform
end

.outputObject



185
186
187
188
189
190
# File 'lib/fastlane/actions/hockey.rb', line 185

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(options) ⇒ 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
66
67
68
69
70
71
72
73
74
75
# File 'lib/fastlane/actions/hockey.rb', line 13

def self.run(options)
  # Available options: http://support.hockeyapp.net/kb/api/api-versions#upload-version

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

  build_file = [
    options[:ipa],
    options[:apk]
  ].detect { |e| !e.to_s.empty? }

  if options[:dsym]
    dsym_filename = options[:dsym]
  else

    if build_file.nil?
      UI.user_error!("You have to provide a build file")
    end

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

  UI.user_error!("Symbols on path '#{File.expand_path(dsym_filename)}' not found") if dsym_filename && !File.exist?(dsym_filename)

  UI.success('Starting with ipa upload to HockeyApp... this could take some time.')

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

  values = options.values
  values[:dsym_filename] = dsym_filename
  values[:notes_type] = options[:notes_type]

  return values if Helper.test?

  ipa_filename = build_file
  ipa_filename = nil if options[:upload_dsym_only]

  response = client.upload_build(ipa_filename, values)
  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

    UI.message("Public Download URL: #{url}") if url
    UI.success('Build successfully uploaded to HockeyApp!')
  else
    if response.body.to_s.include?("App could not be created")
      UI.user_error!("Hockey has an issue processing this app. Please confirm that an app in Hockey matches this IPA's bundle ID or that you are using the correct API upload token. If error persists, please provide the :public_identifier option from the HockeyApp website. More information https://github.com/fastlane/fastlane/issues/400")
    else
      UI.user_error!("Error when trying to upload ipa to HockeyApp: #{response.body}")
    end
  end
end