-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paths3_upload.rb
44 lines (34 loc) · 1.05 KB
/
s3_upload.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'debugger'
require 'yaml'
require "#{File.expand_path(File.dirname(__FILE__))}/s3_uploader.rb"
config = YAML.load_file "#{File.expand_path(Dir.pwd)}/ftp_config.yml"
s3_config = config["s3"]
if s3_config.empty?
abort "Add credentials to ftp_config.yml file"
end
key = s3_config["key"]
secret = s3_config["secret"]
bucket = s3_config["bucket"]
include_dirs = s3_config["include_dirs"]
region = s3_config["region"]
exclude_exts = s3_config["exclude_exts"]
puts region
sha_from = ARGV[0]
sha_to = ARGV[1]
if !sha_from || !sha_to
abort "Invalid params"
end
result = `git show --pretty='format:' --name-only #{sha_from}..#{sha_to}`
s3_instance = S3Uploader.instance(key, secret, bucket, region)
files = result.strip.split("\n").reject { |file| file.empty? }
files.each do |file|
next if !exclude_exts.empty? && exclude_exts.include?(File.extname(file).gsub(".", ""))
if File.exists? file
s3_instance.upload(file, file)
puts "- Uploading #{file}"
else
s3_instance.destroy(file)
puts "- Deleting #{file}"
end
end
`say "Upload S3 Done"`