capistrano-deploytags 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -126,6 +126,14 @@ commit doesn't work as you might expect. The simple solution is to
126
126
  create a new branch from the previous commit you wish to deploy and
127
127
  supplying `-S branch=<new branch>` as arguments to Capistrano.
128
128
 
129
+ Running from Jenkins
130
+ --------------------
131
+ Because Jenkins will check out the code with the current revision
132
+ number you will be in a detached state. This causes the plugin to be
133
+ unhappy about the git tree. The solution is to add `-S branch=$GIT_COMMIT`
134
+ to the cap deploy line called from your Jenkins build. This will cause
135
+ the diffs and comparisons done by the deploytags gem to be correct.
136
+
129
137
  Credits
130
138
  -------
131
139
  This software was written by [Karl Matthias](https://github.com/relistan)
@@ -2,17 +2,24 @@ module Capistrano
2
2
  module DeployTags
3
3
  def pending_git_changes?
4
4
  # Do we have any changes vs HEAD on deployment branch?
5
- !(`git fetch && git diff #{branch} --shortstat`.strip.empty?)
5
+ `git fetch #{remote}`.tap do |output|
6
+ return !(`git diff #{branch} --shortstat`.strip.empty?) if exec_success?
7
+ raise "'git fetch #{remote}' failed:\n #{output}"
8
+ end
6
9
  end
7
10
 
8
11
  def git_tag_for(stage)
9
- "#{stage}-#{Time.now.strftime("%Y.%m.%d-%H%M%S")}"
12
+ "#{stage}-#{Time.new.utc.strftime('%Y.%m.%d-%H%M%S-utc')}"
10
13
  end
11
14
 
12
15
  def safe_run(*args)
13
16
  raise "#{args.join(" ")} failed!" unless system(*args)
14
17
  end
15
18
 
19
+ def exec_success?
20
+ $?.success?
21
+ end
22
+
16
23
  def validate_git_vars
17
24
  unless exists?(:branch) && exists?(:stage)
18
25
  logger.log Capistrano::Logger::IMPORTANT, 'Capistrano Deploytags requires that :branch and :stage be defined.'
@@ -0,0 +1,89 @@
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
+ <<<<<<< HEAD
10
+ "#{stage}-#{Time.new.utc.strftime('%Y.%m.%d-%H%M%S')}"
11
+ =======
12
+ "#{stage}-#{Time.new.utc.strftime('%Y.%m.%d-%H%M%S-utc')}"
13
+ >>>>>>> Added utc to the tag to make the change obvious.
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 and :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 remote
36
+ exists?(:git_remote) ? git_remote : `git remote`.strip.split(/\n/).first
37
+ end
38
+
39
+ def self.load_into(configuration)
40
+ configuration.load do
41
+ before 'deploy', 'git:prepare_tree'
42
+ before 'deploy:migrations', 'git:prepare_tree'
43
+ after 'deploy', 'git:tagdeploy'
44
+ after 'deploy:migrations', 'git:tagdeploy'
45
+
46
+ desc 'prepare git tree so we can tag on successful deployment'
47
+ namespace :git do
48
+ task :prepare_tree, :except => { :no_release => true } do
49
+ next if fetch(:no_deploytags, false)
50
+
51
+ cdt.validate_git_vars
52
+
53
+ logger.log Capistrano::Logger::IMPORTANT, "Preparing to deploy HEAD from branch '#{branch}' to '#{stage}'"
54
+
55
+ if cdt.pending_git_changes?
56
+ logger.log Capistrano::Logger::IMPORTANT, "Whoa there, partner. Dirty trees can't deploy. Git yerself clean first."
57
+ raise 'Dirty git tree'
58
+ end
59
+
60
+ cdt.safe_run 'git', 'checkout', branch
61
+ logger.log Capistrano::Logger::IMPORTANT, "Pulling from #{branch}"
62
+ cdt.safe_run 'git', 'pull', cdt.remote, branch if cdt.has_remote?
63
+ end
64
+
65
+ desc 'add git tags for each successful deployment'
66
+ task :tagdeploy, :except => { :no_release => true } do
67
+ next if fetch(:no_deploytags, false)
68
+
69
+ cdt.validate_git_vars
70
+
71
+ current_sha = `git rev-parse #{branch} HEAD`.strip[0..8]
72
+ logger.log Capistrano::Logger::INFO, "Tagging #{current_sha} for deployment"
73
+
74
+ tag_user = (ENV['USER'] || ENV['USERNAME']).strip
75
+ cdt.safe_run 'git', 'tag', '-a', cdt.git_tag_for(stage), '-m', "#{tag_user} deployed #{current_sha} to #{stage}"
76
+ cdt.safe_run 'git', 'push', '--tags' if cdt.has_remote?
77
+ end
78
+ end
79
+
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ Capistrano.plugin :cdt, Capistrano::DeployTags
86
+
87
+ if Capistrano::Configuration.instance
88
+ Capistrano::DeployTags.load_into(Capistrano::Configuration.instance(:must_exist))
89
+ end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-deploytags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Karl Matthias
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-08-27 00:00:00.000000000 Z
12
+ date: 2014-01-13 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: capistrano
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ! '>='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ! '>='
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: capistrano-ext
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
@@ -52,30 +57,32 @@ extensions: []
52
57
  extra_rdoc_files: []
53
58
  files:
54
59
  - lib/capistrano/deploy_tags.rb
60
+ - lib/capistrano/deploy_tags.rb.orig
55
61
  - lib/capistrano-deploytags.rb
56
62
  - README.md
57
63
  - LICENSE
58
64
  homepage: http://github.com/mydrive/capistrano-deploytags
59
65
  licenses: []
60
- metadata: {}
61
66
  post_install_message:
62
67
  rdoc_options: []
63
68
  require_paths:
64
69
  - lib
65
70
  required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
66
72
  requirements:
67
73
  - - ! '>='
68
74
  - !ruby/object:Gem::Version
69
75
  version: '0'
70
76
  required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
71
78
  requirements:
72
79
  - - ! '>='
73
80
  - !ruby/object:Gem::Version
74
81
  version: '0'
75
82
  requirements: []
76
83
  rubyforge_project:
77
- rubygems_version: 2.0.6
84
+ rubygems_version: 1.8.23
78
85
  signing_key:
79
- specification_version: 4
86
+ specification_version: 3
80
87
  summary: Add dated, environment-specific tags to your git repo at each deployment.
81
88
  test_files: []
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZTkwOGQ4YjJjOWZkMDg4ODEwMjM3NTJlZjEzZDhhYTI3YTFjYzczYw==
5
- data.tar.gz: !binary |-
6
- YzZkMDkxZWM1ZDgzZTJiZmE5NmYzNGM1MDkwYzA2OTAwMGQ0MGFhZQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MTA2OTY3NDU3MjI0MTZlMDJhMjY0M2M3MWMzNjhhN2Q2ZDA2MzJmMGY4N2Nj
10
- ZGNjYzY3ODYzZmQ1MjAyZjMyN2QxOWUyNzVlY2ViODU2YWMyY2Q4NjM0MDE5
11
- M2IwNjBhNmZjYzcxN2E0OWVhNzA0OGY5MDc3YmFjNTkyZTliOTg=
12
- data.tar.gz: !binary |-
13
- MTRiNGMxOTdhYzUzYzE1ZDBlZGFjMTEyNmE0NGM2NzdjZDlhYzMzYTAzNTFk
14
- YzZlYjBiNTg0YTkyNjMzOTAyYWQyN2QxZDMxY2RmODQzMGVmZGRhMTU0YmY2
15
- MDAzNWQ5NTkyMDMwZjRjYmNiNzg0Y2IyZmQwZTI4NjM1ZWNkOTE=