fastlane-plugin-upload_folder_to_s3 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 62f80161b56ff114ab466161a2269960f7ef1b0b
4
+ data.tar.gz: e49d7d20aaff74063d57ccbd551ed6610174b02b
5
+ SHA512:
6
+ metadata.gz: d974f50e83c35786f5cb6856b6dad8229af9351f6ae4705c14ef5a859e7ccaf5226c142985cb252dcc9a7667946d3ebd7b7a989951645210947856684f142a52
7
+ data.tar.gz: 86f4ac7e2e5f72d5d9e76c2b3a68f8226f1033b8e766e503d9f4e7ee117e4e19f685425ab9d6e10558cd048e3aad48325bfb8c82a01632b265a2bdf999edba43
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 teriiehina <peter@teriiehina.pf>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # fastlane-plugin-upload_folder_to_s3 `fastlane` Plugin
2
+
3
+ [![Gem](assets/plugin-badge.svg)](https://rubygems.org/gems/upload_folder_to_s3)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [fastlane](https://github.com/fastlane/fastlane) plugin. To get started with fastlane-plugin-upload_folder_to_s3, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin upload_folder_to_s3
11
+ ```
12
+
13
+ ## About upload_folder_to_s3
14
+
15
+ Upload a folder to S3
16
+
17
+ ## Issues and Feedback
18
+
19
+ For any other issues and feedback about this plugin, please submit it to this repository.
20
+
21
+ ## Troubleshooting
22
+
23
+ For some , check out the [Plugins Troubleshooting](https://github.com/fastlane/fastlane/blob/master/fastlane/docs/PluginsTroubleshooting.md) doc in the main `fastlane` repo.
24
+
25
+ ## Using `fastlane` Plugins
26
+
27
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Plugins.md) in the main `fastlane` repo.
28
+
29
+ ## About `fastlane`
30
+
31
+ `fastlane` automates building, testing, and releasing your app for beta and app store distributions. To learn more about `fastlane`, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/upload_folder_to_s3/version'
2
+
3
+ module Fastlane
4
+ module UploadFolderToS3
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::UploadFolderToS3.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,207 @@
1
+ module Fastlane
2
+ module Actions
3
+ module SharedValues
4
+ UPLOAD_FOLDER_TO_S3_RESULT = :UPLOAD_FOLDER_TO_S3_RESULT
5
+ end
6
+
7
+ class UploadFolderToS3Action < Action
8
+ def self.run(params)
9
+ base_local_path = params[:local_path]
10
+ base_remote_path = params[:remote_path]
11
+ s3_region = params[:region]
12
+ s3_bucket = params[:bucket]
13
+
14
+ awscreds = {
15
+ access_key_id: params[:access_key_id],
16
+ secret_access_key: params[:secret_access_key],
17
+ region: s3_region
18
+ }
19
+
20
+ result = ""
21
+ bucket = valid_bucket awscreds, s3_bucket
22
+ files = files_at_path base_local_path
23
+
24
+ files.each do |file|
25
+ local_path = base_local_path + file
26
+ s3_path = base_remote_path + file
27
+
28
+ obj = write_file_to_bucket(local_path, bucket, s3_path)
29
+
30
+ if obj.exists?
31
+ next
32
+ end
33
+
34
+ result = "Error while uploadin file #{local_path}"
35
+ Actions.lane_context[SharedValues::UPLOAD_FOLDER_TO_S3_RESULT] = result
36
+ return result
37
+ end
38
+
39
+ Actions.lane_context[SharedValues::UPLOAD_FOLDER_TO_S3_RESULT] = result
40
+ result
41
+ end
42
+
43
+ def self.files_at_path(path)
44
+ files = Dir.glob(path + "/**/*")
45
+ to_remove = []
46
+
47
+ files.each do |file|
48
+ if File.directory?(file)
49
+ to_remove.push file
50
+ else
51
+ file.slice! path
52
+ end
53
+ end
54
+
55
+ to_remove.each do |file|
56
+ files.delete file
57
+ end
58
+
59
+ files
60
+ end
61
+
62
+ def self.write_file_to_bucket(local_path, bucket, s3_path)
63
+ obj = bucket.objects[s3_path]
64
+ obj.write(file: local_path, content_type: content_type_for_file(local_path))
65
+ obj
66
+ end
67
+
68
+ def self.valid_s3(awscreds, s3_bucket)
69
+ Actions.verify_gem!('aws-sdk')
70
+ require 'aws-sdk'
71
+
72
+ s3 = AWS::S3.new(awscreds)
73
+
74
+ if s3.buckets[s3_bucket].location_constraint != awscreds[:region]
75
+ s3 = AWS::S3.new(awscreds.merge(region: s3.buckets[s3_bucket].location_constraint))
76
+ end
77
+
78
+ s3
79
+ end
80
+
81
+ def self.valid_bucket(awscreds, s3_bucket)
82
+ s3 = valid_s3 awscreds, s3_bucket
83
+ s3.buckets[s3_bucket]
84
+ end
85
+
86
+ #####################################################
87
+ # @!group Documentation
88
+ #####################################################
89
+
90
+ def self.description
91
+ %q{Upload a folder to S3}
92
+ end
93
+
94
+ def self.details
95
+ [
96
+ "If you want to use regex to exclude some files, please contribute to this action.",
97
+ "Else, just do like me and from your artifacts/builds/product folder,",
98
+ "create the subset you want to upload in another folder and upload it using this action."
99
+ ].join("\n")
100
+ end
101
+
102
+ def self.available_options
103
+ [
104
+ FastlaneCore::ConfigItem.new(key: :access_key_id,
105
+ env_name: "FL_UPLOAD_FOLDER_TO_S3_ACCESS_KEY_ID",
106
+ description: "Access key ID",
107
+ verify_block: proc do |value|
108
+ UI.user_error!(UploadFolderToS3Action.no_access_key_id_error_message) if value.to_s.length == 0
109
+ end),
110
+
111
+ FastlaneCore::ConfigItem.new(key: :secret_access_key,
112
+ env_name: "FL_UPLOAD_FOLDER_TO_S3_SECRET_ACCESS_KEY",
113
+ description: "Secret access key",
114
+ verify_block: proc do |value|
115
+ UI.user_error!(UploadFolderToS3Action.no_secret_access_key_error_message) if value.to_s.length == 0
116
+ end),
117
+
118
+ FastlaneCore::ConfigItem.new(key: :region,
119
+ env_name: "FL_UPLOAD_FOLDER_TO_S3_REGION",
120
+ description: "The region",
121
+ verify_block: proc do |value|
122
+ UI.user_error!(UploadFolderToS3Action.no_region_error_message) if value.to_s.length == 0
123
+ end),
124
+
125
+ FastlaneCore::ConfigItem.new(key: :bucket,
126
+ env_name: "FL_UPLOAD_FOLDER_TO_S3_BUCKET",
127
+ description: "Bucket",
128
+ verify_block: proc do |value|
129
+ UI.user_error!(UploadFolderToS3Action.no_bucket_error_message) if value.to_s.length == 0
130
+ end),
131
+
132
+ FastlaneCore::ConfigItem.new(key: :local_path,
133
+ env_name: "FL_UPLOAD_FOLDER_TO_S3_LOCAL_PATH",
134
+ description: "Path to local folder to upload",
135
+ verify_block: proc do |value|
136
+ UI.user_error!(UploadFolderToS3Action.invalid_local_folder_path_message) if value.to_s.length == 0
137
+ end),
138
+
139
+ FastlaneCore::ConfigItem.new(key: :remote_path,
140
+ env_name: "FL_UPLOAD_FOLDER_TO_S3_REMOTE_PATH",
141
+ description: "The remote base path",
142
+ verify_block: proc do |value|
143
+ UI.user_error!(UploadFolderToS3Action.invalid_remote_folder_path_message) if value.to_s.length == 0
144
+ end)
145
+ ]
146
+ end
147
+
148
+ def self.output
149
+ [
150
+ ['UPLOAD_FOLDER_TO_S3_RESULT', 'An empty string if everything is fine, a short description of the error otherwise']
151
+ ]
152
+ end
153
+
154
+ def self.return_value
155
+ [
156
+ "The return value is an empty string if everything went fine,",
157
+ "or an explanation of the error encountered."
158
+ ].join("\n")
159
+ end
160
+
161
+ def self.authors
162
+ [%q{teriiehina}]
163
+ end
164
+
165
+ def self.is_supported?(platform)
166
+ true
167
+ end
168
+
169
+ def self.content_type_for_file(file)
170
+ file_extension = File.extname(file)
171
+
172
+ extensions_to_type = {
173
+ ".html" => "text/html",
174
+ ".png" => "image/png",
175
+ ".jpg" => "text/jpeg",
176
+ ".gif" => "image/gif",
177
+ ".log" => "text/plain",
178
+ ".css" => "text/css",
179
+ ".js" => "application/javascript"
180
+ }
181
+
182
+ if extensions_to_type[file_extension].nil?
183
+ "application/octet-stream"
184
+ else
185
+ extensions_to_type[file_extension]
186
+ end
187
+ end
188
+
189
+ @no_access_key_id_error_message = "No Access key ID for upload_folder_to_s3 given, pass using `access_key_id: 'key_id'`"
190
+ @no_secret_access_key_error_message = "No Secret access key for upload_folder_to_s3 given, pass using `secret_access_key: 'access_key'`"
191
+ @no_region_error_message = "No region for upload_folder_to_s3 given, pass using `region: 'region'`"
192
+ @no_bucket_error_message = "No bucket for upload_folder_to_s3 given, pass using `bucket: 'bucket'`"
193
+ @invalid_local_folder_path_message = "Invalid local folder path"
194
+ @invalid_remote_folder_path_message = "Invalid remote folder path"
195
+
196
+ class << self
197
+ attr_accessor :no_access_key_id_error_message
198
+ attr_accessor :no_secret_access_key_error_message
199
+ attr_accessor :no_region_error_message
200
+ attr_accessor :no_bucket_error_message
201
+ attr_accessor :invalid_local_folder_path_message
202
+ attr_accessor :invalid_remote_folder_path_message
203
+ end
204
+
205
+ end
206
+ end
207
+ end
@@ -0,0 +1,12 @@
1
+ module Fastlane
2
+ module Helper
3
+ class UploadFolderToS3Helper
4
+ # class methods that you define here become available in your action
5
+ # as `Helper::UploadFolderToS3Helper.your_method`
6
+ #
7
+ def self.show_message
8
+ UI.message("Hello from the upload_folder_to_s3 plugin helper!")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module UploadFolderToS3
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-upload_folder_to_s3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - teriiehina
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fastlane
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.92.0.beta2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.92.0.beta2
69
+ description:
70
+ email: peter@teriiehina.pf
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - LICENSE
76
+ - README.md
77
+ - lib/fastlane/plugin/upload_folder_to_s3.rb
78
+ - lib/fastlane/plugin/upload_folder_to_s3/actions/upload_folder_to_s3_action.rb
79
+ - lib/fastlane/plugin/upload_folder_to_s3/helper/upload_folder_to_s3_helper.rb
80
+ - lib/fastlane/plugin/upload_folder_to_s3/version.rb
81
+ homepage: https://github.com/teriiehina/fastlane-plugin-upload_folder_to_s3
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.4.5.1
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Upload a folder to S3
105
+ test_files: []
106
+ has_rdoc: