Class: Fastlane::Actions::BowlAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



115
116
117
# File 'lib/fastlane/plugin/bowl/actions/bowl_action.rb', line 115

def self.authors
  ["Benjamin Wulff"]
end

.available_optionsObject



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
184
185
186
# File 'lib/fastlane/plugin/bowl/actions/bowl_action.rb', line 128

def self.available_options
  # Define all options your action supports. 
  
  # Below a few examples
  [
    FastlaneCore::ConfigItem.new(key: :m2m_api_token,
                                 env_name: "BOWL_M2M_API_TOKEN", # The name of the environment variable
                                 description: "M2M API Token for UploadToBowlAction", # a short description of this parameter
                                 verify_block: proc do |value|
                                    UI.user_error!("No M2M API token for UploadToBowlAction given, pass using `m2m_api_token: 'token'`") unless (value and not value.empty?)
                                    # UI.user_error!("Couldn't find file at path '#{value}'") unless File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :base_url,
                                 env_name: "BOWL_BASE_URL", # The name of the environment variable
                                 description: "Base Url for UploadToBowlAction", # a short description of this parameter
                                 verify_block: proc do |value|
                                    UI.user_error!("No Base Url for UploadToBowlAction given, pass using `base_url: 'url'`") unless (value and not value.empty?)
                                 end),
    FastlaneCore::ConfigItem.new(key: :apk,
                                  env_name: "BOWL_APK", # The name of the environment variable
                                  description: "Path to your APK file",
                                 default_value: Actions.lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH],
                                 default_value_dynamic: true,
                                 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: :ipa,
                                  env_name: "BOWL_IPA",
                                  description: "Path to your IPA file",
                                  default_value: Actions.lane_context[SharedValues::IPA_OUTPUT_PATH],
                                  default_value_dynamic: true,
                                  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: :version,
                                 env_name: "BOWL_APP_VERSION",
                                 description: "Version of your IPA or APK file",
                                 is_string: true, # true: verifies the input is a string, false: every kind of value
                                 verify_block: proc do |value|
                                      UI.user_error!("No version key given, pass using `version: 'version'`") unless (value and not value.empty?)
                                  end),
    FastlaneCore::ConfigItem.new(key: :mandatory,
                                 env_name: "BOWL_APP_VERSION_MANDATORY",
                                 description: "Wether this version represents a mandatory update",
                                 is_string: false,
                                 optional: true,
                                 default_value: false) # the default value if the user didn't provide one
  ]
end

.connection(options) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fastlane/plugin/bowl/actions/bowl_action.rb', line 37

def self.connection(options)
  require 'faraday'

  foptions = {
    url: options[:base_url]
  }
  Faraday.new(foptions) do |builder|
    builder.request(:multipart)
    builder.request(:url_encoded)
    builder.response(:json, content_type: /\bjson$/)
    builder.adapter(:net_http)
  end
end

.descriptionObject



111
112
113
# File 'lib/fastlane/plugin/bowl/actions/bowl_action.rb', line 111

def self.description
  "Handles uploads to BOWL backend"
end

.detailsObject



123
124
125
126
# File 'lib/fastlane/plugin/bowl/actions/bowl_action.rb', line 123

def self.details
  # Optional:
  "Soon"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


206
207
208
209
210
211
212
# File 'lib/fastlane/plugin/bowl/actions/bowl_action.rb', line 206

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  # [:ios, :mac, :android].include?(platform)
  true
end

.outputObject



188
189
190
191
192
193
194
195
# File 'lib/fastlane/plugin/bowl/actions/bowl_action.rb', line 188

def self.output
  # Define the shared values you are going to provide
  # Example
  [
    ['BOWL_DOWNLOAD_URL', 'Url of the uploaded build'],
    ['BOWL_VERSION_LINK', 'Link to the uploaded version in BOWL backend']
  ]
end


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fastlane/plugin/bowl/actions/bowl_action.rb', line 18

def self.print_qr_code(url)
  require 'rqrcode'
  qrcode = RQRCode::QRCode.new(url)

  width = qrcode.modules.length

  puts WHITE + SPACER * (width + 2) + BLACK

  width.times do |x|
    print WHITE + SPACER
    width.times do |y|
      print (qrcode.is_dark(x,y) ? BLACK : WHITE ) + SPACER
    end
    puts WHITE + SPACER + DEFAULT
  end

  puts WHITE + SPACER * (width + 2) + BLACK
end

.return_valueObject



119
120
121
# File 'lib/fastlane/plugin/bowl/actions/bowl_action.rb', line 119

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/bowl/actions/bowl_action.rb', line 68

def self.run(params)
  build_file = [
    params[:ipa],
    params[:apk]
  ].detect { |e| !e.to_s.empty? }

  if build_file.nil?
    UI.user_error!("You have to provide a build file (params 'apk' or 'ipa')")
  end

  UI.success('Starting with file(s) upload to BOWL... this could take some time.')

  values = params.values
  m2m_api_token = values.delete(:m2m_api_token)

  values.delete_if { |k, v| v.nil? }

  response = self.upload_version(m2m_api_token, build_file, values)
  case response.status
  when 200...300
    install_url = response.body['installUrl']
    link = response.body['link']

    Actions.lane_context[SharedValues::BOWL_DOWNLOAD_URL] = install_url
    Actions.lane_context[SharedValues::BOWL_VERSION_LINK] = link

    UI.success('Build successfully uploaded to BOWL!')
    UI.success('Scan the QR below to test the version')
    self.print_qr_code(install_url)
    UI.message("Installation Link: #{install_url}") if install_url

    UI.success('Once you\'re happy, approve the new version to make it publicly available')
    UI.message("Link to version: #{link}") if link

  else
    if response.body.to_s.include?("App could not be created")
      UI.user_error!("BOWL has an issue processing this app.")
    else
      UI.user_error!("Error when trying to upload file(s) to BOWL: #{response.status} - #{response.body}")
    end
  end
end

.upload_version(m2m_api_token, build_file, options) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fastlane/plugin/bowl/actions/bowl_action.rb', line 51

def self.upload_version(m2m_api_token, build_file, options)
  connection = self.connection(options)

  options[:build_file] = Faraday::UploadIO.new(build_file, 'application/octet-stream') if build_file && File.exist?(build_file)
  
  connection.post do |req|
    req.headers['Accept'] = 'application/json'
    if options[:ipa].nil?
      req.url("/api/apps/android/versions")
    else
      req.url("/api/apps/ios/versions")
    end
    req.headers['X-M2M-Auth-Token'] = m2m_api_token
    req.body = options
  end
end