10 Commits
0.9.1 ... 0.9.2

Author SHA1 Message Date
Karl Matthias
ce07273ce1 Rev for release 0.9.2. 2014-05-01 19:44:15 -07:00
Karl Matthias
2c0cb6098a Merge pull request #21 from bramswenson/custom_tag_commit_messages
Added support for customizable tag commit messages
2014-05-01 19:41:37 -07:00
Bram Swenson
e3abc74e5b Updated readme on customizable commit messages 2014-04-30 12:14:33 -07:00
Bram Swenson
7bbf24343e Added support for customizable tag commit messages 2014-04-30 12:06:35 -07:00
Karl Matthias
7c50957282 Added additional test for configurable time format. Clean up tests. 2014-04-09 20:23:49 -07:00
Karl Matthias
2015eb534e Merge pull request #20 from polleverywhere/override_time_format
Make the time format customizable
2014-04-09 20:16:43 -07:00
Mike Foley
207023eb42 Make the time format customizable 2014-04-09 14:42:46 -07:00
Karl Matthias
f10e66b69a Reflect use of UTC time in the README. 2014-01-14 20:38:12 -08:00
Karl Matthias
989665c52a Only package up lib, plus README and LICENSE. 2014-01-14 20:29:18 -08:00
Karl Matthias
b187533157 Use git ls-files to only package up tracked files! (No .orig) 2014-01-14 20:28:07 -08:00
5 changed files with 71 additions and 23 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
.rbenv-version
.bundle

View File

@@ -16,7 +16,7 @@ If I were to issue the command:
This would result in one new git tag with the environment and
timestamp:
`production-2012.04.02-203155`
`production-2012.04.02-203155-utc`
These tags can be used for any number of useful things including
generating statistics about deployments per day/week/year, tracking
@@ -72,7 +72,7 @@ Disabling Tagging for a Stage
-----------------------------
Sometimes you do not want to enable deployment tagging for a particular
stage. In that event, you can simply disable tagging by setting `no_deploytags`
lik so:
like so:
```ruby
set :no_deploytags, true
@@ -86,6 +86,22 @@ are hooked to the Capistrano Deploytags tasks will also still run, but they may
find their expectations are not met with regards to the cleanliness of the git
tree.
Customizing the Tag Format
--------------------------
You may override the time format in `config/deploy.rb`:
```ruby
set :deploytag_time_format, "%Y.%m.%d-%H%M%S-utc"
```
Customizing the Tag Commit Message
----------------------------------
By default, Capistrano Deploytags will create a tag with a message that indicates
the local user name on the box where the deployment is done, and the hash of the
tagged commit. If you prefer to have a more detailed commit message you may override
the `:deploytag_commit_message` setting from your `deploy.rb` or on the command line
with `-S deploytag_commit_message='This is my commit message for the deployed tag'`.
Viewing Deployment History
--------------------------
It's trivial to view the deployment history for a repo. From a checkout
@@ -98,7 +114,6 @@ dev-2013.07.22-114437 gavin deployed 776e15414 to dev
dev-2013.07.22-115103 karl deployed 619ff5724 to dev
dev-2013.07.22-144121 joshmyers deployed cf1ed1a02 to dev
```
A little use of `grep` and you can easily get the history for a
particular (e.g. `git tag -l -n1 | grep dev`).
@@ -128,9 +143,9 @@ 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`
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.

View File

@@ -1,14 +1,14 @@
Gem::Specification.new do |s|
s.name = 'capistrano-deploytags'
s.version = '0.9.1'
s.date = '2014-01-14'
s.version = '0.9.2'
s.date = '2014-05-01'
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.
EOS
s.authors = ["Karl Matthias"]
s.email = 'relistan@gmail.com'
s.files = Dir.glob("lib/**/*") + %w{ README.md LICENSE }
s.files = `git ls-files lib`.split(/\n/) + %w{ README.md LICENSE }
s.homepage = 'http://github.com/mydrive/capistrano-deploytags'
s.add_dependency 'capistrano'
s.add_dependency 'capistrano-ext'

View File

@@ -9,7 +9,11 @@ module Capistrano
end
def git_tag_for(stage)
"#{stage}-#{Time.new.utc.strftime('%Y.%m.%d-%H%M%S-utc')}"
"#{stage}-#{formatted_time}"
end
def formatted_time
Time.new.utc.strftime(fetch(:deploytag_time_format, "%Y.%m.%d-%H%M%S-utc"))
end
def safe_run(*args)
@@ -39,6 +43,15 @@ module Capistrano
exists?(:git_remote) ? git_remote : `git remote`.strip.split(/\n/).first
end
def commit_message(current_sha)
if exists?(:deploytag_commit_message)
deploytag_commit_message
else
tag_user = (ENV['USER'] || ENV['USERNAME'] || 'deployer').strip
"#{tag_user} deployed #{current_sha} to #{stage}"
end
end
def self.load_into(configuration)
configuration.load do
before 'deploy', 'git:prepare_tree'
@@ -74,8 +87,7 @@ module Capistrano
current_sha = `git rev-parse #{branch} HEAD`.strip[0..8]
logger.log Capistrano::Logger::INFO, "Tagging #{current_sha} for deployment"
tag_user = (ENV['USER'] || ENV['USERNAME']).strip
cdt.safe_run 'git', 'tag', '-a', cdt.git_tag_for(stage), '-m', "#{tag_user} deployed #{current_sha} to #{stage}"
cdt.safe_run 'git', 'tag', '-a', cdt.git_tag_for(stage), '-m', cdt.commit_message(current_sha)
cdt.safe_run 'git', 'push', '--tags' if cdt.has_remote?
end
end

