Class: Fastlane::Actions::ShuttleAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/polidea/actions/shuttle.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorObject



49
50
51
# File 'lib/fastlane/plugin/polidea/actions/shuttle.rb', line 49

def self.author
  ["Piotrek Dubiel"]
end

.available_optionsObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
118
119
120
121
122
123
# File 'lib/fastlane/plugin/polidea/actions/shuttle.rb', line 53

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :api_token,
      env_name: "SHUTTLE_API_TOKEN",
      description: "API Token for Shuttle",
      verify_block: proc do |api_token|
        UI.user_error!("No API token for Shuttle given, pass using `api_token: 'token'`") unless api_token and !api_token.empty?
      end),
    FastlaneCore::ConfigItem.new(key: :ipa,
      env_name: "",
      description: ".ipa file for the build",
      optional: true,
      default_value: Actions.lane_context[SharedValues::IPA_OUTPUT_PATH]),
    FastlaneCore::ConfigItem.new(key: :dsym,
      env_name: "",
      description: "zipped .dsym package for the build",
      optional: true,
      default_value: Actions.lane_context[SharedValues::DSYM_OUTPUT_PATH]),
    FastlaneCore::ConfigItem.new(key: :apk,
      env_name: "",
      description: ".apk file for the build",
      optional: true,
      default_value: Actions.lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]),
    FastlaneCore::ConfigItem.new(key: :mapping,
      env_name: "",
      description: "The path to the mapping.txt file",
      optional: true,
      default_value: Actions.lane_context[SharedValues::GRADLE_MAPPING_TXT_OUTPUT_PATH]),
    FastlaneCore::ConfigItem.new(key: :prefix_schema,
      env_name: "SHUTTLE_PREFIX_SCHEMA",
      description: "Prefix schema in uploaded app",
      default_value: Actions.lane_context[SharedValues::PREFIX_SCHEMA],
      optional: true),
    FastlaneCore::ConfigItem.new(key: :app_identifier,
      description: "App identifier, either bundle id or package name",
      type: String,
      default_value: Actions.lane_context[SharedValues::APP_IDENTIFIER]),
    FastlaneCore::ConfigItem.new(key: :app_version,
      description: "App version, eg. '1.0.0''",
      type: String,
      default_value: Actions.lane_context[SharedValues::APP_VERSION]),
    FastlaneCore::ConfigItem.new(key: :build_number,
      description: "Build number, eg. 1337",
      is_string: false,
      default_value: Actions.lane_context[SharedValues::BUILD_NUMBER],
      verify_block: proc do |build_number|
        UI.user_error!("No value found for 'build_number'") unless build_number and build_number.kind_of? Integer
      end),
    FastlaneCore::ConfigItem.new(key: :binary_size,
      description: ".ipa/.apk binary size in bytes",
      is_string: false,
      default_value: Actions.lane_context[SharedValues::BINARY_SIZE],
      verify_block: proc do |binary_size|
        UI.user_error!("No value found for 'binary_size'") unless binary_size and binary_size.kind_of? Integer
      end),
    FastlaneCore::ConfigItem.new(key: :release_notes,
      description: "Release notes to be attached to uploaded version",
      type: String,
      optional: true,
      default_value: Actions.lane_context[SharedValues::RELEASE_NOTES]),
    FastlaneCore::ConfigItem.new(key: :releaser,
      description: "Releaser email",
      type: String,
      optional: true),
    FastlaneCore::ConfigItem.new(key: :environment,
      description: "Select environment, defaults to :production",
      type: Symbol,
      default_value: :production,
      optional: true)
  ]
end

.descriptionObject



41
42
43
# File 'lib/fastlane/plugin/polidea/actions/shuttle.rb', line 41

def self.description
  "Shuttle upload action"
end

.detailsObject



45
46
47
# File 'lib/fastlane/plugin/polidea/actions/shuttle.rb', line 45

def self.details
  "Notify Shuttle about new app version"
end

.get_config(platform, params) ⇒ Object



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
# File 'lib/fastlane/plugin/polidea/actions/shuttle.rb', line 142

