stuzo-recipes 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README +1 -0
- data/README.rdoc +18 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/lib/git-deployment/README +45 -0
- data/lib/git-deployment/VERSION +1 -0
- data/lib/git-deployment/gitflow.rb +88 -0
- data/lib/git-deployment/natcmp.rb +76 -0
- data/lib/stuzo-recipes.rb +0 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/stuzo-recipes_spec.rb +7 -0
- metadata +81 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 mcfearsome
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
This will be the home of many tasty recipes.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= stuzo-recipes
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 mcfearsome. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "stuzo-recipes"
|
8
|
+
gem.summary = %Q{Tasty Capistrano and Rake recipes for use in php projects at Stuzo Group}
|
9
|
+
gem.description = %Q{Tasty Capistrano and Rake recipes for use in php projects at Stuzo Group}
|
10
|
+
gem.email = "jesse@stuzo.com"
|
11
|
+
gem.homepage = "http://github.com/stuzo/stuzo-recipes"
|
12
|
+
gem.authors = ["Jesse McPherson"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
# require 'spec/rake/spectask'
|
22
|
+
# Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
# spec.libs << 'lib' << 'spec'
|
24
|
+
# spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
# spec.libs << 'lib' << 'spec'
|
29
|
+
# spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
# spec.rcov = true
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# task :spec => :check_dependencies
|
34
|
+
#
|
35
|
+
# task :default => :spec
|
36
|
+
#
|
37
|
+
# require 'rake/rdoctask'
|
38
|
+
# Rake::RDocTask.new do |rdoc|
|
39
|
+
# version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
#
|
41
|
+
# rdoc.rdoc_dir = 'rdoc'
|
42
|
+
# rdoc.title = "stuzo-recipes #{version}"
|
43
|
+
# rdoc.rdoc_files.include('README*')
|
44
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
# end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,45 @@
|
|
1
|
+
A Capistrano recipe for git deployment via tags.
|
2
|
+
|
3
|
+
After experimenting with several workflows for deployment in git, I've finally found one I really like.
|
4
|
+
|
5
|
+
You can push to staging at any time; every staging push is automatically tagged with a unique tag.
|
6
|
+
You can only push a staging tag to production. This helps to enforce QA of all pushes to production.
|
7
|
+
|
8
|
+
Requires the cap multistage extension:
|
9
|
+
gem install capistrano capistrano-ext
|
10
|
+
|
11
|
+
NOTE: it'd be cool to package this up as a gem to make installation easier; don't know how at the moment. just clone the code...
|
12
|
+
|
13
|
+
INSTALLATION: require the gitflow file after your multistage require
|
14
|
+
require 'capistrano/ext/multistage'
|
15
|
+
require 'git-deployment/gitflow.rb'
|
16
|
+
|
17
|
+
Expects stages "staging" and "production".
|
18
|
+
|
19
|
+
USE:
|
20
|
+
|
21
|
+
PUSH TO STAGING:
|
22
|
+
Whenever you want to push the currently checked-out code to staging, just do:
|
23
|
+
|
24
|
+
cap staging deploy
|
25
|
+
|
26
|
+
gitflow will automatically:
|
27
|
+
- create a unique tag in the format of 'staging-YYYY-MM-DD.X'
|
28
|
+
- configure multistage to use that tag for the deploy
|
29
|
+
- push the code and tags to the remote "origin"
|
30
|
+
- and run the normal deploy task for the staging stage.
|
31
|
+
|
32
|
+
PUSH TO PRODUCTION:
|
33
|
+
Whenever you want to push code to production, you must specify the staging tag you wish to promote to production:
|
34
|
+
|
35
|
+
cap production deploy -s tag=staging-2009-09-08.2
|
36
|
+
|
37
|
+
gitflow will automatically:
|
38
|
+
- alias the staging tag to a production tag like: production-2008-09-08.2
|
39
|
+
- configure multistage to use that tag for the deploy
|
40
|
+
- push the code and tags to the remote "origin"
|
41
|
+
- and run the normal deploy task for the production stage.
|
42
|
+
|
43
|
+
NOTES:
|
44
|
+
- 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
|
45
|
+
- if your stages already have a "set :branch, 'my-staging-branch'" call in your configs, remove it. This workflow configures it automatically.
|
@@ -0,0 +1 @@
|
|
1
|
+
1.2
|
@@ -0,0 +1,88 @@
|
|
1
|
+
Capistrano::Configuration.instance(true).load do
|
2
|
+
before "deploy:update_code", "gitflow:calculate_tag"
|
3
|
+
namespace :gitflow do
|
4
|
+
desc "Calculate the tag to deploy"
|
5
|
+
task :calculate_tag do
|
6
|
+
# make sure we have any other deployment tags that have been pushed by others so our auto-increment code doesn't create conflicting tags
|
7
|
+
`git fetch`
|
8
|
+
|
9
|
+
tagMethod = "tag_#{stage}"
|
10
|
+
send tagMethod
|
11
|
+
|
12
|
+
# push tags and latest code
|
13
|
+
system 'git push'
|
14
|
+
if $? != 0
|
15
|
+
raise "git push failed"
|
16
|
+
end
|
17
|
+
system 'git push --tags'
|
18
|
+
if $? != 0
|
19
|
+
raise "git push --tags failed"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Mark the current code as a staging/qa release"
|
24
|
+
task :tag_staging do
|
25
|
+
# find latest staging tag for today
|
26
|
+
newTagDate = Date.today.to_s
|
27
|
+
newTagSerial = 1
|
28
|
+
|
29
|
+
todaysStagingTags = `git tag -l 'staging-#{newTagDate}.*'`
|
30
|
+
todaysStagingTags = todaysStagingTags.split
|
31
|
+
|
32
|
+
natcmpSrc = File.join(File.dirname(__FILE__), '/natcmp.rb')
|
33
|
+
require natcmpSrc
|
34
|
+
todaysStagingTags.sort! do |a,b|
|
35
|
+
String.natcmp(b,a,true)
|
36
|
+
end
|
37
|
+
|
38
|
+
lastStagingTag = nil
|
39
|
+
if todaysStagingTags.length > 0
|
40
|
+
lastStagingTag = todaysStagingTags[0]
|
41
|
+
|
42
|
+
# calculate largest serial and increment
|
43
|
+
lastStagingTag =~ /staging-[0-9]{4}-[0-9]{2}-[0-9]{2}\.([0-9]*)/
|
44
|
+
newTagSerial = $1.to_i + 1
|
45
|
+
end
|
46
|
+
newStagingTag = "staging-#{newTagDate}.#{newTagSerial}"
|
47
|
+
|
48
|
+
shaOfCurrentCheckout = `git log --format=format:%H HEAD -1`
|
49
|
+
shaOfLastStagingTag = nil
|
50
|
+
if lastStagingTag
|
51
|
+
shaOfLastStagingTag = `git log --format=format:%H #{lastStagingTag} -1`
|
52
|
+
end
|
53
|
+
|
54
|
+
if shaOfLastStagingTag == shaOfCurrentCheckout
|
55
|
+
puts "Not re-tagging staging because the most recent tag (#{lastStagingTag}) already points to current head"
|
56
|
+
newStagingTag = lastStagingTag
|
57
|
+
else
|
58
|
+
puts "Tagging current branch for deployment to staging as '#{newStagingTag}'"
|
59
|
+
system "git tag -a -m 'tagging current code for deployment to staging' #{newStagingTag}"
|
60
|
+
end
|
61
|
+
|
62
|
+
set :branch, newStagingTag
|
63
|
+
end
|
64
|
+
|
65
|
+
desc "Push the passed staging tag to production. Pass in tag to deploy with '-s tag=staging-YYYY-MM-DD.X'."
|
66
|
+
task :tag_production do
|
67
|
+
if !exists? :tag
|
68
|
+
raise "staging tag required; use '-s tag=staging-YYYY-MM-DD.X'"
|
69
|
+
end
|
70
|
+
|
71
|
+
# get list of staging tags
|
72
|
+
todaysStagingTags = `git tag -l 'staging-*' | sort -rn`
|
73
|
+
todaysStagingTags = todaysStagingTags.split
|
74
|
+
|
75
|
+
|
76
|
+
if !todaysStagingTags.include? tag
|
77
|
+
raise "Staging Tag #{tag} does not exist."
|
78
|
+
end
|
79
|
+
|
80
|
+
tag =~ /staging-([0-9]{4}-[0-9]{2}-[0-9]{2}\.[0-9]*)/
|
81
|
+
newProductionTag = "production-#{$1}"
|
82
|
+
puts "promoting staging tag #{tag} to production as '#{newProductionTag}'"
|
83
|
+
system "git tag -a -m 'tagging current code for deployment to production' #{newProductionTag} #{tag}"
|
84
|
+
|
85
|
+
set :branch, newProductionTag
|
86
|
+
end
|
87
|
+
end
|
88
|
+
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
|
File without changes
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stuzo-recipes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jesse McPherson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-24 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
25
|
+
description: Tasty Capistrano and Rake recipes for use in php projects at Stuzo Group
|
26
|
+
email: jesse@stuzo.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README
|
34
|
+
- README.rdoc
|
35
|
+
files:
|
36
|
+
- .document
|
37
|
+
- .gitignore
|
38
|
+
- LICENSE
|
39
|
+
- README
|
40
|
+
- README.rdoc
|
41
|
+
- Rakefile
|
42
|
+
- VERSION
|
43
|
+
- lib/git-deployment/README
|
44
|
+
- lib/git-deployment/VERSION
|
45
|
+
- lib/git-deployment/gitflow.rb
|
46
|
+
- lib/git-deployment/natcmp.rb
|
47
|
+
- lib/stuzo-recipes.rb
|
48
|
+
- spec/spec.opts
|
49
|
+
- spec/spec_helper.rb
|
50
|
+
- spec/stuzo-recipes_spec.rb
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://github.com/stuzo/stuzo-recipes
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options:
|
57
|
+
- --charset=UTF-8
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.3.5
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Tasty Capistrano and Rake recipes for use in php projects at Stuzo Group
|
79
|
+
test_files:
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
- spec/stuzo-recipes_spec.rb
|