10 Commits
0.8.0 ... 0.9.1

Author SHA1 Message Date
Karl Matthias
90177a7ff5 Rev for bugifxed release 0.9.1. 2014-01-14 20:17:01 -08:00
Karl Matthias
257b59c37d Rev for release 0.9.0. 2014-01-13 21:14:29 -08:00
Karl Matthias
b5b1cae948 Fix a bunch of test failures due to new git fetch code. 2014-01-13 21:06:45 -08:00
Karl Matthias
72224b2d96 Add test for validating git fetch. 2014-01-13 20:57:13 -08:00
Karl Matthias
d5a6d036c9 Merge pull request #17 from aspiers/master
correctly handle failing git fetch
2014-01-13 20:39:04 -08:00
Adam Spiers
c247629356 correctly handle failing git fetch
If the repository doesn't have an upstream branch configured, git fetch
will output an error; handle this separately to prevent it interfering
with the git diff call which checks to see if we have any pending
changes.
2013-12-13 11:53:56 +00:00
Karl Matthias
b8b4ffce03 Added information about running deployments from Jenkins. 2013-11-19 15:43:01 -08:00
Karl Matthias
bcecbcc885 Added utc to the tag to make the change obvious. 2013-10-16 11:36:54 -07:00
relistan
85a7fcd2f4 Merge pull request #15 from tute/patch-1
Use UTC timestamp for teams in different timezones [fixes #14]
2013-10-16 11:30:23 -07:00
Tute Costa
368ec7e2a2 Use UTC timestamp for teams in different timezones [fixes #14] 2013-10-11 23:25:57 +02:00
4 changed files with 35 additions and 6 deletions

View File

@@ -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)

View File

@@ -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.1'
s.date = '2014-01-14'
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.

View File

@@ -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.'

View File

@@ -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')