factorylabs-auto_tagger 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +6 -0
- data/.gitignore +6 -0
- data/CHANGELOG +30 -0
- data/MIT-LICENSE +20 -0
- data/README.md +176 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/auto_tagger.gemspec +83 -0
- data/bin/autotag +38 -0
- data/features/autotag.feature +39 -0
- data/features/deployment.feature +29 -0
- data/features/step_definitions/autotag_steps.rb +41 -0
- data/features/step_definitions/deployment_steps.rb +53 -0
- data/features/support/env.rb +8 -0
- data/features/support/step_helpers.rb +136 -0
- data/features/templates/cap_ext_deploy.erb +32 -0
- data/features/templates/deploy.erb +34 -0
- data/features/templates/stage.erb +1 -0
- data/geminstaller.yml +7 -0
- data/lib/auto_tagger.rb +10 -0
- data/lib/auto_tagger/auto_tagger.rb +26 -0
- data/lib/auto_tagger/capistrano_helper.rb +39 -0
- data/lib/auto_tagger/commander.rb +15 -0
- data/lib/auto_tagger/recipes.rb +54 -0
- data/lib/auto_tagger/repository.rb +42 -0
- data/lib/auto_tagger/stage_manager.rb +23 -0
- data/lib/auto_tagger/tag.rb +41 -0
- data/spec/auto_tagger/auto_tagger_spec.rb +85 -0
- data/spec/auto_tagger/capistrano_helper_spec.rb +146 -0
- data/spec/auto_tagger/commander_spec.rb +17 -0
- data/spec/auto_tagger/repository_spec.rb +72 -0
- data/spec/auto_tagger/stage_manager_spec.rb +34 -0
- data/spec/auto_tagger/tag_spec.rb +66 -0
- data/spec/spec_helper.rb +7 -0
- metadata +116 -0
data/.document
ADDED
data/.gitignore
ADDED
data/CHANGELOG
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
2009-10-15
|
2
|
+
|
3
|
+
- You can now define your stages as strings or symbols and auto-tagger will not fail (thanks to Chad Wooley for the bug report)
|
4
|
+
- When deploying from a branch auto_tagger uses real_revision, not the previous tag, to create the new tag (Brian Takita)
|
5
|
+
|
6
|
+
2009-04-30
|
7
|
+
|
8
|
+
- Fixed bug whereby auto-tagger would use the wrong tag because it found tags that had similar names to what it uses.
|
9
|
+
|
10
|
+
2009-04-20
|
11
|
+
|
12
|
+
- `release_tagger:create_tag` creates a production tag if you don't set any stages
|
13
|
+
|
14
|
+
2009-04-05
|
15
|
+
|
16
|
+
- Added basic support for cap-ext-multistage
|
17
|
+
- Changed "stages" variable to "autotagger_stages" so as not to conflict with the multistage "stages" variable in capistrano
|
18
|
+
- Changed the :current_stage variable in the capistrano tasks to just :stage
|
19
|
+
|
20
|
+
2009-03-31
|
21
|
+
|
22
|
+
- Capistrano bases new tags off of old tags from the previous environment when tagging if there is a tag from the previous environment
|
23
|
+
- Added the following cap tasks:
|
24
|
+
- print_latest_tags
|
25
|
+
- read_tag_from_shared
|
26
|
+
- write_tag_to_shared
|
27
|
+
|
28
|
+
2009-03-29
|
29
|
+
|
30
|
+
- Capistrano tasks :set_branch no longer sets the branch to nil. If the CapistranoHelper returns nil, it leaves the branch alone.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 [Jeff Dean]
|
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.md
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
# IMPORTANT NOTE
|
2
|
+
|
3
|
+
This gem is still in it's infancy, and lots of things might change. Since this creates and pushes tags to your git repository, please use with caution.
|
4
|
+
|
5
|
+
# AutoTagger
|
6
|
+
|
7
|
+
AutoTagger is a gem that helps you automatically create a date-stamped tag for each stage of your deployment, and deploy from the last tag from the previous environment.
|
8
|
+
|
9
|
+
Let's say you have the following workflow:
|
10
|
+
|
11
|
+
* Run all test on a Continuous Integration (CI) server
|
12
|
+
* Deploy to a staging server
|
13
|
+
* Deploy to a production server
|
14
|
+
|
15
|
+
You can use the `autotag` command to tag releases on your CI box, then use the capistrano tasks to auto-tag each release.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
sudo gem install auto_tagger
|
20
|
+
|
21
|
+
## Contribute
|
22
|
+
|
23
|
+
* [GitHub Repository](http://github.com/zilkey/auto_tagger/tree/master)
|
24
|
+
|
25
|
+
## The autotag executable
|
26
|
+
|
27
|
+
Installing the gem creates an executable file named autotag, which takes two arguments: the stage, and optionally the path to the git repo:
|
28
|
+
|
29
|
+
$ autotag demo # => creates a tag like demo/200804041234 in the current directory
|
30
|
+
$ autotag demo . # => same as above
|
31
|
+
$ autotag demo /Users/me/foo # => cd's to /Users/me/foo before creating the tag
|
32
|
+
|
33
|
+
Running autotag does the following:
|
34
|
+
|
35
|
+
$ git fetch origin --tags
|
36
|
+
$ git tag <stage>/<timestamp>
|
37
|
+
$ git push origin --tags
|
38
|
+
|
39
|
+
## Capistrano Integration
|
40
|
+
|
41
|
+
AutoTagger comes with 2 capistrano tasks:
|
42
|
+
|
43
|
+
* `release_tagger:set_branch` tries to set the branch to the last tag from the previous environment.
|
44
|
+
* `release_tagger:create_tag` runs autotag for the current stage
|
45
|
+
|
46
|
+
Example `config/deploy.rb` file:
|
47
|
+
|
48
|
+
require 'release_tagger'
|
49
|
+
|
50
|
+
# The :autotagger_stages variable is required
|
51
|
+
set :autotagger_stages, [:ci, :staging, :production]
|
52
|
+
|
53
|
+
# The :working_directory variable is optional, and defaults to Dir.pwd
|
54
|
+
# :working_directory can be an absolute or relative path
|
55
|
+
set :working_directory, "../../"
|
56
|
+
|
57
|
+
task :production do
|
58
|
+
# In each of your environments that need auto-branch setting, you need to set :stage
|
59
|
+
set :stage, :production
|
60
|
+
end
|
61
|
+
|
62
|
+
task :staging do
|
63
|
+
# If you do not set stage, it will not auto-set your branch
|
64
|
+
# set :stage, :staging
|
65
|
+
end
|
66
|
+
|
67
|
+
# You need to add the before/ater callbacks yourself
|
68
|
+
before "deploy:update_code", "release_tagger:set_branch"
|
69
|
+
after "deploy", "release_tagger:create_tag"
|
70
|
+
after "deploy", "release_tagger:write_tag_to_shared"
|
71
|
+
after "deploy", "release_tagger:print_latest_tags"
|
72
|
+
|
73
|
+
### Cpistano-ext multistage support
|
74
|
+
|
75
|
+
If you use capistano-ext multistage, you can use auto_tagger.
|
76
|
+
|
77
|
+
set :autotagger_stages, [:ci, :staging, :production]
|
78
|
+
set :stages, [:staging, :production]
|
79
|
+
set :default_stage, :staging
|
80
|
+
require 'capistrano/ext/multistage'
|
81
|
+
|
82
|
+
When you deploy, autotagger will auto-detect your current stage.
|
83
|
+
|
84
|
+
### release_tagger:set_branch
|
85
|
+
|
86
|
+
This task sets the git branch to the latest tag from the previous stage. Assume you have the following tags in your git repository:
|
87
|
+
|
88
|
+
* ci/01
|
89
|
+
* staging/01
|
90
|
+
* production/01
|
91
|
+
|
92
|
+
And the following stages in your capistrano file:
|
93
|
+
|
94
|
+
set :autotagger_stages, [:ci, :staging, :production]
|
95
|
+
|
96
|
+
The deployments would look like this:
|
97
|
+
|
98
|
+
cap staging release_tagger:set_branch # => sets branch to ci/01
|
99
|
+
cap production release_tagger:set_branch # => sets branch to staging/01
|
100
|
+
|
101
|
+
You can override with with the -Shead and -Stag options
|
102
|
+
|
103
|
+
cap staging release_tagger:set_branch -Shead=true # => sets branch to master
|
104
|
+
cap staging release_tagger:set_branch -Stag=staging/01 # => sets branch to staging/01
|
105
|
+
|
106
|
+
If you add `before "deploy:update_code", "release_tagger:set_branch"`, you can just deploy with:
|
107
|
+
|
108
|
+
cap staging deploy
|
109
|
+
|
110
|
+
and the branch will be set for you automatically.
|
111
|
+
|
112
|
+
### release_tagger:create_tag
|
113
|
+
|
114
|
+
This cap task creates a new tag, based on the latest tag from the previous environment.
|
115
|
+
|
116
|
+
If there is no tag from the previous stage, it creates a new tag from the latest commit in your _working directory_.
|
117
|
+
|
118
|
+
If you don't specify any `autotagger_stages`, autotagger will create a tag that starts with "production".
|
119
|
+
|
120
|
+
### release_tagger:print_latest_tags
|
121
|
+
|
122
|
+
This task reads the git version from the text file in shared:
|
123
|
+
|
124
|
+
cap staging release_tagger:read_tag_from_shared
|
125
|
+
|
126
|
+
### release_tagger:print_latest_tags
|
127
|
+
|
128
|
+
This task takes the latest tag from each environment and prints it to the screen. You can add it to your deploy.rb like so:
|
129
|
+
|
130
|
+
after "deploy", "release_tagger:print_latest_tags"
|
131
|
+
|
132
|
+
Or call it directly, like:
|
133
|
+
|
134
|
+
cap production release_tagger:print_latest_tags
|
135
|
+
|
136
|
+
This will produce output like:
|
137
|
+
|
138
|
+
** AUTO TAGGER: release tag history is:
|
139
|
+
** ci ci/20090331045345 8031807feb5f4f99dd83257cdc07081fa6080cba some commit message
|
140
|
+
** staging staging/20090331050908 8031807feb5f4f99dd83257cdc07081fa6080cba some commit message
|
141
|
+
** production production/20090331050917 8031807feb5f4f99dd83257cdc07081fa6080cba some commit message
|
142
|
+
|
143
|
+
## Running tests:
|
144
|
+
|
145
|
+
You must be able to ssh into your box via localhost (remote login). To make this easier, add your own key to your own account:
|
146
|
+
|
147
|
+
cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys
|
148
|
+
|
149
|
+
To ensure that this has worked, try this:
|
150
|
+
|
151
|
+
ssh localhost
|
152
|
+
|
153
|
+
If it asks you for a password, you've done something wrong.
|
154
|
+
|
155
|
+
To run the specs, execute:
|
156
|
+
|
157
|
+
spec spec/
|
158
|
+
|
159
|
+
To run the cucumber features, execute:
|
160
|
+
|
161
|
+
cucumber features/
|
162
|
+
|
163
|
+
## Acknowledgments
|
164
|
+
|
165
|
+
Special thanks to
|
166
|
+
|
167
|
+
* Brian Takita for the original recipes
|
168
|
+
* Mike Dalessio for his git fu
|
169
|
+
* Chad Wooley for his feature ideas
|
170
|
+
* Tim Holahan for his QA
|
171
|
+
|
172
|
+
## Links
|
173
|
+
|
174
|
+
* http://codeintensity.blogspot.com/2008/06/changelogs-and-deployment-notification.html
|
175
|
+
|
176
|
+
Copyright (c) 2009 [Jeff Dean], released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "factorylabs-auto_tagger"
|
8
|
+
gem.summary = %Q{Helps you automatically create tags for each stage in a multi-stage deploment and deploy from the latest tag from the previous environment}
|
9
|
+
gem.email = "jeff@zilkey.com"
|
10
|
+
gem.homepage = "http://github.com/zilkey/auto_tagger"
|
11
|
+
gem.authors = ["Jeff Dean", "Brian Takita", "Mike Grafton"]
|
12
|
+
gem.add_dependency('capistrano', [">= 2.5.3"])
|
13
|
+
gem.require_paths = ["lib"]
|
14
|
+
gem.executables = ["autotag"]
|
15
|
+
gem.default_executable = %q{autotag}
|
16
|
+
gem.date = %q{2009-03-28}
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo 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
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "the-perfect-gem #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/auto_tagger.gemspec
ADDED
@@ -0,0 +1,83 @@
|
|
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{auto_tagger}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jeff Dean", "Brian Takita", "Mike Grafton"]
|
12
|
+
s.date = %q{2010-04-06}
|
13
|
+
s.default_executable = %q{autotag}
|
14
|
+
s.email = %q{jeff@zilkey.com}
|
15
|
+
s.executables = ["autotag"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"CHANGELOG",
|
23
|
+
"MIT-LICENSE",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"auto_tagger.gemspec",
|
28
|
+
"bin/autotag",
|
29
|
+
"features/autotag.feature",
|
30
|
+
"features/deployment.feature",
|
31
|
+
"features/step_definitions/autotag_steps.rb",
|
32
|
+
"features/step_definitions/deployment_steps.rb",
|
33
|
+
"features/support/env.rb",
|
34
|
+
"features/support/step_helpers.rb",
|
35
|
+
"features/templates/cap_ext_deploy.erb",
|
36
|
+
"features/templates/deploy.erb",
|
37
|
+
"features/templates/stage.erb",
|
38
|
+
"geminstaller.yml",
|
39
|
+
"lib/auto_tagger.rb",
|
40
|
+
"lib/auto_tagger/auto_tagger.rb",
|
41
|
+
"lib/auto_tagger/capistrano_helper.rb",
|
42
|
+
"lib/auto_tagger/commander.rb",
|
43
|
+
"lib/auto_tagger/recipes.rb",
|
44
|
+
"lib/auto_tagger/repository.rb",
|
45
|
+
"lib/auto_tagger/stage_manager.rb",
|
46
|
+
"lib/auto_tagger/tag.rb",
|
47
|
+
"spec/auto_tagger/auto_tagger_spec.rb",
|
48
|
+
"spec/auto_tagger/capistrano_helper_spec.rb",
|
49
|
+
"spec/auto_tagger/commander_spec.rb",
|
50
|
+
"spec/auto_tagger/repository_spec.rb",
|
51
|
+
"spec/auto_tagger/stage_manager_spec.rb",
|
52
|
+
"spec/auto_tagger/tag_spec.rb",
|
53
|
+
"spec/spec_helper.rb"
|
54
|
+
]
|
55
|
+
s.homepage = %q{http://github.com/zilkey/auto_tagger}
|
56
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
57
|
+
s.require_paths = ["lib"]
|
58
|
+
s.rubygems_version = %q{1.3.6}
|
59
|
+
s.summary = %q{Helps you automatically create tags for each stage in a multi-stage deploment and deploy from the latest tag from the previous environment}
|
60
|
+
s.test_files = [
|
61
|
+
"spec/auto_tagger/auto_tagger_spec.rb",
|
62
|
+
"spec/auto_tagger/capistrano_helper_spec.rb",
|
63
|
+
"spec/auto_tagger/commander_spec.rb",
|
64
|
+
"spec/auto_tagger/repository_spec.rb",
|
65
|
+
"spec/auto_tagger/stage_manager_spec.rb",
|
66
|
+
"spec/auto_tagger/tag_spec.rb",
|
67
|
+
"spec/spec_helper.rb"
|
68
|
+
]
|
69
|
+
|
70
|
+
if s.respond_to? :specification_version then
|
71
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
72
|
+
s.specification_version = 3
|
73
|
+
|
74
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
75
|
+
s.add_runtime_dependency(%q<capistrano>, [">= 2.5.3"])
|
76
|
+
else
|
77
|
+
s.add_dependency(%q<capistrano>, [">= 2.5.3"])
|
78
|
+
end
|
79
|
+
else
|
80
|
+
s.add_dependency(%q<capistrano>, [">= 2.5.3"])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
data/bin/autotag
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "auto_tagger"))
|
3
|
+
require 'getoptlong'
|
4
|
+
|
5
|
+
opts = GetoptLong.new(
|
6
|
+
['--help', '-h', '-?', GetoptLong::NO_ARGUMENT]
|
7
|
+
)
|
8
|
+
|
9
|
+
def usage
|
10
|
+
puts
|
11
|
+
puts "USAGE: #{File.basename($0)} <stage> [<repository>]"
|
12
|
+
puts
|
13
|
+
puts ' where: stage sets the tag prefix'
|
14
|
+
puts ' repository sets the repository to act on - defualts to the current directory'
|
15
|
+
puts
|
16
|
+
puts ' examples: autotag'
|
17
|
+
puts ' autotag .'
|
18
|
+
puts ' autotag ../'
|
19
|
+
puts ' autotag /data/myrepo'
|
20
|
+
puts ' autotag demo'
|
21
|
+
puts
|
22
|
+
puts
|
23
|
+
exit 0
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.each do |opt, arg|
|
27
|
+
case opt
|
28
|
+
when "--help"
|
29
|
+
usage
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
if ARGV[0]
|
34
|
+
AutoTagger.new(ARGV[0], ARGV[1]).create_tag
|
35
|
+
exit 0
|
36
|
+
else
|
37
|
+
usage
|
38
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
Feature: Deployment
|
2
|
+
In order to get auto-tagging goodness on ci boxes
|
3
|
+
As a ruby and git ninja
|
4
|
+
I want to be able to easily create a tag from the command line with the same name format as the one created by the cap tasks
|
5
|
+
|
6
|
+
Scenario: user runs autotag with no args
|
7
|
+
Given a repo
|
8
|
+
When I run autotag with no arguments
|
9
|
+
Then I should see "USAGE:"
|
10
|
+
And no tags should be created
|
11
|
+
|
12
|
+
Scenario: user runs autotag with "--help"
|
13
|
+
Given a repo
|
14
|
+
When I run autotag with "--help"
|
15
|
+
Then I should see "USAGE:"
|
16
|
+
And no tags should be created
|
17
|
+
|
18
|
+
Scenario: user runs autotag with "-h"
|
19
|
+
Given a repo
|
20
|
+
When I run autotag with "-h"
|
21
|
+
Then I should see "USAGE:"
|
22
|
+
And no tags should be created
|
23
|
+
|
24
|
+
Scenario: user runs autotag with "-?"
|
25
|
+
Given a repo
|
26
|
+
When I run autotag with "-?"
|
27
|
+
Then I should see "USAGE:"
|
28
|
+
And no tags should be created
|
29
|
+
|
30
|
+
Scenario: user runs autotag with "demo"
|
31
|
+
Given a repo
|
32
|
+
When I run autotag with "demo"
|
33
|
+
# can't check output here for some reason
|
34
|
+
Then a "demo" tag should be created
|
35
|
+
|
36
|
+
Scenario: user runs autotag with "demo ."
|
37
|
+
Given a repo
|
38
|
+
When I run autotag with "demo"
|
39
|
+
Then a "demo" tag should be created
|