capistrano-deploytags 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2012 MyDrive Solutions Limited, All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+
7
+ * Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above
11
+ copyright notice, this list of conditions and the following
12
+ disclaimer in the documentation and/or other materials provided
13
+ with the distribution.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19
+ COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25
+ ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ Capistrano Deployment Tags
2
+ ==========================
3
+ This plugin to Capistrano will add timestamped and latest Git tags
4
+ at each deployment, automatically. It is intended to be used with
5
+ the multistage recipe and will tag each release by environment.
6
+ You can, however, use it without multistage simply by setting :branch
7
+ and :stage in your recipe.
8
+
9
+ What It Does
10
+ ------------
11
+ Simply: it makes it so you can track your deployments from Git.
12
+ If I were to issue the command:
13
+
14
+ `cap production deploy`
15
+
16
+ This would result in one new git tag with the environment and
17
+ timestamp:
18
+
19
+ `production-2012.04.02-203155`
20
+
21
+ It would also result in moving or creating this tag:
22
+
23
+ `production-latest`
24
+
25
+ These tags can be used for any number of useful things including
26
+ generating statistics about deployments per day/week/year, tracking
27
+ code size over a period of time, detecting Rails migrations, and
28
+ probably a thousand other things I haven't thought of.
29
+
30
+ Usage
31
+ -----
32
+ If you use Bundler, be sure to add the gem to your Gemfile.
33
+ In your Capistrano `config/deploy.rb` you should add:
34
+
35
+ `require 'capistrano-deploytags'`
36
+
37
+ This will create two tasks, one that runs before deployment and one
38
+ that runs after.
39
+
40
+ NOTE: You will be creating and pushing tags from the version of the
41
+ code in the current checkout. This plugin needs to be run from a
42
+ clean checkout of your codebase. You should be deploying from a
43
+ clean checkout anyway, so in most cases this is not a restriction
44
+ on how you already do things. The plugin will check if your code
45
+ is clean and complain if it is not.
46
+
47
+ Credits
48
+ -------
49
+ This software was written by [Karl Matthias](https://github.com/relistan)
50
+ with help from [Gavin Heavyside](https://github.com/hgavin) and the
51
+ support of [MyDrive Solutions Limited](http://mydrivesolutions.com).
52
+
53
+ License
54
+ -------
55
+ This plugin is released under the BSD two clause license which is
56
+ available in both the Ruby Gem and the source repository.
@@ -0,0 +1,3 @@
1
+ Dir[File.join(File.dirname(__FILE__), 'capistrano', '*')].each do |file|
2
+ require file
3
+ end
@@ -0,0 +1,84 @@
1
+ module Capistrano
2
+ module DeployTags
3
+ def pending_git_changes?
4
+ # Do we have any changes vs HEAD on deployment branch?
5
+ !(`git fetch && git diff #{branch} --shortstat`.strip.empty?)
6
+ end
7
+
8
+ def git_tag_for(stage)
9
+ "#{stage}-#{Time.now.strftime("%Y.%m.%d-%H%M%S")}"
10
+ end
11
+
12
+ def last_git_tag_for(stage)
13
+ "#{stage}-latest"
14
+ end
15
+
16
+ def safe_run(*args)
17
+ raise "#{args.join(" ")} failed!" unless system(*args)
18
+ end
19
+
20
+ def validate_git_vars
21
+ unless exists?(:branch) && exists?(:stage)
22
+ logger.log Capistrano::Logger::IMPORTANT, "Capistrano Deploytags requires that :branch and :stage be defined."
23
+ raise 'define :branch or :stage'
24
+ end
25
+ end
26
+
27
+ def git_tag?(tag)
28
+ !`git tag -l #{tag}`.strip.empty?
29
+ end
30
+
31
+ def has_remote?
32
+ !`git remote`.strip.empty?
33
+ end
34
+
35
+ def self.load_into(configuration)
36
+ configuration.load do
37
+ before :deploy, 'git:prepare_tree'
38
+ after :deploy, 'git:tagdeploy'
39
+
40
+ desc 'prepare git tree so we can tag on successful deployment'
41
+ namespace :git do
42
+ task :prepare_tree, :except => { :no_release => true } do
43
+ cdt.validate_git_vars
44
+
45
+ logger.log Capistrano::Logger::IMPORTANT, "Preparing to deploy HEAD from branch '#{branch}' to '#{stage}'"
46
+
47
+ if cdt.pending_git_changes?
48
+ logger.log Capistrano::Logger::IMPORTANT, "Whoa there, partner. Dirty trees can't deploy. Git yerself clean first."
49
+ raise 'Dirty git tree'
50
+ end
51
+
52
+ cdt.safe_run "git", "checkout", branch
53
+ cdt.safe_run "git", "pull", "origin", branch if cdt.has_remote?
54
+ end
55
+
56
+ desc 'add git tags for each successful deployment'
57
+ task :tagdeploy, :except => { :no_release => true } do
58
+ cdt.validate_git_vars
59
+
60
+ current_sha = `git rev-parse #{branch} HEAD`.strip[0..8]
61
+ logger.log Capistrano::Logger::INFO, "Tagging #{current_sha} for deployment"
62
+
63
+ tag_user = (ENV['USER'] || ENV['USERNAME']).strip
64
+ cdt.safe_run "git", "tag", "-a", cdt.git_tag_for(stage), "-m", "#{tag_user} deployed #{current_sha} to #{stage}"
65
+ if cdt.git_tag?(cdt.last_git_tag_for(stage))
66
+ cdt.safe_run "git", "tag", "-d", cdt.last_git_tag_for(stage)
67
+ cdt.safe_run "git", "push", "--tags" if cdt.has_remote?
68
+ end
69
+
70
+ cdt.safe_run "git", "tag", "-a", cdt.last_git_tag_for(stage), "-m", "#{tag_user} deployed #{current_sha} to #{stage}"
71
+ cdt.safe_run "git", "push", "--tags" if cdt.has_remote?
72
+ end
73
+ end
74
+
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ Capistrano.plugin :cdt, Capistrano::DeployTags
81
+
82
+ if Capistrano::Configuration.instance
83
+ Capistrano::DeployTags.load_into(Capistrano::Configuration.instance(:must_exist))
84
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-deploytags
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.5'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Karl Matthias
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: &70334355156820 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70334355156820
25
+ - !ruby/object:Gem::Dependency
26
+ name: capistrano-ext
27
+ requirement: &70334355156380 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70334355156380
36
+ description: ! ' All you have to do is require capistrano-deploytags and each deployment
37
+ will add a new tag for that deployment, and will move the *-latest tag to the latest
38
+ commit. This lets you easily see which code is deployed on each environment, and
39
+ allows you to figure out which code was running in an environment at any time in
40
+ the past.
41
+
42
+ '
43
+ email: relistan@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/capistrano/deploy_tags.rb
49
+ - lib/capistrano-deploytags.rb
50
+ - README.md
51
+ - LICENSE
52
+ homepage: http://github.com/mydrive/capistrano_deploytags
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.11
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Add dated, environment-specific tags to your git repo at each deployment.
76
+ test_files: []