capistrano-tbg 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3-p194
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-tbg.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Vincent Siebert
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Capistrano::Tbg
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano-tbg'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capistrano-tbg
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
File without changes
@@ -0,0 +1,101 @@
1
+ namespace :deploy do
2
+ namespace :automation do
3
+ desc "Get all referenced pivotal tracker stories"
4
+ task :create_changelog, [:message] => :environment do |t, args|
5
+
6
+ changelog_location = "#{Rails.root}/CHANGELOG.md"
7
+ changelog = {:features => [], :bugs => []}
8
+ # get current repo
9
+ repo = Grit::Repo.new Rails.root
10
+ # last release
11
+ # last_rel = "REL-2012-06-12_10-38-04"
12
+ last_rel = repo.git.describe({'abbrev' => 0, 'tags' => true, 'match' => 'REL-*'}).gsub!("\n","")
13
+ p "LAST RELEASE: #{last_rel}"
14
+ # validate
15
+ raise "Could not find previous release tag" unless last_rel
16
+
17
+ # lets tag the new release
18
+ time = Time.new
19
+ tag_name = time.to_formatted_s :release_tag
20
+ repo.git.tag({ 'a' => true, 'm' => "creating release tag for #{tag_name}"}, tag_name)
21
+ repo.git.push({'tags' => true})
22
+
23
+ # current release
24
+ cur_rel = repo.git.describe({'abbrev' => 0, 'tags' => true, 'match' => 'REL-*'}).gsub!("\n","")
25
+ p "CURRENT RELEASE: #{cur_rel}"
26
+ # validate
27
+ raise "Could not find latest release tag" unless cur_rel
28
+ # Now lets get all the commit messages with PT story references
29
+ commits = repo.git.log({'grep' => "\[[ a-z]*[ ]*#[0-9]+[ ]*\]", 'E' => true, 'i' => true, 'format' => 'format:%s'}, "#{last_rel}...#{cur_rel}")
30
+ p commits
31
+ # Only if we have commit do we need to carry on
32
+ if not commits.blank?
33
+ # Lets extract the sory references
34
+ story_ids = commits.scan(/\[[ a-z]*[ ]*#([0-9]+)[ ]*\]/).flatten!.uniq
35
+ p story_ids
36
+ # Pivotal Tracker
37
+ accepted_status = [:started, :finished, :delivered, :accepted]
38
+ # Manually set API Token
39
+ PivotalTracker::Client.token = Rails.application.config.pivotal_tracker_token
40
+ # return all projects
41
+ projects = PivotalTracker::Project.all
42
+ # We need to order the projects by the likelyhood of stories being contained within them to speed up the process
43
+ projects = projects.sort { |p1, p2| p2.last_activity_at <=> p1.last_activity_at }
44
+ projects.map do |project|
45
+ break unless story_ids
46
+ p "checking project #{project.name} for stories"
47
+ story_ids.each do |id|
48
+ story = project.stories.find id
49
+ if story
50
+ if accepted_status.include? story.current_state.to_sym
51
+ if story.story_type == "feature"
52
+ changelog[:features] << story.name
53
+ story.update :current_state => :accepted
54
+ elsif story.story_type == "bug"
55
+ changelog[:bugs] << story.name
56
+ story.update :current_state => :accepted
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ # Now lets assemble the changelog
63
+ head = "\n## Release #{tag_name}\nPlease find all changes below.\n"
64
+ # assemble the features
65
+ features = "\n### New features deployed:\n"
66
+ if changelog[:features]
67
+ changelog[:features].each do |feature|
68
+ features << "* #{feature}\n"
69
+ end
70
+ else
71
+ features << "**No new features deployed**\n"
72
+ end
73
+ # Assemble the bug fixes
74
+ bugs = "\n### Bug fixes deployed:\n"
75
+ if changelog[:bugs]
76
+ changelog[:bugs].each do |bug|
77
+ bugs << "* #{bug}\n"
78
+ end
79
+ else
80
+ bugs << "**No bug fixes deployed**\n"
81
+ end
82
+ # Write the changelog to the changelog file
83
+ open(changelog_location, 'a') do |f|
84
+ f << head
85
+ f << features
86
+ f << bugs
87
+ end
88
+ # And commit them to the remote
89
+ # p changelog_location
90
+ repo.git.add({}, changelog_location)
91
+ c = repo.git.commit({'m' => "updating changelog for release #{tag_name}"}, changelog_location).scan(/^\[(\w+)[\s]{1}([a-zA-Z0-9]+)\]/).flatten
92
+ if c.first and c.last
93
+ repo.git.push({}, "origin #{c.last}:#{c.first}")
94
+ end
95
+ else
96
+ p "No commits with story references identified"
97
+ end
98
+ end
99
+ end
100
+ end
101
+
@@ -0,0 +1,23 @@
1
+ namespace :scm do
2
+ Time::DATE_FORMATS[:release_tag] = "REL-%Y-%m-%d_%H-%M-%S"
3
+ namespace :git do
4
+ desc "create git tag"
5
+ task :tag_release do
6
+ repo = Grit::Repo.new Rails.root
7
+ time = Time.new
8
+ tag_name = time.to_formatted_s :release_tag
9
+ repo.git.tag({ 'a' => true, 'm' => "creating release tag for #{tag_name}"}, tag_name)
10
+ repo.git.push({'tags' => true})
11
+ end
12
+
13
+ desc "get two release tags"
14
+ task :latest_release_tag do
15
+ # First we need to setup the repo
16
+ repo = Grit::Repo.new Rails.root
17
+ # lets retrive the latest release tag
18
+ last_rel_tag = repo.git.describe({'abbrev' => 0, 'tags' => true, 'match' => 'REL-*'}).gsub!("\n","")
19
+ p Grit::Tag.find_all repo
20
+ end
21
+
22
+ end
23
+ end
data/lib/tbg.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "tbg/version"
2
+
3
+ module Capistrano
4
+ module Tbg
5
+ Dir["tasks/**/*.rake"].each { |ext| load ext } if defined?(Rake)
6
+ # Your code goes here...
7
+ end
8
+ end
data/lib/tbg/base.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'capistrano/tbg/common'
2
+
3
+ unless Capistrano::Configuration.respond_to?(:instance)
4
+ abort "capistrano/tbg/deploy requires Capistrano 2"
5
+ end
6
+
7
+ Capistrano::Configuration.instance.load do
8
+ # User details
9
+ _cset :user, 'deploy'
10
+ _cset(:group) { user }
11
+
12
+ # Application details
13
+ _cset(:app_name) { abort "Please specify the short name of your application, set :app_name, 'foo'" }
14
+ _cset(:application) { app_name }
15
+ _cset(:runner) { user }
16
+ _cset :use_sudo, false
17
+
18
+ # SCM settings
19
+ _cset(:app_dir) { "/home/#{user}/deployments/#{application}" }
20
+ _cset :scm, 'git'
21
+ _cset(:repository) { "git@github.com:thebeansgroup/#{app_name}.git" }
22
+ _cset :branch, 'master'
23
+ _cset :deploy_via, 'remote_cache'
24
+ _cset(:deploy_to) { app_dir }
25
+
26
+ # Git settings for Capistrano
27
+ default_run_options[:pty] = true # needed for git password prompts
28
+ ssh_options[:forward_agent] = true # use the keys for the person running the cap command to check out the append
29
+ ssh_options[:auth_methods] = ["publickey"]
30
+ ssh_options[:keys] = [File.join(ENV["HOME"], ".ssh", user)]
31
+
32
+ namespace :deploy do
33
+ task :start do ; end
34
+ task :stop do ; end
35
+ task :restart, :roles => :app, :except => { :no_release => true } do
36
+ run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
37
+ end
38
+ end
39
+
40
+ end
data/lib/tbg/common.rb ADDED
@@ -0,0 +1,5 @@
1
+ def _cset(name, *args, &block)
2
+ unless exists?(name)
3
+ set(name, *args, &block)
4
+ end
5
+ end
@@ -0,0 +1,168 @@
1
+ #
2
+ # = Capistrano database.yml task
3
+ #
4
+ # Provides a couple of tasks for creating the database.yml
5
+ # configuration file dynamically when deploy:setup is run.
6
+ #
7
+ # Category:: Capistrano
8
+ # Package:: Database
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # Copyright:: 2007-2010 The Authors
11
+ # License:: MIT License
12
+ # Link:: http://www.simonecarletti.com/
13
+ # Source:: http://gist.github.com/2769
14
+ #
15
+ #
16
+ # == Requirements
17
+ #
18
+ # This extension requires the original <tt>config/database.yml</tt> to be excluded
19
+ # from source code checkout. You can easily accomplish this by renaming
20
+ # the file (for example to database.example.yml) and appending <tt>database.yml</tt>
21
+ # value to your SCM ignore list.
22
+ #
23
+ # # Example for Subversion
24
+ #
25
+ # $ svn mv config/database.yml config/database.example.yml
26
+ # $ svn propset svn:ignore 'database.yml' config
27
+ #
28
+ # # Example for Git
29
+ #
30
+ # $ git mv config/database.yml config/database.example.yml
31
+ # $ echo 'config/database.yml' >> .gitignore
32
+ #
33
+ #
34
+ # == Usage
35
+ #
36
+ # Include this file in your <tt>deploy.rb</tt> configuration file.
37
+ # Assuming you saved this recipe as capistrano_database_yml.rb:
38
+ #
39
+ # require "capistrano_database_yml"
40
+ #
41
+ # Now, when <tt>deploy:setup</tt> is called, this script will automatically
42
+ # create the <tt>database.yml</tt> file in the shared folder.
43
+ # Each time you run a deploy, this script will also create a symlink
44
+ # from your application <tt>config/database.yml</tt> pointing to the shared configuration file.
45
+ #
46
+ # == Custom template
47
+ #
48
+ # By default, this script creates an exact copy of the default
49
+ # <tt>database.yml</tt> file shipped with a new Rails 2.x application.
50
+ # If you want to overwrite the default template, simply create a custom Erb template
51
+ # called <tt>database.yml.erb</tt> and save it into <tt>config/deploy</tt> folder.
52
+ #
53
+ # Although the name of the file can't be changed, you can customize the directory
54
+ # where it is stored defining a variable called <tt>:template_dir</tt>.
55
+ #
56
+ # # store your custom template at foo/bar/database.yml.erb
57
+ # set :template_dir, "foo/bar"
58
+ #
59
+ # # example of database template
60
+ #
61
+ # base: &base
62
+ # adapter: sqlite3
63
+ # timeout: 5000
64
+ # development:
65
+ # database: #{shared_path}/db/development.sqlite3
66
+ # <<: *base
67
+ # test:
68
+ # database: #{shared_path}/db/test.sqlite3
69
+ # <<: *base
70
+ # production:
71
+ # adapter: mysql
72
+ # database: #{application}_production
73
+ # username: #{user}
74
+ # password: #{Capistrano::CLI.ui.ask("Enter MySQL database password: ")}
75
+ # encoding: utf8
76
+ # timeout: 5000
77
+ #
78
+ # Because this is an Erb template, you can place variables and Ruby scripts
79
+ # within the file.
80
+ # For instance, the template above takes advantage of Capistrano CLI
81
+ # to ask for a MySQL database password instead of hard coding it into the template.
82
+ #
83
+ # === Password prompt
84
+ #
85
+ # For security reasons, in the example below the password is not
86
+ # hard coded (or stored in a variable) but asked on setup.
87
+ # I don't like to store passwords in files under version control
88
+ # because they will live forever in your history.
89
+ # This is why I use the Capistrano::CLI utility.
90
+ #
91
+
92
+ unless Capistrano::Configuration.respond_to?(:instance)
93
+ abort "This extension requires Capistrano 2"
94
+ end
95
+
96
+ Capistrano::Configuration.instance.load do
97
+
98
+ namespace :deploy do
99
+
100
+ namespace :db do
101
+
102
+ desc <<-DESC
103
+ Creates the database.yml configuration file in shared path.
104
+
105
+ By default, this task uses a template unless a template \
106
+ called database.yml.erb is found either is :template_dir \
107
+ or /config/deploy folders. The default template matches \
108
+ the template for config/database.yml file shipped with Rails.
109
+
110
+ When this recipe is loaded, db:setup is automatically configured \
111
+ to be invoked after deploy:setup. You can skip this task setting \
112
+ the variable :skip_db_setup to true. This is especially useful \
113
+ if you are using this recipe in combination with \
114
+ capistrano-ext/multistaging to avoid multiple db:setup calls \
115
+ when running deploy:setup for all stages one by one.
116
+ DESC
117
+ task :setup, :except => { :no_release => true } do
118
+ default_template = <<-EOF
119
+ # store your custom template at foo/bar/database.yml.erb
120
+ #set :template_dir, "foo/bar"
121
+ #
122
+ # example of database template
123
+ production:
124
+ adapter: mysql2
125
+ encoding: utf8
126
+ timeout: 5000
127
+ database: #{application}
128
+ host: db.thebeansgroup.com
129
+ pool: 5
130
+ username: tbg
131
+ password: #{Capistrano::CLI.ui.ask("Enter MySQL database password: ")}
132
+ EOF
133
+
134
+ location = fetch(:template_dir, "config/deploy") + '/database.yml.erb'
135
+ template = File.file?(location) ? File.read(location) : default_template
136
+
137
+ config = ERB.new(template)
138
+
139
+ run "mkdir -p #{shared_path}/db"
140
+ run "mkdir -p #{shared_path}/config"
141
+ put config.result, "#{shared_path}/config/database.yml"
142
+ end
143
+
144
+ desc <<-DESC
145
+ [internal] Updates the symlink for database.yml file to the just deployed release.
146
+ DESC
147
+ task :symlink, :except => { :no_release => true } do
148
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
149
+ end
150
+
151
+ desc <<-DESC
152
+ [internal] Removes the database.yml file after code_update in order for the symlink to work
153
+ DESC
154
+ task :remove_config, :except => { :no_release => true } do
155
+ f = "#{release_path}/config/database.yml"
156
+ if File.file?(f) then FileUtils.rm_rf(f) end
157
+ end
158
+
159
+
160
+ end
161
+
162
+ after "deploy:setup", "deploy:db:setup" unless fetch(:skip_db_setup, false)
163
+ after "deploy:code_update", "deploy:db:remove_config"
164
+ after "deploy:finalize_update", "deploy:db:symlink"
165
+
166
+ end
167
+
168
+ end
@@ -0,0 +1,14 @@
1
+ unless Capistrano::Configuration.respond_to?(:instance)
2
+ abort "capistrano/tbg/git_tag requires Capistrano 2"
3
+ end
4
+
5
+ Capistrano::Configuration.instance.load do
6
+ namespace :deploy do
7
+ namespace :git do
8
+ desc 'Create a git tag'
9
+ task :generate_tag do
10
+ p "git tag"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Tbg
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/tbg.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/tbg/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Vincent Siebert"]
6
+ gem.email = ["vincent@siebert.im"]
7
+ gem.description = %q{TBG deploy gem}
8
+ gem.summary = %q{DRYing the TBG deploy process}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "capistrano-tbg"
15
+ # gem.require_paths = ["lib"]
16
+ gem.version = Capistrano::Tbg::VERSION
17
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-tbg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Vincent Siebert
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-14 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: TBG deploy gem
15
+ email:
16
+ - vincent@siebert.im
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .rvmrc
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - lib/tasks/.gitkeep
28
+ - lib/tasks/deploy_automation.rake
29
+ - lib/tasks/git_tag.rake
30
+ - lib/tbg.rb
31
+ - lib/tbg/base.rb
32
+ - lib/tbg/common.rb
33
+ - lib/tbg/database.rb
34
+ - lib/tbg/git_tag.rb
35
+ - lib/tbg/version.rb
36
+ - tbg.gemspec
37
+ homepage: ''
38
+ licenses: []
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 1.8.24
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: DRYing the TBG deploy process
61
+ test_files: []