lib/dpl/provider.rb in dpl-1.1.1 vs lib/dpl/provider.rb in dpl-1.2.0
- old
+ new
@@ -27,22 +27,30 @@
def self.requires(name, options = {})
version = options[:version] || '> 0'
load = options[:load] || name
gem(name, version)
rescue LoadError
- system("gem install %s -v %p" % [name, version])
+ context.shell("gem install %s -v %p" % [name, version])
Gem.clear_paths
ensure
require load
end
+ def self.context
+ self
+ end
+
+ def self.shell(command)
+ system(command)
+ end
+
def self.pip(name, command = name)
- system "pip install #{name}" if `which #{command}`.chop.empty?
+ context.shell "pip install #{name}" if `which #{command}`.chop.empty?
end
def self.npm_g(name, command = name)
- system "npm install -g #{name}" if `which #{command}`.chop.empty?
+ context.shell "npm install -g #{name}" if `which #{command}`.chop.empty?
end
attr_reader :context, :options
def initialize(context, options)
@@ -66,10 +74,12 @@
if needs_key?
create_key(".dpl/id_rsa")
setup_key(".dpl/id_rsa.pub")
setup_git_ssh(".dpl/git-ssh", ".dpl/id_rsa")
end
+
+ cleanup
end
context.fold("Deploying application") { push_app }
Array(options[:run]).each do |command|
@@ -81,18 +91,27 @@
end
ensure
remove_key if needs_key?
end
+ def sha
+ @sha ||= ENV['TRAVIS_COMMIT'] || `git rev-parse HEAD`.strip
+ end
+
+ def cleanup
+ context.shell "git reset --hard #{sha}"
+ context.shell "git clean -dffqx -e .dpl"
+ end
+
def needs_key?
true
end
def check_app
end
def create_key(file)
- system "ssh-keygen -t rsa -N \"\" -C #{option(:key_name)} -f #{file}"
+ context.shell "ssh-keygen -t rsa -N \"\" -C #{option(:key_name)} -f #{file}"
end
def setup_git_ssh(path, key_path)
key_path = File.expand_path(key_path)
path = File.expand_path(path)