class Fastlane::Actions::UploadFolderToS3Action
Attributes
invalid_local_folder_path_message[RW]
invalid_remote_folder_path_message[RW]
no_access_key_id_error_message[RW]
no_bucket_error_message[RW]
no_region_error_message[RW]
no_secret_access_key_error_message[RW]
Public Class Methods
available_options()
click to toggle source
# File lib/fastlane/plugin/upload_folder_to_s3/actions/upload_folder_to_s3_action.rb, line 139 def self.available_options [ FastlaneCore::ConfigItem.new(key: :access_key_id, env_name: "FL_UPLOAD_FOLDER_TO_S3_ACCESS_KEY_ID", description: "Access key ID", verify_block: proc do |value| UI.user_error!(UploadFolderToS3Action.no_access_key_id_error_message) if value.to_s.length == 0 end), FastlaneCore::ConfigItem.new(key: :secret_access_key, env_name: "FL_UPLOAD_FOLDER_TO_S3_SECRET_ACCESS_KEY", description: "Secret access key", verify_block: proc do |value| UI.user_error!(UploadFolderToS3Action.no_secret_access_key_error_message) if value.to_s.length == 0 end), FastlaneCore::ConfigItem.new(key: :region, env_name: "FL_UPLOAD_FOLDER_TO_S3_REGION", description: "The region", verify_block: proc do |value| UI.user_error!(UploadFolderToS3Action.no_region_error_message) if value.to_s.length == 0 end), FastlaneCore::ConfigItem.new(key: :bucket, env_name: "FL_UPLOAD_FOLDER_TO_S3_BUCKET", description: "Bucket", verify_block: proc do |value| UI.user_error!(UploadFolderToS3Action.no_bucket_error_message) if value.to_s.length == 0 end), FastlaneCore::ConfigItem.new(key: :local_path, env_name: "FL_UPLOAD_FOLDER_TO_S3_LOCAL_PATH", description: "Path to local folder to upload", verify_block: proc do |value| UI.user_error!(UploadFolderToS3Action.invalid_local_folder_path_message) if value.to_s.length == 0 end), FastlaneCore::ConfigItem.new(key: :remote_path, env_name: "FL_UPLOAD_FOLDER_TO_S3_REMOTE_PATH", description: "The remote base path", verify_block: proc do |value| UI.user_error!(UploadFolderToS3Action.invalid_remote_folder_path_message) if value.to_s.length == 0 end) ] end
content_type_for_file(file)
click to toggle source
# File lib/fastlane/plugin/upload_folder_to_s3/actions/upload_folder_to_s3_action.rb, line 206 def self.content_type_for_file(file) file_extension = File.extname(file) extensions_to_type = { ".html" => "text/html", ".png" => "image/png", ".jpg" => "text/jpeg", ".gif" => "image/gif", ".log" => "text/plain", ".css" => "text/css", ".js" => "application/javascript" } if extensions_to_type[file_extension].nil? "application/octet-stream" else extensions_to_type[file_extension] end end
description()
click to toggle source
@!group Documentation
# File lib/fastlane/plugin/upload_folder_to_s3/actions/upload_folder_to_s3_action.rb, line 127 def self.description %q{Upload a folder to S3} end
details()
click to toggle source
# File lib/fastlane/plugin/upload_folder_to_s3/actions/upload_folder_to_s3_action.rb, line 131 def self.details [ "If you want to use regex to exclude some files, please contribute to this action.", "Else, just do like me and from your artifacts/builds/product folder,", "create the subset you want to upload in another folder and upload it using this action." ].join("\n") end
files_at_path(path)
click to toggle source
# File lib/fastlane/plugin/upload_folder_to_s3/actions/upload_folder_to_s3_action.rb, line 43 def self.files_at_path(path) files = Dir.glob(path + "/**/*") to_remove = [] files.each do |file| if File.directory?(file) to_remove.push file else file.slice! path end end to_remove.each do |file| files.delete file end files end
is_supported?(platform)
click to toggle source
# File lib/fastlane/plugin/upload_folder_to_s3/actions/upload_folder_to_s3_action.rb, line 202 def self.is_supported?(platform) true end
load_from_original_gem_name()
click to toggle source
# File lib/fastlane/plugin/upload_folder_to_s3/actions/upload_folder_to_s3_action.rb, line 87 def self.load_from_original_gem_name begin Gem::Specification.find_by_name('aws-sdk') require 'aws-sdk' rescue Gem::LoadError => e UI.verbose("The 'aws-sdk' gem is not present") return false end UI.verbose("The 'aws-sdk' gem is present") true end
load_from_v1_gem_name()
click to toggle source
# File lib/fastlane/plugin/upload_folder_to_s3/actions/upload_folder_to_s3_action.rb, line 100 def self.load_from_v1_gem_name Actions.verify_gem!('aws-sdk-v1') require 'aws-sdk-v1' end
output()
click to toggle source
# File lib/fastlane/plugin/upload_folder_to_s3/actions/upload_folder_to_s3_action.rb, line 185 def self.output [ ['UPLOAD_FOLDER_TO_S3_RESULT', 'An empty string if everything is fine, a short description of the error otherwise'] ] end
return_value()
click to toggle source
# File lib/fastlane/plugin/upload_folder_to_s3/actions/upload_folder_to_s3_action.rb, line 191 def self.return_value [ "The return value is an empty string if everything went fine,", "or an explanation of the error encountered." ].join("\n") end
run(params)
click to toggle source
# File lib/fastlane/plugin/upload_folder_to_s3/actions/upload_folder_to_s3_action.rb, line 8 def self.run(params) base_local_path = params[:local_path] base_remote_path = params[:remote_path] s3_region = params[:region] s3_bucket = params[:bucket] awscreds = { access_key_id: params[:access_key_id], secret_access_key: params[:secret_access_key], region: s3_region } result = "" bucket = valid_bucket awscreds, s3_bucket files = files_at_path base_local_path files.each do |file| local_path = base_local_path + file s3_path = base_remote_path + file obj = write_file_to_bucket(local_path, bucket, s3_path) if obj.exists? next end result = "Error while uploadin file #{local_path}" Actions.lane_context[SharedValues::UPLOAD_FOLDER_TO_S3_RESULT] = result return result end Actions.lane_context[SharedValues::UPLOAD_FOLDER_TO_S3_RESULT] = result result end
v1_sdk_module_present?()
click to toggle source
# File lib/fastlane/plugin/upload_folder_to_s3/actions/upload_folder_to_s3_action.rb, line 105 def self.v1_sdk_module_present? begin # Here we'll make sure that the `AWS` module is defined. If it is, the gem is the v1.x API. Object.const_get("AWS") rescue NameError UI.verbose("Couldn't find the needed `AWS` module in the 'aws-sdk' gem") return false end UI.verbose("Found the needed `AWS` module in the 'aws-sdk' gem") true end
valid_bucket(awscreds, s3_bucket)
click to toggle source
# File lib/fastlane/plugin/upload_folder_to_s3/actions/upload_folder_to_s3_action.rb, line 118 def self.valid_bucket(awscreds, s3_bucket) s3 = valid_s3 awscreds, s3_bucket s3.buckets[s3_bucket] end
valid_s3(awscreds, s3_bucket)
click to toggle source
# File lib/fastlane/plugin/upload_folder_to_s3/actions/upload_folder_to_s3_action.rb, line 68 def self.valid_s3(awscreds, s3_bucket) loaded_original_gem = load_from_original_gem_name if !loaded_original_gem || !v1_sdk_module_present? load_from_v1_gem_name UI.verbose("Loaded AWS SDK v1.x from the `aws-sdk-v1` gem") else UI.verbose("Loaded AWS SDK v1.x from the `aws-sdk` gem") end s3 = AWS::S3.new(awscreds) if s3.buckets[s3_bucket].location_constraint != awscreds[:region] s3 = AWS::S3.new(awscreds.merge(region: s3.buckets[s3_bucket].location_constraint)) end s3 end
write_file_to_bucket(local_path, bucket, s3_path)
click to toggle source
# File lib/fastlane/plugin/upload_folder_to_s3/actions/upload_folder_to_s3_action.rb, line 62 def self.write_file_to_bucket(local_path, bucket, s3_path) obj = bucket.objects[s3_path] obj.write(file: local_path, content_type: content_type_for_file(local_path)) obj end