View File

@@ -17,7 +17,7 @@ describe Capistrano::DeployTags do
FileUtils.rm_rf tmpdir
FileUtils.mkdir tmpdir
FileUtils.chdir tmpdir
raise unless system("/usr/bin/tar xzf #{File.join(mypath, 'fixtures', 'git-fixture.tar.gz')}")
raise unless system("`which tar` xzf #{File.join(mypath, 'fixtures', 'git-fixture.tar.gz')}")
FileUtils.chdir "#{tmpdir}/git-fixture"
yield
FileUtils.rm_rf tmpdir
@@ -29,13 +29,13 @@ describe Capistrano::DeployTags do
configuration.set(:stage, 'test')
end
it "raises an error when not in a git tree" do
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
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/)
@@ -48,7 +48,7 @@ describe Capistrano::DeployTags do
configuration.set(:stage, 'test')
end
it "raises an error if :stage or :branch are undefined" do
it 'raises an error if :stage or :branch are undefined' do
with_clean_repo do
configuration.unset(:branch)
configuration.unset(:stage)
@@ -56,14 +56,14 @@ describe Capistrano::DeployTags do
end
end
it "does not raise an error when run from a clean tree" 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
it "does not run when :no_deploytags is defined by (i.e. by the stage)" do
it 'does not run when :no_deploytags is defined by (i.e. by the stage)' do
with_clean_repo do
configuration.set(:no_deploytags, true)
configuration.cdt.should_not_receive(:validate_git_vars)
@@ -71,7 +71,7 @@ describe Capistrano::DeployTags do
end
end
it "uses a different remote when one is defined" do
it 'uses a different remote when one is defined' do
with_clean_repo do
system('git remote add nowhere git@example.com:nowhere')
configuration.set(:git_remote, 'nowhere')
@@ -82,7 +82,7 @@ describe Capistrano::DeployTags do
end
end
it "uses the first remote when one is not specified" 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')
@@ -100,13 +100,13 @@ describe Capistrano::DeployTags do
configuration.set(:stage, 'test')
end
it "does not raise an error when run from a clean tree" do
it 'does not raise an error when run from a clean tree' do
with_clean_repo do
expect { configuration.find_and_execute_task('git:tagdeploy') }.to_not raise_error
end
end
it "adds appropriate git tags" do
it 'adds appropriate git tags' do
with_clean_repo do
configuration.find_and_execute_task('git:tagdeploy')
@@ -116,7 +116,7 @@ describe Capistrano::DeployTags do
end
end
it "does not run when :no_deploytags is defined by (i.e. by the stage)" do
it 'does not run when :no_deploytags is defined by (i.e. by the stage)' do
with_clean_repo do
configuration.set(:branch, 'master')
configuration.set(:stage, 'test')
@@ -125,5 +125,25 @@ describe Capistrano::DeployTags do
expect { configuration.find_and_execute_task('git:prepare_tree') }.to_not raise_error
end
end
it 'supports configurable timestamp formats' do
with_clean_repo do
configuration.set(:deploytag_time_format, '%Y-%m-%d')
configuration.find_and_execute_task('git:tagdeploy')
tags = `git tag -l`.split(/\n/)
tags.should have(1).items
tags.first.should =~ /^test-\d{4}-\d{2}-\d{2}/
end
end
it 'supports configurable commit messages' do
with_clean_repo do
configuration.set(:deploytag_commit_message, 'This is my custom commit message')
configuration.find_and_execute_task('git:tagdeploy')
tags = `git tag -l -n40`.split(/\n/)
tags.should have(1).items
tags.first.should =~ /This is my custom commit message/
end
end
end
end