diff --git a/.gitignore b/.gitignore index a0cf52b..730ea3f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .rbenv-version +.bundle diff --git a/README.md b/README.md index 72d531c..4252daf 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,13 @@ You may override the time format in `config/deploy.rb`: 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 -------------------------- @@ -107,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`). @@ -137,9 +143,9 @@ supplying `-S 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. diff --git a/lib/capistrano/deploy_tags.rb b/lib/capistrano/deploy_tags.rb index 0febdca..7ba2c4a 100644 --- a/lib/capistrano/deploy_tags.rb +++ b/lib/capistrano/deploy_tags.rb @@ -43,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' @@ -78,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 diff --git a/spec/capistrano_deploy_tags_spec.rb b/spec/capistrano_deploy_tags_spec.rb index f27d21c..7006ab4 100644 --- a/spec/capistrano_deploy_tags_spec.rb +++ b/spec/capistrano_deploy_tags_spec.rb @@ -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 @@ -135,5 +135,15 @@ describe Capistrano::DeployTags do 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