62 Commits

Author SHA1 Message Date
62465d2973 Include git in commands without env prefix. 2020-01-23 19:14:42 +00:00
396b2a9972 Override default runner in SSHKit 2020-01-16 19:45:18 +00:00
dcca41a841 Call system instead of execute and run_locally. 2020-01-16 18:32:54 +00:00
Gavin Heavyside
6ef8f3ec46 Merge pull request #33 from vitalied/master
Update for Cap 3.7
2017-02-07 18:45:20 +00:00
Vitalie D
63b13affee Update for Cap 3.7 2017-02-07 18:48:48 +02:00
Gavin Heavyside
7ee61ce716 Bump version and date, pushed to rubygems 2017-01-06 09:04:38 +00:00
Karl Matthias
6156bbe4e5 Merge pull request #31 from simon-soak/patch-1
Undefined variable fix.
2016-08-04 13:08:21 +01:00
Simon hughes
4a3560b753 Undefined variable fix.
Missing fetch(: ).
2016-08-04 13:03:47 +01:00
Karl Matthias
561331b263 Merge pull request #30 from subodhkhanduri1/master
Bump patch version and date
2015-10-18 09:14:45 -07:00
Subodh Khanduri
57efd74341 Bump version and date 2015-10-18 20:48:37 +05:30
Gavin Heavyside
5d31bd7df6 Merge pull request #29 from subodhkhanduri1/master
Add support for custom tag name
2015-10-16 14:18:05 +01:00
Subodh Khanduri
1a8635a98b Add support for custom tag name 2015-10-16 17:58:29 +05:30
Gavin Heavyside
1cff76230d Merge pull request #28 from lacco/master
Update README
2015-08-04 10:24:28 +01:00
Kai Schlichting
eeb75048ba Use correct Gemfile group in README 2015-08-04 11:23:17 +02:00
Kai Schlichting
1ac8d2f9c4 Documentation for deploytag_utc 2015-08-04 11:23:17 +02:00
Gavin Heavyside
36f2405a31 Bump date 2015-05-11 14:45:22 +01:00
Gavin Heavyside
e9ba5e715c Bump version 2015-05-11 14:45:00 +01:00
Gavin Heavyside
11eabe5b7c Merge pull request #27 from dicksonlabs/respect_dry_run
don't create and push the tag when sshkit backend is SSHKit::Backend:::Printer
2015-05-11 14:44:03 +01:00
Ed Slocomb
7eaf0a83f8 don't create and push the tag when sshkit backend is SSHKit::Backend::Printer 2015-05-08 13:25:14 -07:00
Gavin Heavyside
95b1cc15b9 Update date of latest version... 2015-01-22 15:11:40 +00:00
Gavin Heavyside
9f9a0c3d6a Add license to gemspec 2015-01-22 15:09:00 +00:00
Gavin Heavyside
536214fd03 Bump patch version 2015-01-22 15:05:44 +00:00
Gavin Heavyside
964c57d21f Merge pull request #25 from matiaskorhonen/localtime
Make UTC optional
2014-10-23 12:34:04 +01:00
Matias Korhonen
675361e5d9 Makes UTC optional 2014-10-23 13:19:17 +03:00
Karl Matthias
4fa2026b00 Merge pull request #22 from mydrive/cap3
Rewritten for Capistrano 3
2014-07-08 16:51:11 -07:00
Gavin Heavyside
0945596b2f Rename to capistrano/deploytags 2014-06-25 12:08:35 +01:00
Gavin Heavyside
8ed22009d7 Use error-level logging for error 2014-06-15 14:53:40 +01:00
Gavin Heavyside
7f0a7e516b Update readme for Cap 3 and new conventions 2014-06-15 14:39:39 +01:00
Gavin Heavyside
0ad8061fbb Tweak gemspec, elide specs which don't work with Cap 3 :( 2014-06-15 14:35:07 +01:00
Gavin Heavyside
0cdc527259 First cut of Capistrano 3 version
Working with a local project, no specs or doc updates yet
2014-06-14 20:54:53 +01:00
Karl Matthias
1e2687ce83 Added Rubygems tag to README. 2014-05-01 20:17:50 -07:00
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
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
Karl Matthias
06b6042ab9 Rev for release 0.8.0. 2013-08-27 15:24:18 +01:00
Karl Matthias
b0133c88c0 Use a configurable remote, or default to the first in git remote list.
Also, don't use double quotes where we don't need them.
2013-08-27 15:22:53 +01:00
Karl Matthias
e934cead87 Make it explicit that the plugin will do a git pull. 2013-08-27 14:28:24 +01:00
Karl Matthias
2dbec99914 Documenation bug fix. 2013-08-27 12:23:15 +01:00
Karl Matthias
c24bab3f37 Further documentation improvements. 2013-08-27 12:22:28 +01:00
Karl Matthias
3c6fc42623 Added explanation of how to disable tagging in the README. 2013-08-27 12:20:42 +01:00
Karl Matthias
bb520be7e3 Add ability to disable all tagging/git checking based on a setting. 2013-08-27 12:15:34 +01:00
Karl Matthias
a24c306e6b Updated README to talk about editing deployment scripts. 2013-08-27 11:53:38 +01:00
Karl Matthias
221b7246c1 Added clarification on deployment history. 2013-07-29 12:08:14 +01:00
Karl Matthias
b85a7a3e48 Added info to README on how to show your deployment history. 2013-07-29 12:06:33 +01:00
Karl Matthias
01f5e36a89 Update on deploying a previous commit. 2013-05-15 09:09:47 +01:00
10 changed files with 279 additions and 245 deletions

