lib/fastlane/plugin/polidea/actions/s3.rb in fastlane-plugin-polidea-0.6.3 vs lib/fastlane/plugin/polidea/actions/s3.rb in fastlane-plugin-polidea-0.6.4
- old
+ new
@@ -50,10 +50,11 @@
params[:version_template_path] = config[:version_template_path]
params[:version_file_name] = config[:version_file_name]
params[:acl] = config[:acl]
params[:installation_password] = config[:installation_password]
params[:release_notes] = config[:release_notes]
+ params[:treat_bucket_as_domain_name] = config[:treat_bucket_as_domain_name]
case platform
when :ios
upload_ios(params)
when :android
@@ -74,14 +75,17 @@
icon_file = params[:icon]
dsym_file = params[:dsym]
acl = params[:acl]
installation_password = params[:installation_password]
release_notes = params[:release_notes]
+ treat_bucket_as_domain_name = params[:treat_bucket_as_domain_name]
validate(params)
UI.user_error!("No IPA file path given, pass using `ipa: 'ipa path'`") unless ipa_file.to_s.length > 0
+ UI.message("Will transform S3 urls from https://s3.amazonaws.com/#{s3_bucket} to https://#{s3_bucket}") if treat_bucket_as_domain_name
+
bucket = get_bucket(s3_access_key, s3_secret_access_key, s3_region, s3_bucket)
# Gets info used for the plist
info = FastlaneCore::IpaFileAnalyser.fetch_info_plist_file(ipa_file)
@@ -99,22 +103,22 @@
ipa_file_basename = File.basename(ipa_file)
ipa_file_name = "#{url_part}#{ipa_file_basename}"
ipa_file_data = File.open(ipa_file, 'rb')
- ipa_url = self.upload_file(bucket, ipa_file_name, ipa_file_data, acl)
+ ipa_url = self.upload_file(bucket, ipa_file_name, ipa_file_data, acl, treat_bucket_as_domain_name)
# Setting action and environment variables
Actions.lane_context[SharedValues::S3_IPA_OUTPUT_PATH] = ipa_url
ENV[SharedValues::S3_IPA_OUTPUT_PATH.to_s] = ipa_url
if dsym_file
dsym_file_basename = File.basename(dsym_file)
dsym_file_name = "#{url_part}#{dsym_file_basename}"
dsym_file_data = File.open(dsym_file, 'rb')
- dsym_url = self.upload_file(bucket, dsym_file_name, dsym_file_data, acl)
+ dsym_url = self.upload_file(bucket, dsym_file_name, dsym_file_data, acl, treat_bucket_as_domain_name)
# Setting action and environment variables
Actions.lane_context[SharedValues::S3_DSYM_OUTPUT_PATH] = dsym_url
ENV[SharedValues::S3_DSYM_OUTPUT_PATH.to_s] = dsym_url
end
@@ -155,11 +159,11 @@
bundle_version: bundle_version,
title: app_name
})
# Gets icon from ipa and uploads it
- icon_url = self.upload_icon(icon_file, url_part, bucket, acl)
+ icon_url = self.upload_icon(icon_file, url_part, bucket, acl, treat_bucket_as_domain_name)
# Creates html from template
html_render = PageGenerator.generate({
url: "itms-services://?action=download-manifest&url=#{URI.encode_www_form_component(plist_url)}",
installation_password: installation_password,
@@ -190,14 +194,14 @@
#
# html and plist uploading
#
#####################################
- plist_url = self.upload_file(bucket, plist_file_name, plist_render, acl)
- html_url = self.upload_file(bucket, html_file_name, html_render, acl)
+ plist_url = self.upload_file(bucket, plist_file_name, plist_render, acl, treat_bucket_as_domain_name)
+ html_url = self.upload_file(bucket, html_file_name, html_render, acl, treat_bucket_as_domain_name)
self.upload_directory(bucket, html_resources_name, "#{__dir__}/../templates/installation-page", acl)
- version_url = self.upload_file(bucket, version_file_name, version_render, acl)
+ version_url = self.upload_file(bucket, version_file_name, version_render, acl, treat_bucket_as_domain_name)
# Setting action and environment variables
Actions.lane_context[SharedValues::S3_PLIST_OUTPUT_PATH] = plist_url
ENV[SharedValues::S3_PLIST_OUTPUT_PATH.to_s] = plist_url
@@ -228,14 +232,17 @@
apk_file = params[:apk]
icon_file = params[:icon]
acl = params[:acl]
installation_password = params[:installation_password]
release_notes = params[:release_notes]
+ treat_bucket_as_domain_name = params[:treat_bucket_as_domain_name]
validate(params)
UI.user_error!("No APK file path given, pass using `apk: 'apk path'`") unless apk_file.to_s.length > 0
+ UI.message("Will transform S3 urls from https://s3.amazonaws.com/#{s3_bucket} to https://#{s3_bucket}") if treat_bucket_as_domain_name
+
bucket = get_bucket(s3_access_key, s3_secret_access_key, s3_region, s3_bucket)
# Gets info used from the apk manifest
manifest = Android::Apk.new(apk_file).manifest
@@ -248,11 +255,11 @@
apk_file_basename = File.basename(apk_file)
apk_file_name = "#{url_part}#{apk_file_basename}"
apk_file_data = File.open(apk_file, 'rb')
- apk_url = self.upload_file(bucket, apk_file_name, apk_file_data, acl)
+ apk_url = self.upload_file(bucket, apk_file_name, apk_file_data, acl, treat_bucket_as_domain_name)
# Setting action and environment variables
Actions.lane_context[SharedValues::S3_APK_OUTPUT_PATH] = apk_url
ENV[SharedValues::S3_APK_OUTPUT_PATH.to_s] = apk_url
@@ -266,11 +273,11 @@
html_file_name ||= "#{url_part}index.html"
html_resources_name = "#{url_part}installation-page"
# Gets icon from ipa and uploads it
- icon_url = self.upload_icon(icon_file, url_part, bucket, acl)
+ icon_url = self.upload_icon(icon_file, url_part, bucket, acl, treat_bucket_as_domain_name)
# Creates html from template
html_render = PageGenerator.generate({
url: apk_url,
installation_password: installation_password,
@@ -280,11 +287,11 @@
app_icon: icon_url,
platform: "android",
release_notes: release_notes
})
- html_url = self.upload_file(bucket, html_file_name, html_render, acl)
+ html_url = self.upload_file(bucket, html_file_name, html_render, acl, treat_bucket_as_domain_name)
self.upload_directory(bucket, html_resources_name, "#{__dir__}/../templates/installation-page", acl)
Actions.lane_context[SharedValues::S3_HTML_OUTPUT_PATH] = html_url
ENV[SharedValues::S3_HTML_OUTPUT_PATH.to_s] = html_url
@@ -333,24 +340,27 @@
)
end
s3_client
end
- def self.upload_file(bucket, file_name, file_data, acl)
- puts file_name, content_type_for_file(file_name)
+ def self.upload_file(bucket, file_name, file_data, acl, treat_bucket_as_domain_name)
obj = bucket.objects.create(file_name, file_data, acl: acl, content_type: content_type_for_file(file_name))
# When you enable versioning on a S3 bucket,
# writing to an object will create an object version
# instead of replacing the existing object.
# http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/ObjectVersion.html
if obj.kind_of? AWS::S3::ObjectVersion
obj = obj.object
end
- # Return public url
- shorten_url(obj.public_url.to_s)
+ if treat_bucket_as_domain_name
+ # Return public url
+ shorten_url(obj.public_url.to_s)
+ else
+ obj.public_url.to_s
+ end
end
def self.upload_directory(bucket, directory_name, directory_path, acl)
files = files_at_path(directory_path)
@@ -418,16 +428,16 @@
end
return path
end
- def self.upload_icon(icon_path, url_part, bucket, acl)
+ def self.upload_icon(icon_path, url_part, bucket, acl, treat_bucket_as_domain_name)
return unless icon_path
icon_file_basename = File.basename(icon_path)
icon_file = File.open(icon_path)
icon_file_name = "#{url_part}#{icon_file_basename}"
- self.upload_file(bucket, icon_file_name, icon_file, acl)
+ self.upload_file(bucket, icon_file_name, icon_file, acl, treat_bucket_as_domain_name)
end
def self.shorten_url(url)
uri = URI.parse(url)
uri.scheme + ':/' + uri.path
@@ -518,10 +528,15 @@
FastlaneCore::ConfigItem.new(key: :release_notes,
env_name: "S3_RELEASE_NOTES",
description: "Release notes",
type: Array,
optional: true,
- default_value: Actions.lane_context[SharedValues::RELEASE_NOTES] ? Actions.lane_context[SharedValues::RELEASE_NOTES].split("\n") : nil)
+ default_value: Actions.lane_context[SharedValues::RELEASE_NOTES] ? Actions.lane_context[SharedValues::RELEASE_NOTES].split("\n") : nil),
+ FastlaneCore::ConfigItem.new(key: :treat_bucket_as_domain_name,
+ description: "If it's true, it transforms all urls from https://s3.amazonaws.com/BUCKET_NAME to https://BUCKET_NAME",
+ is_string: false,
+ optional: true,
+ default_value: true)
]
end
def self.output
[