Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
257b59c37d | ||
|
|
b5b1cae948 | ||
|
|
72224b2d96 | ||
|
|
d5a6d036c9 | ||
|
|
c247629356 | ||
|
|
b8b4ffce03 | ||
|
|
bcecbcc885 | ||
|
|
85a7fcd2f4 | ||
|
|
368ec7e2a2 |
@@ -126,6 +126,14 @@ commit doesn't work as you might expect. The simple solution is to
|
||||
create a new branch from the previous commit you wish to deploy and
|
||||
supplying `-S branch=<new branch>` as arguments to Capistrano.
|
||||
|
||||
Running from Jenkins
|
||||
--------------------
|
||||
Because Jenkins will check out the code with the current revision
|
||||
number you will be in a detached state. This causes the plugin to be
|
||||
unhappy about the git tree. The solution is to add `-S branch=$GIT_COMMIT`
|
||||
to the cap deploy line called from your Jenkins build. This will cause
|
||||
the diffs and comparisons done by the deploytags gem to be correct.
|
||||
|
||||
Credits
|
||||
-------
|
||||
This software was written by [Karl Matthias](https://github.com/relistan)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Gem::Specification.new do |s|
|
||||
s.name = 'capistrano-deploytags'
|
||||
s.version = '0.8.0'
|
||||
s.date = '2013-08-27'
|
||||
s.version = '0.9.0'
|
||||
s.date = '2014-01-13'
|
||||
s.summary = "Add dated, environment-specific tags to your git repo at each deployment."
|
||||
s.description = <<-EOS
|
||||
Capistrano Deploytags is a simple plugin to Capistrano that works with your deployment framework to track your code releases. All you have to do is require capistrano-deploytags and each deployment will add a new tag for that deployment, pointing to the latest commit. This lets you easily see which code is deployed on each environment, and allows you to figure out which code was running in an environment at any time in the past.
|
||||
|
||||
@@ -2,17 +2,24 @@ module Capistrano
|
||||
module DeployTags
|
||||
def pending_git_changes?
|
||||
# Do we have any changes vs HEAD on deployment branch?
|
||||
!(`git fetch && git diff #{branch} --shortstat`.strip.empty?)
|
||||
`git fetch #{remote}`.tap do |output|
|
||||
return !(`git diff #{branch} --shortstat`.strip.empty?) if exec_success?
|
||||
raise "'git fetch #{remote}' failed:\n #{output}"
|
||||
end
|
||||
end
|
||||
|
||||
def git_tag_for(stage)
|
||||
"#{stage}-#{Time.now.strftime("%Y.%m.%d-%H%M%S")}"
|
||||
"#{stage}-#{Time.new.utc.strftime('%Y.%m.%d-%H%M%S-utc')}"
|
||||
end
|
||||
|
||||
def safe_run(*args)
|
||||
raise "#{args.join(" ")} failed!" unless system(*args)
|
||||
end
|
||||
|
||||
def exec_success?
|
||||
$?.success?
|
||||
end
|
||||
|
||||
def validate_git_vars
|
||||
unless exists?(:branch) && exists?(:stage)
|
||||
logger.log Capistrano::Logger::IMPORTANT, 'Capistrano Deploytags requires that :branch and :stage be defined.'
|
||||
|
||||
@@ -24,13 +24,24 @@ describe Capistrano::DeployTags do
|
||||
end
|
||||
|
||||
context "prepare_tree" do
|
||||
it "raises an error when not in a git tree" do
|
||||
FileUtils.chdir '/tmp'
|
||||
before do
|
||||
configuration.set(:branch, 'master')
|
||||
configuration.set(:stage, 'test')
|
||||
end
|
||||
|
||||
it "raises an error when not in a git tree" do
|
||||
FileUtils.chdir '/tmp'
|
||||
configuration.cdt.stub(exec_success?: true)
|
||||
expect { configuration.find_and_execute_task('git:prepare_tree') }.to raise_error('git checkout master failed!')
|
||||
end
|
||||
|
||||
it "raises when unable to fetch" do
|
||||
with_clean_repo do
|
||||
configuration.cdt.should_receive(:exec_success?).and_return(false)
|
||||
expect { configuration.find_and_execute_task('git:prepare_tree') }.to raise_error(/'git fetch ' failed/)
|
||||
end
|
||||
end
|
||||
|
||||
context "with a clean git tree" do
|
||||
before :each do
|
||||
configuration.set(:branch, 'master')
|
||||
@@ -47,6 +58,7 @@ describe Capistrano::DeployTags do
|
||||
|
||||
it "does not raise an error when run from a clean tree" do
|
||||
with_clean_repo do
|
||||
configuration.cdt.stub(exec_success?: true)
|
||||
expect { configuration.find_and_execute_task('git:prepare_tree') }.to_not raise_error
|
||||
end
|
||||
end
|
||||
@@ -63,6 +75,7 @@ describe Capistrano::DeployTags do
|
||||
with_clean_repo do
|
||||
system('git remote add nowhere git@example.com:nowhere')
|
||||
configuration.set(:git_remote, 'nowhere')
|
||||
configuration.cdt.stub(pending_git_changes?: false)
|
||||
configuration.cdt.should_receive(:safe_run).with('git', 'checkout', 'master')
|
||||
configuration.cdt.should_receive(:safe_run).with('git', 'pull', 'nowhere', 'master')
|
||||
configuration.find_and_execute_task('git:prepare_tree')
|
||||
@@ -71,6 +84,7 @@ describe Capistrano::DeployTags do
|
||||
|
||||
it "uses the first remote when one is not specified" do
|
||||
with_clean_repo do
|
||||
configuration.cdt.stub(pending_git_changes?: false)
|
||||
system('git remote add somewhere git@example.com:somewhere')
|
||||
configuration.cdt.should_receive(:safe_run).with('git', 'checkout', 'master')
|
||||
configuration.cdt.should_receive(:safe_run).with('git', 'pull', 'somewhere', 'master')
|
||||
|
||||
Reference in New Issue
Block a user