3
.gitignore vendored
View File

@@ -1 +1,4 @@
.rbenv-version
.bundle
/bin
Gemfile.lock

View File

@@ -1,9 +1,3 @@
source "https://rubygems.org"
group :test do
gem 'rake'
gem 'rspec'
gem 'capistrano'
gem 'capistrano-ext'
gem 'capistrano-spec', :git => 'git://github.com/mydrive/capistrano-spec.git'
end
gemspec

View File

@@ -1,45 +0,0 @@
GIT
remote: git://github.com/mydrive/capistrano-spec.git
revision: dcc0908dc00872272b1d495bcce70e82240fa8f7
specs:
capistrano-spec (0.1.0)
GEM
remote: https://rubygems.org/
specs:
capistrano (2.11.2)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
capistrano-ext (1.2.1)
capistrano (>= 1.0.0)
diff-lcs (1.1.3)
highline (1.6.11)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
net-ssh (>= 2.0.9)
net-ssh (2.3.0)
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
rake (0.9.2.2)
rspec (2.8.0)
rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0)
rspec-mocks (~> 2.8.0)
rspec-core (2.8.0)
rspec-expectations (2.8.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.8.0)
PLATFORMS
ruby
DEPENDENCIES
capistrano
capistrano-ext
capistrano-spec!
rake
rspec

192
README.md
View File

