Skip to content

Instantly share code, notes, and snippets.

@olbartek
Last active October 10, 2019 08:17
Show Gist options
  • Save olbartek/8a43257a8e320d580f3534ee0440901f to your computer and use it in GitHub Desktop.
Save olbartek/8a43257a8e320d580f3534ee0440901f to your computer and use it in GitHub Desktop.
Fastlane action for uploading builds to Zander API
module Fastlane
module Actions
module SharedValues
ZANDER_DOWNLOAD_LINK = :ZANDER_DOWNLOAD_LINK
ZANDER_BUILD_INFORMATION = :ZANDER_BUILD_INFORMATION # contains all keys/values from the Zander API, like :buildNumber, :releaseNotes
end
class ZanderAction < Action
def self.connection(options)
require 'faraday'
require 'faraday_middleware'
base_url = "https://zander.ios.net.pl"
foptions = {
url: base_url
}
Faraday.new(foptions) do |builder|
builder.request(:multipart)
builder.request(:url_encoded)
builder.response(:json, content_type: /\bjson$/)
builder.use(FaradayMiddleware::FollowRedirects)
builder.adapter(:net_http)
end
end
def self.upload_build(ipa, options)
connection = self.connection(options)
options[:ipaFile] = Faraday::UploadIO.new(ipa, 'application/octet-stream') if ipa && File.exist?(ipa)
version = options.delete(:bundle_version)
buildNumber = options.delete(:bundle_short_version)
releaseNotes = options.delete(:notes)
options[:version] = version
options[:buildNumber] = buildNumber
options[:releaseNotes] = releaseNotes
connection.post do |req|
req.url("/apps/bundleId/#{options.delete(:public_identifier)}/builds/upload")
req.body = options
end
end
def self.run(options)
build_file = options.values.delete(:ipa)
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 Zander... this could take some time.')
values = options.values
values.delete_if { |k, v| v.nil? }
return values if Helper.test?
response = self.upload_build(build_file, values)
case response.status
when 200...300
url = response.body['downloadUrl']
buildInformation = response.body['buildMetadata']
Actions.lane_context[SharedValues::ZANDER_DOWNLOAD_LINK] = url
Actions.lane_context[SharedValues::ZANDER_BUILD_INFORMATION] = buildInformation
UI.message("Public Download URL: #{url}") if url
UI.message("Build info: #{buildInformation}") if buildInformation
UI.success('Build successfully uploaded to Zander!')
else
UI.user_error!("Error when trying to upload file(s) to Zander: #{response.status} - #{response.body}")
end
end
def self.description
"Uploads builds to Zander"
end
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :ipa,
env_name: "FL_ZANDER_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),
FastlaneCore::ConfigItem.new(key: :notes,
env_name: "FL_ZANDER_NOTES",
description: "Beta Notes",
default_value: Actions.lane_context[SharedValues::FL_CHANGELOG] || "No changelog given",
default_value_dynamic: true),
FastlaneCore::ConfigItem.new(key: :bundle_short_version,
env_name: "FL_ZANDER_BUNDLE_SHORT_VERSION",
description: "The bundle_short_version of your application",
optional: true),
FastlaneCore::ConfigItem.new(key: :bundle_version,
env_name: "FL_ZANDER_BUNDLE_VERSION",
description: "The bundle_version of your application",
optional: true),
FastlaneCore::ConfigItem.new(key: :public_identifier,
env_name: "FL_ZANDER_PUBLIC_IDENTIFIER",
description: "App id of the app you are targeting",
optional: true)
]
end
def self.output
[
['ZANDER_DOWNLOAD_LINK', 'The newly generated download link for this build'],
['ZANDER_BUILD_INFORMATION', 'contains all keys/values from the Zander API, like :title, :bundle_identifier']
]
end
def self.author
["olbartek"]
end
def self.is_supported?(platform)
true
end
def self.details
"Currently only uploading builds is supported, new app versions must be created manually"
end
def self.example_code
[
'zander(
public_identifier: "....",
bundle_short_version: "1.0.2",
bundle_version: "1.0.2.145",
ipa: "./app.ipa",
notes: "Changelog"
)'
]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment