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



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

def self.author
  ["Piotrek Dubiel"]
end

.available_optionsObject



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

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: :plist_url,
      env_name: "SHUTTLE_PLIST_URL",
      description: "Url to uploaded plist",
      default_value: Actions.lane_context[SharedValues::S3_PLIST_OUTPUT_PATH],
      optional: true),
    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: :apk_url,
      env_name: "SHUTTLE_APK_URL",
      description: "Url to uploaded apk",
      default_value: Actions.lane_context[SharedValues::S3_APK_OUTPUT_PATH],
      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

.create_request(uri, access_token, params) ⇒ Object



192
193
194
195
196
197
198
# File 'lib/fastlane/plugin/polidea/actions/shuttle.rb', line 192

def self.create_request(uri, access_token, params)
  req = Net::HTTP::Post.new(uri.request_uri)
  req['Content-Type'] = 'application/json'
  req['Access-Token'] = access_token
  req.body = JSON.generate(params)
  req
end

.descriptionObject



34
35
36
# File 'lib/fastlane/plugin/polidea/actions/shuttle.rb', line 34

def self.description
  "Shuttle upload action"
end

.detailsObject



38
39
40
# File 'lib/fastlane/plugin/polidea/actions/shuttle.rb', line 38

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

.get_config(platform, params) ⇒ Object



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

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 :ios
    href = itms_href(params[:plist_url])
    prefix_schema = params[:prefix_schema]
  when :android
    href = params[:apk_url]
  end

  {
    api_token: api_token,
    app_identifier: app_identifier,
    app_version: app_version,
    build_number: build_number,
    href: href,
    release_notes: release_notes,
    releaser: releaser,
    binary_size: binary_size,
    prefix_schema: prefix_schema,
    environment: params[:environment]
  }
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/fastlane/plugin/polidea/actions/shuttle.rb', line 108

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

.make_request(uri, request, limit = 10) ⇒ Object

Raises:

  • (ArgumentError)


210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/fastlane/plugin/polidea/actions/shuttle.rb', line 210

def self.make_request(uri, request, limit = 10)
  raise ArgumentError, 'HTTP redirect too deep' if limit.zero?

  http = Net::HTTP.new(uri.host, uri.port)

  if uri.instance_of?(URI::HTTPS)
    http.use_ssl = true
  end

  response = http.request(request)
  UI.verbose(response.body)
  case response
  when Net::HTTPSuccess     then response
  when Net::HTTPRedirection then make_request(URI.parse(response['location']), request, limit - 1)
  else
    UI.user_error! "#{response.code} #{response.body}"
  end
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
# File 'lib/fastlane/plugin/polidea/actions/shuttle.rb', line 8

def self.run(params)
  platform = Actions.lane_context[Actions::SharedValues::PLATFORM_NAME].to_sym
  options = {
    api_token: params[:api_token],
    plist_url: params[:plist_url],
    prefix_schema: params[:prefix_schema],
    apk_url: params[:apk_url],
    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)
  notify(platform, config)

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

.validate(platform, params) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/fastlane/plugin/polidea/actions/shuttle.rb', line 112

def self.validate(platform, params)
  case platform
  when :android
    apk_url = params[:apk_url]
    UI.user_error!("No apk url given, pass using `apk_url: 'url'` or make sure s3 action succeded and exposed S3_APK_OUTPUT_PATH shared value") unless apk_url and !apk_url.empty?
  when :ios
    plist_url = params[:plist_url]
    UI.user_error!("No plist url given, pass using `plist_url: 'url'` or make sure s3 action succeded and exposed S3_PLIST_OUTPUT_PATH shared value") unless plist_url and !plist_url.empty?
    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?
  end
end