Compare commits
12 Commits
0.6.0
...
deploy_old
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8013426a7 | ||
|
|
e84f6a359d | ||
|
|
2bd711ab9c | ||
|
|
f3fb400e98 | ||
|
|
029074e3d4 | ||
|
|
c76311a2b8 | ||
|
|
c38a4dc9d5 | ||
|
|
ae3b749937 | ||
|
|
f713b5ab48 | ||
|
|
68619ccdea | ||
|
|
982dc81bd9 | ||
|
|
7f17000d0c |
15
README.md
15
README.md
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user