capistrano-gitflow 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/README.rdoc +75 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/capistrano-gitflow.gemspec +61 -0
- data/gitflow.gemspec +60 -0
- data/lib/capistrano/gitflow.rb +172 -0
- data/lib/capistrano/gitflow/natcmp.rb +76 -0
- data/recipes/gitflow_recipes.rb +2 -0
- data/spec/gitflow_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +111 -0
data/.document
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
= gitflow: a Capistrano recipe for git deployment using tags in a multistage environment.
|
2
|
+
|
3
|
+
The best thing about this recipe is that there is almost nothing to learn -- your cap deploy process barely changes.
|
4
|
+
Gitflow simply adds some tagging/logging/workflow magic.
|
5
|
+
|
6
|
+
# BEFORE
|
7
|
+
$ cap deploy # 'master' goes to staging
|
8
|
+
$ cap production deploy # 'master' goes to production
|
9
|
+
|
10
|
+
# AFTER
|
11
|
+
$ cap deploy
|
12
|
+
# 'master' goes to staging; tag staging-YYYY-MM-DD.X created
|
13
|
+
$ cap production deploy -s tag=staging-YYYY-MM-DD-X-user-description
|
14
|
+
# tag 'staging-YYYY-MM-DD-X' goes to production
|
15
|
+
# tag 'production-YYYY-MM-DD-X' created; points to staging-YYYY-MM-DD-X
|
16
|
+
|
17
|
+
# BONUS
|
18
|
+
cap gitflow:commit_log
|
19
|
+
# displays a commit log pushed to staging
|
20
|
+
# ... alternatively, if you're using GitHub, will open a page using branch compare
|
21
|
+
cap production gitflow:log_log
|
22
|
+
# displays a commit log of what will be pushed to production
|
23
|
+
|
24
|
+
== INSTALLATION
|
25
|
+
|
26
|
+
First, install the gem:
|
27
|
+
|
28
|
+
gem install capistrano-gitflow
|
29
|
+
|
30
|
+
Then update config/deploy.rb
|
31
|
+
|
32
|
+
require 'capistrano/ext/multistage'
|
33
|
+
require 'capistrano/gitflow' # needs to come after multistage
|
34
|
+
|
35
|
+
== DETAILS
|
36
|
+
|
37
|
+
After experimenting with several workflows for deployment in git, I've finally found one I really like.
|
38
|
+
|
39
|
+
* You can push to staging at any time; every staging push is automatically tagged with a unique tag.
|
40
|
+
* You can only push a staging tag to production. This helps to enforce QA of all pushes to production.
|
41
|
+
|
42
|
+
=== PUSH TO STAGING
|
43
|
+
|
44
|
+
Whenever you want to push the currently checked-out code to staging, just do:
|
45
|
+
|
46
|
+
cap staging deploy
|
47
|
+
|
48
|
+
gitflow will automatically:
|
49
|
+
|
50
|
+
* create a unique tag in the format of 'staging-YYYY-MM-DD.X'
|
51
|
+
* configure multistage to use that tag for the deploy
|
52
|
+
* push the code and tags to the remote "origin"
|
53
|
+
* and run the normal deploy task for the staging stage.
|
54
|
+
|
55
|
+
=== PUSH TO PRODUCTION:
|
56
|
+
|
57
|
+
Whenever you want to push code to production, you must specify the staging tag you wish to promote to production:
|
58
|
+
|
59
|
+
cap production deploy -s tag=staging-2009-09-08.2
|
60
|
+
|
61
|
+
gitflow will automatically:
|
62
|
+
|
63
|
+
* alias the staging tag to a production tag like: production-2008-09-08.2
|
64
|
+
* configure multistage to use that tag for the deploy
|
65
|
+
* push the code and tags to the remote "origin"
|
66
|
+
* and run the normal deploy task for the production stage.
|
67
|
+
|
68
|
+
=== NOTES:
|
69
|
+
|
70
|
+
* you may need to wipe out the cached-copy on the remote server that cap uses when switching to this workflow; I have seen situations where the cached copy cannot cleanly checkout to the new branch/tag. it's safe to try without wiping it out first, it will fail gracefully.
|
71
|
+
* if your stages already have a "set :branch, 'my-staging-branch'" call in your configs, remove it. This workflow configures it automatically.
|
72
|
+
|
73
|
+
== CREDIT
|
74
|
+
|
75
|
+
Originally forked from Alan Pinstein's git_deployment repo. Gemified and hacked by Josh Nichols. There wasn't really a license originally, so...
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "capistrano-gitflow"
|
8
|
+
gem.summary = %Q{Capistrano recipe for a deployment workflow based on git tags }
|
9
|
+
gem.description = %Q{Capistrano recipe for a deployment workflow based on git tags}
|
10
|
+
gem.email = "josh@technicalpickles.com"
|
11
|
+
gem.homepage = "http://github.com/technicalpickles/gitflow"
|
12
|
+
gem.authors = ["Joshua Nichols"]
|
13
|
+
gem.add_dependency "capistrano"
|
14
|
+
gem.add_dependency "stringex"
|
15
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'spec/rake/spectask'
|
24
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
25
|
+
spec.libs << 'lib' << 'spec'
|
26
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
end
|
28
|
+
|
29
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
+
spec.rcov = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task :spec => :check_dependencies
|
36
|
+
|
37
|
+
task :default => :spec
|
38
|
+
|
39
|
+
require 'rake/rdoctask'
|
40
|
+
Rake::RDocTask.new do |rdoc|
|
41
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
42
|
+
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
44
|
+
rdoc.title = "gitflow #{version}"
|
45
|
+
rdoc.rdoc_files.include('README*')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.3.0
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{capistrano-gitflow}
|
8
|
+
s.version = "1.3.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Joshua Nichols"]
|
12
|
+
s.date = %q{2010-06-15}
|
13
|
+
s.description = %q{Capistrano recipe for a deployment workflow based on git tags}
|
14
|
+
s.email = %q{josh@technicalpickles.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
"README.rdoc",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"capistrano-gitflow.gemspec",
|
24
|
+
"gitflow.gemspec",
|
25
|
+
"lib/capistrano/gitflow.rb",
|
26
|
+
"lib/capistrano/gitflow/natcmp.rb",
|
27
|
+
"recipes/gitflow_recipes.rb",
|
28
|
+
"spec/gitflow_spec.rb",
|
29
|
+
"spec/spec.opts",
|
30
|
+
"spec/spec_helper.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/technicalpickles/gitflow}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.6}
|
36
|
+
s.summary = %q{Capistrano recipe for a deployment workflow based on git tags}
|
37
|
+
s.test_files = [
|
38
|
+
"spec/gitflow_spec.rb",
|
39
|
+
"spec/spec_helper.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_runtime_dependency(%q<capistrano>, [">= 0"])
|
48
|
+
s.add_runtime_dependency(%q<stringex>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<capistrano>, [">= 0"])
|
52
|
+
s.add_dependency(%q<stringex>, [">= 0"])
|
53
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<capistrano>, [">= 0"])
|
57
|
+
s.add_dependency(%q<stringex>, [">= 0"])
|
58
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
data/gitflow.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{gitflow}
|
8
|
+
s.version = "1.3.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Joshua Nichols"]
|
12
|
+
s.date = %q{2010-06-15}
|
13
|
+
s.description = %q{Capistrano recipe for a deployment workflow based on git tags}
|
14
|
+
s.email = %q{josh@technicalpickles.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
"README.rdoc",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"gitflow.gemspec",
|
24
|
+
"lib/capistrano/gitflow.rb",
|
25
|
+
"lib/capistrano/gitflow/natcmp.rb",
|
26
|
+
"recipes/gitflow_recipes.rb",
|
27
|
+
"spec/gitflow_spec.rb",
|
28
|
+
"spec/spec.opts",
|
29
|
+
"spec/spec_helper.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/technicalpickles/gitflow}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.6}
|
35
|
+
s.summary = %q{Capistrano recipe for a deployment workflow based on git tags}
|
36
|
+
s.test_files = [
|
37
|
+
"spec/gitflow_spec.rb",
|
38
|
+
"spec/spec_helper.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_runtime_dependency(%q<capistrano>, [">= 0"])
|
47
|
+
s.add_runtime_dependency(%q<stringex>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<capistrano>, [">= 0"])
|
51
|
+
s.add_dependency(%q<stringex>, [">= 0"])
|
52
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<capistrano>, [">= 0"])
|
56
|
+
s.add_dependency(%q<stringex>, [">= 0"])
|
57
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,172 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
require 'capistrano/gitflow/natcmp'
|
3
|
+
require 'stringex'
|
4
|
+
|
5
|
+
module Capistrano
|
6
|
+
class Gitflow
|
7
|
+
def self.load_into(capistrano_configuration)
|
8
|
+
capistrano_configuration.load do
|
9
|
+
before "deploy:update_code", "gitflow:calculate_tag"
|
10
|
+
before "gitflow:calculate_tag", "gitflow:verify_up_to_date"
|
11
|
+
|
12
|
+
namespace :gitflow do
|
13
|
+
def last_tag_matching(pattern)
|
14
|
+
matching_tags = `git tag -l '#{pattern}'`.split
|
15
|
+
matching_tags.sort! do |a,b|
|
16
|
+
String.natcmp(b, a, true)
|
17
|
+
end
|
18
|
+
|
19
|
+
last_tag = if matching_tags.length > 0
|
20
|
+
matching_tags[0]
|
21
|
+
else
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def last_staging_tag()
|
27
|
+
last_tag_matching('staging-*')
|
28
|
+
end
|
29
|
+
|
30
|
+
def last_production_tag()
|
31
|
+
last_tag_matching('production-*')
|
32
|
+
end
|
33
|
+
|
34
|
+
task :verify_up_to_date do
|
35
|
+
set :local_branch, `git branch --no-color 2> /dev/null | sed -e '/^[^*]/d'`.gsub(/\* /, '').chomp
|
36
|
+
set :local_sha, `git log --pretty=format:%H HEAD -1`.chomp
|
37
|
+
set :origin_sha, `git log --pretty=format:%H origin/#{local_branch} -1`
|
38
|
+
unless local_sha == origin_sha
|
39
|
+
abort """
|
40
|
+
Your #{local_branch} branch is not up to date with origin/#{local_branch}.
|
41
|
+
Please make sure you have pulled and pushed all code before deploying:
|
42
|
+
|
43
|
+
git pull origin #{local_branch}
|
44
|
+
#run tests, etc
|
45
|
+
git push origin #{local_branch}
|
46
|
+
|
47
|
+
"""
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "Calculate the tag to deploy"
|
52
|
+
task :calculate_tag do
|
53
|
+
# make sure we have any other deployment tags that have been pushed by others so our auto-increment code doesn't create conflicting tags
|
54
|
+
`git fetch`
|
55
|
+
|
56
|
+
send "tag_#{stage}"
|
57
|
+
|
58
|
+
system "git push --tags origin #{local_branch}"
|
59
|
+
if $? != 0
|
60
|
+
abort "git push failed"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "Show log between most recent staging tag (or given tag=XXX) and last production release."
|
65
|
+
task :commit_log do
|
66
|
+
from_tag = if stage == :production
|
67
|
+
last_production_tag
|
68
|
+
elsif stage == :staging
|
69
|
+
last_staging_tag
|
70
|
+
else
|
71
|
+
abort "Unsupported stage #{stage}"
|
72
|
+
end
|
73
|
+
|
74
|
+
# no idea how to properly test for an optional cap argument a la '-s tag=x'
|
75
|
+
to_tag = capistrano_configuration[:tag]
|
76
|
+
to_tag ||= begin
|
77
|
+
puts "Calculating 'end' tag for :commit_log for '#{stage}'"
|
78
|
+
to_tag = if stage == :production
|
79
|
+
last_staging_tag
|
80
|
+
elsif stage == :staging
|
81
|
+
'head'
|
82
|
+
else
|
83
|
+
abort "Unsupported stage #{stage}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
command = if `git config remote.origin.url` =~ /git@github.com:(.*)\/(.*).git/
|
89
|
+
"open https://github.com/#{$1}/#{$2}/compare/#{from_tag}...#{to_tag || 'master'}"
|
90
|
+
else
|
91
|
+
log_subcommand = if ENV['git_log_command'] && ENV['git_log_command'].strip != ''
|
92
|
+
ENV['git_log_command']
|
93
|
+
else
|
94
|
+
'log'
|
95
|
+
end
|
96
|
+
"git #{log_subcommand} #{fromTag}..#{toTag}"
|
97
|
+
end
|
98
|
+
puts command
|
99
|
+
system command
|
100
|
+
end
|
101
|
+
|
102
|
+
desc "Mark the current code as a staging/qa release"
|
103
|
+
task :tag_staging do
|
104
|
+
# find latest staging tag for today
|
105
|
+
new_tag_date = Date.today.to_s
|
106
|
+
new_tag_serial = 1
|
107
|
+
|
108
|
+
who = `whoami`.chomp.to_url
|
109
|
+
what = Capistrano::CLI.ui.ask("What does this release introduce? (this will be normalized and used in the tag for this release) ").to_url
|
110
|
+
|
111
|
+
last_staging_tag = last_tag_matching("staging-#{new_tag_date}.*")
|
112
|
+
if last_staging_tag
|
113
|
+
# calculate largest serial and increment
|
114
|
+
last_staging_tag =~ /staging-[0-9]{4}-[0-9]{2}-[0-9]{2}\-([0-9]*)/
|
115
|
+
new_tag_serial = $1.to_i + 1
|
116
|
+
end
|
117
|
+
|
118
|
+
new_staging_tag = "#{stage}-#{new_tag_date}-#{new_tag_serial}-#{who}-#{what}"
|
119
|
+
|
120
|
+
current_sha = `git log --pretty=format:%H HEAD -1`
|
121
|
+
last_staging_tag_sha = if last_staging_tag
|
122
|
+
`git log --pretty=format:%H #{last_staging_tag} -1`
|
123
|
+
end
|
124
|
+
|
125
|
+
if last_staging_tag_sha == current_sha
|
126
|
+
puts "Not re-tagging staging because the most recent tag (#{last_staging_tag}) already points to current head"
|
127
|
+
new_staging_tag = last_staging_tag
|
128
|
+
else
|
129
|
+
puts "Tagging current branch for deployment to staging as '#{new_staging_tag}'"
|
130
|
+
system "git tag -a -m 'tagging current code for deployment to staging' #{new_staging_tag}"
|
131
|
+
end
|
132
|
+
|
133
|
+
set :branch, new_staging_tag
|
134
|
+
end
|
135
|
+
|
136
|
+
desc "Push the approved tag to production. Pass in tag to deploy with '-s tag=staging-YYYY-MM-DD-X-feature'."
|
137
|
+
task :tag_production do
|
138
|
+
promote_to_production_tag = capistrano_configuration[:tag]
|
139
|
+
|
140
|
+
unless promote_to_production_tag && promote_to_production_tag =~ /staging-.*/
|
141
|
+
abort "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'"
|
142
|
+
end
|
143
|
+
unless last_tag_matching(promote_to_production_tag)
|
144
|
+
abort "Staging tag #{promote_to_production_tag} does not exist."
|
145
|
+
end
|
146
|
+
|
147
|
+
promote_to_production_tag =~ /^staging-(.*)$/
|
148
|
+
new_production_tag = "production-#{$1}"
|
149
|
+
puts "promoting staging tag #{promote_to_production_tag} to production as '#{new_production_tag}'"
|
150
|
+
system "git tag -a -m 'tagging current code for deployment to production' #{new_production_tag} #{promote_to_production_tag}"
|
151
|
+
|
152
|
+
set :branch, new_production_tag
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
namespace :deploy do
|
157
|
+
namespace :pending do
|
158
|
+
task :compare do
|
159
|
+
gitflow.commit_log
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
if Capistrano::Configuration.instance
|
171
|
+
Capistrano::Gitflow.load_into(Capistrano::Configuration.instance)
|
172
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# natcmp.rb
|
2
|
+
#
|
3
|
+
# Natural order comparison of two strings
|
4
|
+
# e.g. "my_prog_v1.1.0" < "my_prog_v1.2.0" < "my_prog_v1.10.0"
|
5
|
+
# which does not follow alphabetically
|
6
|
+
#
|
7
|
+
# Based on Martin Pool's "Natural Order String Comparison" originally written in C
|
8
|
+
# http://sourcefrog.net/projects/natsort/
|
9
|
+
#
|
10
|
+
# This implementation is Copyright (C) 2003 by Alan Davies
|
11
|
+
# <cs96and_AT_yahoo_DOT_co_DOT_uk>
|
12
|
+
#
|
13
|
+
# This software is provided 'as-is', without any express or implied
|
14
|
+
# warranty. In no event will the authors be held liable for any damages
|
15
|
+
# arising from the use of this software.
|
16
|
+
#
|
17
|
+
# Permission is granted to anyone to use this software for any purpose,
|
18
|
+
# including commercial applications, and to alter it and redistribute it
|
19
|
+
# freely, subject to the following restrictions:
|
20
|
+
#
|
21
|
+
# 1. The origin of this software must not be misrepresented; you must not
|
22
|
+
# claim that you wrote the original software. If you use this software
|
23
|
+
# in a product, an acknowledgment in the product documentation would be
|
24
|
+
# appreciated but is not required.
|
25
|
+
# 2. Altered source versions must be plainly marked as such, and must not be
|
26
|
+
# misrepresented as being the original software.
|
27
|
+
# 3. This notice may not be removed or altered from any source distribution.
|
28
|
+
|
29
|
+
class String
|
30
|
+
|
31
|
+
# 'Natural order' comparison of two strings
|
32
|
+
def String.natcmp(str1, str2, caseInsensitive=false)
|
33
|
+
str1, str2 = str1.dup, str2.dup
|
34
|
+
compareExpression = /^(\D*)(\d*)(.*)$/
|
35
|
+
|
36
|
+
if caseInsensitive
|
37
|
+
str1.downcase!
|
38
|
+
str2.downcase!
|
39
|
+
end
|
40
|
+
|
41
|
+
# Remove all whitespace
|
42
|
+
str1.gsub!(/\s*/, '')
|
43
|
+
str2.gsub!(/\s*/, '')
|
44
|
+
|
45
|
+
while (str1.length > 0) or (str2.length > 0) do
|
46
|
+
# Extract non-digits, digits and rest of string
|
47
|
+
str1 =~ compareExpression
|
48
|
+
chars1, num1, str1 = $1.dup, $2.dup, $3.dup
|
49
|
+
|
50
|
+
str2 =~ compareExpression
|
51
|
+
chars2, num2, str2 = $1.dup, $2.dup, $3.dup
|
52
|
+
|
53
|
+
# Compare the non-digits
|
54
|
+
case (chars1 <=> chars2)
|
55
|
+
when 0 # Non-digits are the same, compare the digits...
|
56
|
+
# If either number begins with a zero, then compare alphabetically,
|
57
|
+
# otherwise compare numerically
|
58
|
+
if (num1[0] != 48) and (num2[0] != 48)
|
59
|
+
num1, num2 = num1.to_i, num2.to_i
|
60
|
+
end
|
61
|
+
|
62
|
+
case (num1 <=> num2)
|
63
|
+
when -1 then return -1
|
64
|
+
when 1 then return 1
|
65
|
+
end
|
66
|
+
when -1 then return -1
|
67
|
+
when 1 then return 1
|
68
|
+
end # case
|
69
|
+
|
70
|
+
end # while
|
71
|
+
|
72
|
+
# Strings are naturally equal
|
73
|
+
return 0
|
74
|
+
end
|
75
|
+
|
76
|
+
end # class String
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-gitflow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 1.3.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Joshua Nichols
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-06-15 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: capistrano
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: stringex
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: rspec
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 1
|
53
|
+
- 2
|
54
|
+
- 9
|
55
|
+
version: 1.2.9
|
56
|
+
type: :development
|
57
|
+
version_requirements: *id003
|
58
|
+
description: Capistrano recipe for a deployment workflow based on git tags
|
59
|
+
email: josh@technicalpickles.com
|
60
|
+
executables: []
|
61
|
+
|
62
|
+
extensions: []
|
63
|
+
|
64
|
+
extra_rdoc_files:
|
65
|
+
- README.rdoc
|
66
|
+
files:
|
67
|
+
- .document
|
68
|
+
- README.rdoc
|
69
|
+
- Rakefile
|
70
|
+
- VERSION
|
71
|
+
- capistrano-gitflow.gemspec
|
72
|
+
- gitflow.gemspec
|
73
|
+
- lib/capistrano/gitflow.rb
|
74
|
+
- lib/capistrano/gitflow/natcmp.rb
|
75
|
+
- recipes/gitflow_recipes.rb
|
76
|
+
- spec/gitflow_spec.rb
|
77
|
+
- spec/spec.opts
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
has_rdoc: true
|
80
|
+
homepage: http://github.com/technicalpickles/gitflow
|
81
|
+
licenses: []
|
82
|
+
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options:
|
85
|
+
- --charset=UTF-8
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
requirements: []
|
103
|
+
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 1.3.6
|
106
|
+
signing_key:
|
107
|
+
specification_version: 3
|
108
|
+
summary: Capistrano recipe for a deployment workflow based on git tags
|
109
|
+
test_files:
|
110
|
+
- spec/gitflow_spec.rb
|
111
|
+
- spec/spec_helper.rb
|