Commit a1ac4fb
Changed files (3)
lib
capistrano
s3tarball
lib/capistrano/s3tarball/tasks/s3.rake
@@ -2,7 +2,7 @@ strategy = self
namespace :s3 do
desc 'Check that the repository is reachable'
- task :check do
+ task :check => 's3:set_current_revision' do
on roles(:all) do
strategy.check
end
@@ -39,4 +39,9 @@ namespace :s3 do
end
end
end
+
+ desc "Determine the revision that will be deployed"
+ task :set_current_revision do
+ set :current_revision, strategy.fetch_revision
+ end
end
lib/capistrano/s3tarball/plugin.rb
@@ -3,11 +3,11 @@ require "capistrano/scm/plugin"
module Capistrano
class S3Plugin < ::Capistrano::SCM::Plugin
def set_defaults
- set :current_revision, ENV.fetch('BUILD_VERSION', `git ls-remote #{fetch(:git_repo)} #{fetch(:git_branch)}`)[0...7]
- set :git_repo, ''
- set :aws_profile, 'default'
- set :git_branch, ENV['BRANCH']
- set :bucket_name, ''
+ set :git_repo, ""
+ set :aws_profile, "default"
+ set :git_branch, ENV.fetch("GIT_BRANCH", "master")
+ set :bucket_name, ""
+ set :current_revision, ENV.fetch("BUILD_REVISION", nil)
end
def define_tasks
@@ -16,6 +16,7 @@ module Capistrano
def register_hooks
after "deploy:new_release_path", "s3:create_release"
+ before "deploy:set_current_revision", "s3:set_current_revision"
before "deploy:check", "s3:check"
end
@@ -28,7 +29,7 @@ module Capistrano
end
def clone
- backend.execute(:mkdir, '-p', repo_path)
+ backend.execute(:mkdir, "-p", repo_path)
end
def update
@@ -53,6 +54,10 @@ module Capistrano
def tarball
"#{fetch(:application)}-#{fetch(:current_revision)}.tar.gz"
end
+
+ def fetch_revision
+ command = "git ls-remote #{fetch(:git_repo)} #{fetch(:git_branch)}"
+ @current_revision ||= fetch(:current_revision) || `#{command}`[0...7]
+ end
end
end
-
lib/capistrano/s3tarball/version.rb
@@ -1,5 +1,5 @@
module Capistrano
module S3tarball
- VERSION = "0.1.0"
+ VERSION = "0.1.1"
end
end