def self.get_config(platform, params)
  api_token = params[:api_token]
  app_identifier = params[:app_identifier]
  app_version = params[:app_version]
  build_number = params[:build_number]
  binary_size = params[:binary_size]
  release_notes = params[:release_notes]
  releaser = params[:releaser] || commit_author

  case platform
  when :android
    apk = params[:apk]
    mapping = params[:mapping]
  when :ios
    prefix_schema = params[:prefix_schema]
    ipa = params[:ipa]
    dsym = params[:dsym]
  end

  {
    api_token: api_token,
    app_identifier: app_identifier,
    app_version: app_version,
    build_number: build_number,
    release_notes: release_notes,
    releaser: releaser,
    binary_size: binary_size,
    prefix_schema: prefix_schema,
    environment: params[:environment],
    ipa: ipa,
    apk: apk,
    mapping: mapping,
    dsym: dsym
  }
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/fastlane/plugin/polidea/actions/shuttle.rb', line 125

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

.run(params) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fastlane/plugin/polidea/actions/shuttle.rb', line 8

def self.run(params)
  Fastlane::Polidea.session.action_launched("shuttle", params)
  platform = Actions.lane_context[Actions::SharedValues::PLATFORM_NAME].to_sym
  options = {
    api_token: params[:api_token],
    ipa: params[:ipa],
    apk: params[:apk],
    dsym: params[:dsym],
    mapping: params[:mapping],
    prefix_schema: params[:prefix_schema],
    app_identifier: params[:app_identifier],
    app_version: params[:app_version],
    build_number: params[:build_number],
    binary_size: params[:binary_size],
    release_notes: params[:release_notes],
    releaser: params[:releaser],
    environment: params[:environment]
  }
  validate(platform, options)
  config = get_config(platform, options)
  client = Shuttle::Client.new(base_url(params[:environment]), params[:api_token])
  notify(client, platform, config)
  upload(client, platform, config)

  UI.success("Successfully uploaded to #{params[:app_identifier]} #{params[:app_version]}.#{params[:build_number]} to Shuttle")

  Fastlane::Polidea.session.action_completed("shuttle")
end

.upload(client, platform, params) ⇒ Object



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/fastlane/plugin/polidea/actions/shuttle.rb', line 193

def self.upload(client, platform, params)
  case platform
  when :ios
    upload_urls = client.get_upload_urls(platform, params[:app_identifier], params[:prefix_schema])
    upload_build_url = upload_urls['buildUrl']
    self.upload_file(upload_build_url, params[:ipa])
    UI.success("Successfully uploaded ipa file")
    if params[:dsym]
      upload_dsym_url = upload_urls['debugFileUrl']
      self.upload_file(upload_dsym_url, params[:dsym])
      UI.success("Successfully uploaded dsym file")
    end
  when :android
    upload_urls = client.get_upload_urls(platform, params[:app_identifier], params[:build_number])
    upload_build_url = upload_urls['buildUrl']
    self.upload_file(upload_build_url, params[:apk])
    UI.success("Successfully uploaded apk file")
    if params[:mapping]
      upload_mapping_file_url = upload_urls['debugFileUrl']
      self.upload_file(upload_mapping_file_url, params[:mapping])
      UI.success("Successfully uploaded mapping file")
    end
  end
end

.upload_file(url, build) ⇒ Object



218
219
220
221
# File 'lib/fastlane/plugin/polidea/actions/shuttle.rb', line 218

def self.upload_file(url, build)
  client = S3::Client.new
  client.upload_file(url, build)
end

.validate(platform, params) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/fastlane/plugin/polidea/actions/shuttle.rb', line 129

def self.validate(platform, params)
  case platform
  when :ios
    url_scheme = params[:prefix_schema]
    UI.user_error!("No prefix scheme given. Make sure `add_prefix_schema` action succeded before build action") if url_scheme.nil?
    ipa = params[:ipa]
    UI.user_error!("No .ipa file path given. Make sure `gym` action succeded") if ipa.nil?
  when :android
    apk = params[:apk]
    UI.user_error!("No .apk file path given. Make sure `gradle` action succeded") if apk.nil?
  end
end