Skip to content

Commit

Permalink
create proper URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
seanlinsley committed Apr 22, 2014
1 parent 3a68e66 commit 9973424
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions script/travis_cache
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,30 @@ require 'digest'
require 'openssl'
require 'shellwords'

URL = 'https://s3.amazonaws.com/ActiveAdmin'
PREFIX = "ruby_#{RUBY_VERSION}-rails_#{ENV.fetch 'RAILS'}-"
ID = ENV.fetch 'AWS_S3_ID'
SECRET = ENV.fetch 'AWS_S3_SECRET'
prefix = "ruby_#{RUBY_VERSION}-rails_#{ENV.fetch 'RAILS'}-"
BUNDLE = prefix + 'bundle'
APP = prefix + 'app'

def download_bundle
s3 :save, file: 'bundle.sha2', as: 'remote_bundle.sha2'
s3 :save, file: 'bundle.tgz', as: 'remote_bundle.tgz', untar: true
s3 :save, file: "#{BUNDLE}.sha2", as: "remote-#{BUNDLE}.sha2"
s3 :save, file: "#{BUNDLE}.tgz", as: "remote-#{BUNDLE}.tgz", untar: true
end

# Don't use an existing archive if the Gemfile.lock changed
def download_app
s3 :save, file: 'app.sha2', as: 'remote_app.sha2'
if !digest_changed?('Gemfile.lock', 'remote_bundle.sha2', 'bundle.sha2') &&
!digest_changed?('spec/support', 'remote_app.sha2', 'app.sha2')
s3 :save, file: 'app.tgz', as: 'remote_app.tgz', untar: true
s3 :save, file: "#{APP}.sha2", as: "remote-#{APP}.sha2"
if !digest_changed?('Gemfile.lock', "remote-#{BUNDLE}.sha2", "#{BUNDLE}.sha2") &&
!digest_changed?('spec/support', "remote-#{APP}.sha2", "#{APP}.sha2")
s3 :save, file: "#{APP}.tgz", as: "remote-#{APP}.tgz", untar: true
end
end

def upload
[ ['Gemfile.lock', 'bundle', 'bundle'],
['spec/support', 'app', 'spec/rails']
[ ['Gemfile.lock', BUNDLE, 'bundle'],
['spec/support', APP, 'spec/rails']
].each do |to_check, name, to_save|
puts "=> Checking #{to_check} for changes"
if digest_changed? to_check, "remote_#{name}.sha2", "#{name}.sha2"
if digest_changed? to_check, "remote-#{name}.sha2", "#{name}.sha2"
puts " => Changes found"

puts " => Creating an archive"
Expand Down Expand Up @@ -64,14 +63,18 @@ def sign(secret, to_sign, digest = 'sha1')
Base64.strict_encode64 OpenSSL::HMAC.digest OpenSSL::Digest.new(digest), secret, to_sign
end

ID = ENV.fetch 'AWS_S3_ID'
SECRET = ENV.fetch 'AWS_S3_SECRET'
URL = 'https://s3.amazonaws.com/ActiveAdmin'

# s3 :list
# s3 :upload, file: 'foo'
# s3 :find, file: 'foo'
# s3 :save, file: 'foo', as: 'bar'
# s3 :save, file: 'foo', untar: true
def s3(action, options = {})
verb = {list: :get, upload: :put, find: :get, save: :get}.fetch action
file = PREFIX + options.fetch(:file) unless action == :list
file = options.fetch(:file) unless action == :list
extra_arg = {
upload: ->{ %[-T "#{file}"] },
save: ->{ %[-o "#{options[:as]}"] if options[:as] }
Expand Down

0 comments on commit 9973424

Please sign in to comment.