12 Commits

Author SHA1 Message Date
Barrie Bremner
e8013426a7 Avoid pulling a SHA if specified with -s revision=, just branches. 2013-01-30 16:43:08 +00:00
Barrie Bremner
e84f6a359d Check state of local tree with git status, rather than a diff, since there's no guarantee we're at the right point on the branch at this stage. 2013-01-30 14:08:59 +00:00
Karl Matthias
2bd711ab9c Rev for release 0.7.0. 2012-10-02 20:49:46 +01:00
relistan
f3fb400e98 Merge pull request #7 from pusewicz/master
Fix tagging on deploy:migrations
2012-10-02 12:40:32 -07:00
Piotr Usewicz
029074e3d4 Fix deploy:migrations tagging 2012-10-02 11:45:01 +01:00
Karl Matthias
c76311a2b8 Use more modern rspec syntax for lambda 2012-09-28 20:26:21 +01:00
Karl Matthias
c38a4dc9d5 Fix test broken by one-line pul request! 2012-09-28 20:05:14 +01:00
relistan
ae3b749937 Merge pull request #4 from mydrive/gh3_inconsistent_validation_vs_exception
Issue 3: bring exception message inline with code
2012-09-28 12:00:19 -07:00
Barrie Bremner
f713b5ab48 GH issue 3: bring exception message inline with code, :branch _and_ :stage must be defined. 2012-09-26 11:27:57 +01:00
Karl Matthias
68619ccdea Added helpful git config. 2012-08-30 20:50:13 +01:00
Gavin Heavyside
982dc81bd9 Update README.md 2012-07-29 13:17:21 +02:00
Karl Matthias
7f17000d0c Update description for rubygems. 2012-05-30 23:00:35 +01:00
4 changed files with 54 additions and 27 deletions

View File

@@ -46,10 +46,23 @@ clean checkout anyway, so in most cases this is not a restriction
on how you already do things. The plugin will check if your code
is clean and complain if it is not.
Helpful Git Config
------------------
You might find it useful to add this to your ~/.gitconfig in order
to get a nice history view of the commits and tags.
```
[alias]
lol = log --pretty=oneline --abbrev-commit --graph --decorate
```
You can then view the list by typing `git lol` from the checked out
code path.
Credits
-------
This software was written by [Karl Matthias](https://github.com/relistan)
with help from [Gavin Heavyside](https://github.com/hgavin) and the
with help from [Gavin Heavyside](https://github.com/gavinheavyside) and the
support of [MyDrive Solutions Limited](http://mydrivesolutions.com).
License

View File

@@ -1,10 +1,10 @@
Gem::Specification.new do |s|
s.name = 'capistrano-deploytags'
s.version = '0.6.0'
s.date = '2012-05-30'
s.version = '0.7.0'
s.date = '2012-10-02'
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, and will move the *-latest tag 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.
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'

View File

@@ -1,22 +1,23 @@
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?)
def uncommitted_git_changes?
# Is the working directory clean?
!( `git status --porcelain`.strip.empty? )
end
def git_tag_for(stage)
"#{stage}-#{Time.now.strftime("%Y.%m.%d-%H%M%S")}"
end
def safe_run(*args)
raise "#{args.join(" ")} failed!" unless system(*args)
end
def validate_git_vars
unless exists?(:branch) && exists?(:stage)
logger.log Capistrano::Logger::IMPORTANT, "Capistrano Deploytags requires that :branch and :stage be defined."
raise 'define :branch or :stage'
raise 'define :branch and :stage'
end
end
@@ -30,35 +31,48 @@ module Capistrano
def self.load_into(configuration)
configuration.load do
before :deploy, 'git:prepare_tree'
after :deploy, 'git:tagdeploy'
before "deploy", 'git:prepare_tree'
before "deploy:migrations", 'git:prepare_tree'
after "deploy", 'git:tagdeploy'
after "deploy:migrations", 'git:tagdeploy'
desc 'prepare git tree so we can tag on successful deployment'
namespace :git do
task :prepare_tree, :except => { :no_release => true } do
cdt.validate_git_vars
logger.log Capistrano::Logger::IMPORTANT, "Preparing to deploy HEAD from branch '#{branch}' to '#{stage}'"
if cdt.pending_git_changes?
logger.log Capistrano::Logger::IMPORTANT, "Whoa there, partner. Dirty trees can't deploy. Git yerself clean first."
raise 'Dirty git tree'
if cdt.uncommitted_git_changes?
logger.log Capistrano::Logger::IMPORTANT, "Sorry, you have uncommitted changes. Please commit or stash them."
end
cdt.safe_run "git", "checkout", branch
cdt.safe_run "git", "pull", "origin", branch if cdt.has_remote?
cdt.safe_run "git", "fetch"
ref = fetch(:revision, branch)
if exists?(:revision)
logger.log Capistrano::Logger::IMPORTANT, "Preparing to deploy '#{ref}' to '#{stage}'"
else
logger.log Capistrano::Logger::IMPORTANT, "Preparing to deploy HEAD from '#{ref}' to '#{stage}'"
end
cdt.safe_run "git", "checkout", ref
# It doesn't make sense to pull a SHA, only a branch.
if cdt.has_remote? && ! exists?(:revision)
cdt.safe_run "git", "pull", "origin", ref
end
end
desc 'add git tags for each successful deployment'
task :tagdeploy, :except => { :no_release => true } do
cdt.validate_git_vars
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", "push", "--tags" if cdt.has_remote?
end
end

View File

@@ -28,13 +28,13 @@ describe Capistrano::DeployTags do
FileUtils.chdir '/tmp'
configuration.set(:branch, 'master')
configuration.set(:stage, 'test')
lambda { configuration.find_and_execute_task('git:prepare_tree') }.should raise_error('git checkout master failed!')
expect { configuration.find_and_execute_task('git:prepare_tree') }.to raise_error('git checkout master failed!')
end
context "with a clean git tree" do
it "raises an error if :stage or :branch are undefined" do
with_clean_repo do
lambda { configuration.find_and_execute_task('git:prepare_tree') }.should raise_error('define :branch or :stage')
expect { configuration.find_and_execute_task('git:prepare_tree') }.to raise_error('define :branch and :stage')
end
end
@@ -42,7 +42,7 @@ describe Capistrano::DeployTags do
with_clean_repo do
configuration.set(:branch, 'master')
configuration.set(:stage, 'test')
lambda { configuration.find_and_execute_task('git:prepare_tree') }.should_not raise_error
expect { configuration.find_and_execute_task('git:prepare_tree') }.to_not raise_error
end
end
end
@@ -56,7 +56,7 @@ describe Capistrano::DeployTags do
it "does not raise an error when run from a clean tree" do
with_clean_repo do
lambda { configuration.find_and_execute_task('git:tagdeploy') }.should_not raise_error
expect { configuration.find_and_execute_task('git:tagdeploy') }.to_not raise_error
end
end