@@ -1,13 +1,23 @@
Capistrano Deployment Tags
==========================
This plugin to Capistrano will add a timestamped Git tag
at each deployment, automatically. It is intended to be used with
the multistage recipe and will tag each release by environment.
You can, however, use it without multistage simply by setting :branch
and :stage in your recipe.
[![Gem Version](https://badge.fury.io/rb/capistrano-deploytags.svg)](http://badge.fury.io/rb/capistrano-deploytags)
## Capistrano Deployment Tags
This plugin for Capistrano 3 will add a timestamped Git tag
at each deployment, automatically. It requires :branch and :stage to be set,
but as Capistrano 3 is multistage by default (unlike Cap 2) :stage should
already be set, but you can override the variable if you want to change the
name of the tag.
### Requires Capistrano 3.7
As of version 1.0.7, this plugin requires Cap 3.7.
If you need a Capistrano < 3.7 compatible version, then use `gem 'capistrano-deploytags', '1.0.6'`
If you need a Capistrano 2 compatible version, then use `gem 'capistrano-deploytags', '~> 0.9.2'`
### What It Does
What It Does
------------
Simply: it makes it so you can track your deployments from Git.
If I were to issue the command:
@@ -16,42 +26,130 @@ 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
code size over a period of time, detecting Rails migrations, and
probably a thousand other things I haven't thought of.
Usage
-----
### Usage
capistrano-deploytags is available on
[rubygems.org](https://rubygems.org/gems/capistrano-deploytags).
You can install it from there with:
In keeping with the pattern used by Capistrano itself and other plugins, add it
to the `development` group of your Gemfile with `require: false`:
`gem install capistrano-deploytags`
```ruby
# Gemfile
group :development do
gem 'capistrano-deploytags', '~> 1.0.0', require: false
end
```
If you use Bundler, be sure to add the gem to your Gemfile.
In your Capistrano `config/deploy.rb` you should add:
Then require `capistrano/deploytags` in your Capfile
`require 'capistrano-deploytags'`
```
# Capfile
require 'capistrano/deploytags'
```
This will create two tasks, one that runs before deployment and one
that runs after.
This will create two tasks, one that runs before the `deploy` task, and one
that runs after the `cleanup` task.
NOTE: You will be creating and pushing tags from the version of the
code in the current checkout. This plugin needs to be run from a
clean checkout of your codebase. You should be deploying from a
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.
*NOTE:* You will be creating and pushing tags from the version of the code in the
current checkout. This plugin needs to be run from a clean checkout of your
codebase. You should be deploying from a 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.
*ALSO:* The plugin will do a pull to make sure you have the code on your local
system that will actually be deployed before checking the tree for changes.
Know this ahead of time as this may affect how you deal with your deployment
branches.
### Setting the Remote
By default, Capistrano Deploytags will use the remote names `origin`. If you
use a different remote name, then you may change the `:git_remote` setting
from your `deploy.rb` or the stage.
### Working on Your Deployment Scripts
Because you must have a clean tree to deploy, working on your deployment
scripts themselves can be a bit frustrating unless you know how to make it
work. The easiest way around this problem is to simply commit your changes
before you deploy. You do not have to push them. The plugin will then
happily carry on deploying without complaint.
Alternatively, you could disable the plugin temporarily with one of the
methods described below.
### 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`
like so:
```ruby
set :no_deploytags, true
```
You can also set this from the command line at any time with an environment
variable `cap stage deploy NO_DEPLOYTAGS=true`.
*NOTE:* this will disable the use of the plugin's functionality entirely for
that stage. The tasks will run, but will do nothing. This means that tasks that
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 `deploy.rb` or your stage:
```ruby
set :deploytag_time_format, "%Y.%m.%d-%H%M%S-utc"
```
To use your local time and not UTC (so that ```Time.now``` and not ```Time.now.utc``` is used internally):
```ruby
set :deploytag_utc, false
```
### 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`, e.g.
`set :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
of the repo, type `git tag -l -n1`. The output looks something like:
```
dev-2013.07.22-105130 baz deployed a4d522d9d to dev
dev-2013.07.22-113207 karl deployed 4c43f8464 to dev
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 josh 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`).
It should be noted that the names used when tags are created are the
local user name on the box where the deployment is done.
### Helpful Git Config
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.
```
```ini
[alias]
lol = log --pretty=oneline --abbrev-commit --graph --decorate
```
@@ -59,13 +157,43 @@ to get a nice history view of the commits and tags.
You can then view the list by typing `git lol` from the checked out
code path.
Credits
-------
### Deploying a Previous Commit
Because you have to actually be on the head of the branch you are
deploying in order for tagging to work properly, deploying a previous
commit doesn't work as you might expect.
One simple solution is to configure your `config.rb` to accept an ENV var
override. Then if you need to deploy a previous commit you can check out that
commit (SHA or branch), and supply the var on the command line. e.g. with this
in your `config.rb`:
```ruby
set :branch, ENV["REVISION"] || ENV["BRANCH_NAME"] || "master"
```
you can deploy a previous commit with
```shell
git checkout <previous-commit>
cap <stage> deploy REVISION=<previous-commit>
```
### 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)
with help from [Gavin Heavyside](https://github.com/gavinheavyside) and the
support of [MyDrive Solutions Limited](http://mydrivesolutions.com).
License
-------
### License
This plugin is released under the BSD two clause license which is
available in both the Ruby Gem and the source repository.

View File

@@ -1,16 +1,19 @@
Gem::Specification.new do |s|
s.name = 'capistrano-deploytags'
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, 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.
s.license = 'BSD-2-Clause'
s.version = '1.0.7'
s.date = '2017-02-07'
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 3 that works with your deployment framework to track your code releases. All you have to do is require capistrano-deploytags/capistrano 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.authors = ['Karl Matthias', 'Gavin Heavyside']
s.email = ['relistan@gmail.com', 'gavin.heavyside@mydrivesolutions.com']
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'
s.add_dependency 'capistrano', '>= 3.7.0'
# s.add_development_dependency 'capistrano-spec'
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec', '~> 3.0.0'
s.require_path = 'lib'
end

View File

@@ -1,3 +0,0 @@
Dir[File.join(File.dirname(__FILE__), 'capistrano', '*')].each do |file|
require file
end

View File

@@ -1,77 +0,0 @@
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?)
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 and :stage'
end
end
def git_tag?(tag)
!`git tag -l #{tag}`.strip.empty?
end
def has_remote?
!`git remote`.strip.empty?
end
def self.load_into(configuration)
configuration.load do
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'
end
cdt.safe_run "git", "checkout", branch
cdt.safe_run "git", "pull", "origin", branch if cdt.has_remote?
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
end
end
end
end
Capistrano.plugin :cdt, Capistrano::DeployTags
if Capistrano::Configuration.instance
Capistrano::DeployTags.load_into(Capistrano::Configuration.instance(:must_exist))
end

View File

@@ -0,0 +1,47 @@
# Ensure deploy tasks are loaded before we run
require 'capistrano/deploy'
module SSHKit
class CommandMap
def defaults
Hash.new do |hash, command|
if %w{if test time exec git}.include? command.to_s || !File.executable?('/usr/bin/env')
hash[command] = command.to_s
else
hash[command] = "/usr/bin/env #{command}"
#hash[command] = "#{command}"
end
end
end
end
end
# Load extra tasks into the deploy namespace
load File.expand_path("../tasks/deploytags.rake", __FILE__)
module CapistranoDeploytags
class Helper
def self.git_tag_for(stage)
"#{stage}-#{formatted_time}"
end
def self.formatted_time
now = if fetch(:deploytag_utc, true)
Time.now.utc
else
Time.now
end
now.strftime(fetch(:deploytag_time_format, "%Y.%m.%d-%H%M%S-#{now.zone.downcase}"))
end
def self.commit_message(current_sha, stage)
if fetch(:deploytag_commit_message, false)
fetch(:deploytag_commit_message)
else
tag_user = (ENV['USER'] || ENV['USERNAME'] || 'deployer').strip
"#{tag_user} deployed #{current_sha} to #{stage}"
end
end
end
end

View File

@@ -0,0 +1,52 @@
namespace :deploy do
desc 'prepare git tree so we can tag on successful deployment'
before :deploy, :prepare_tree do
SSHKit.config.default_env = {}
run_locally do
if ENV['NO_DEPLOYTAGS'] || fetch(:no_deploytags, false)
info "[deploytags] Skipping deploytags"
else
branch = fetch(:branch, false)
stage = fetch(:stage, false)
unless branch && stage
error 'capistrano-deploytags requires that :branch and :stage be defined'
raise 'define :branch and :stage'
end
execute :git, "fetch #{fetch(:git_remote, 'origin')}"
diff_output = capture :git, "diff #{branch} --shortstat"
unless diff_output.empty?
error "Whoa there, partner. Dirty trees can't deploy. Git yerself clean first"
raise 'Dirty git tree'
end
execute :git, "checkout #{branch}"
info "Pulling from #{branch}"
execute :git, "pull #{fetch(:git_remote, 'origin')} #{branch}"
end
end
end
desc 'add git tags for each successful deployment'
after :cleanup, :tagdeploy do
run_locally do
if ENV['NO_DEPLOYTAGS'] || fetch(:no_deploytags, false)
info "[deploytags] Skipping deploytags"
else
tag_name = ENV['CUSTOM_DEPLOYTAG'] || fetch(:custom_deploytag) || CapistranoDeploytags::Helper.git_tag_for(fetch(:stage))
latest_revision = fetch(:current_revision)
commit_message = CapistranoDeploytags::Helper.commit_message(latest_revision, fetch(:stage))
unless fetch(:sshkit_backend) == SSHKit::Backend::Printer # unless --dry-run flag present
execute :git, "tag -a #{tag_name} -m \"#{commit_message}\" #{latest_revision}"
execute :git, "push #{fetch(:git_remote, 'origin')} #{tag_name}"
end
info "[cap-deploy-tagger] Tagged #{latest_revision} with #{tag_name}"
end
end
end
end

View File

@@ -1,73 +1,5 @@
require 'capistrano'
require 'capistrano-spec'
require 'fileutils'
mypath = File.expand_path(File.dirname(__FILE__))
require File.expand_path(File.join(mypath, '..', 'lib', 'capistrano', 'deploy_tags'))
require 'rspec'
describe Capistrano::DeployTags do
let(:configuration) { Capistrano::Configuration.new }
let(:tmpdir) { "/tmp/#{$$}" }
let(:mypath) { mypath }
before :each do
Capistrano::DeployTags.load_into(configuration)
end
def with_clean_repo(&block)
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')}")
FileUtils.chdir "#{tmpdir}/git-fixture"
yield
FileUtils.rm_rf tmpdir
end
context "prepare_tree" do
it "raises an error when not in a git tree" do
FileUtils.chdir '/tmp'
configuration.set(:branch, 'master')
configuration.set(:stage, 'test')
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
expect { configuration.find_and_execute_task('git:prepare_tree') }.to raise_error('define :branch and :stage')
end
end
it "does not raise an error when run from a clean tree" do
with_clean_repo do
configuration.set(:branch, 'master')
configuration.set(:stage, 'test')
expect { configuration.find_and_execute_task('git:prepare_tree') }.to_not raise_error
end
end
end
end
context "tagdeploy" do
before :each do
configuration.set(:branch, 'master')
configuration.set(:stage, 'test')
end
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
with_clean_repo do
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
end
describe 'Capistrano::Deploytags' do
pending "capistrano-spec doesn't support Capistrano 3"
end