push2heroku 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in push2heroku.gemspec
4
4
  gemspec
5
+
6
+ gem 'rake'
data/README.md CHANGED
@@ -1,33 +1,75 @@
1
1
  # Push2heroku
2
2
 
3
- Push to heroku.
3
+ Makes it easy to push to heroku.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Add this to Gemfile:
8
8
 
9
9
  gem 'push2heroku'
10
10
 
11
- And then execute:
11
+ ## Usage
12
12
 
13
- $ bundle
13
+ After installing the gem copy [this file](https://raw.github.com/gist/3098161/578dad8cd3933834712a8afdf33520221dbdb986/push2heroku.yml) to `config/push2heroku.yml` .
14
14
 
15
- Or install it yourself as:
15
+ Change the contents of `config/push2heroku.yml` as per your needs after
16
+ reading rest of README.
16
17
 
17
- $ gem install push2heroku
18
+ ## What problem it solves
18
19
 
19
- ## Usage
20
+ Here at BigBinary we create a separate branch for each feature we work
21
+ on. Let's say that I am working on `authentication with facebook`.
22
+ When I am done with the feature then I send pull request to my team
23
+ members to review. However in order to review the work all the team
24
+ members need to pull down the branch and fire up `rails server` and then
25
+ review.
26
+
27
+ We like to see things working. So we developed `push2heroku` to push a
28
+ feature branch to heroku instantly with one command. Executing
29
+ `push2heroku` prints a url and we put that url in the pull request so
30
+ that team members can actually test the feature.
31
+
32
+ ## Here is how it works
33
+
34
+ `push2heroku` reads the `push2heroku.yml` and executes those commands.
35
+ It's that simple.
36
+
37
+ Lets say that I am working in a branch called
38
+ `76-facebook-authentication`. When I execute `push2heroku` then the
39
+ application name under which it will be deployed to heroku will be
40
+ `nimbleshop-76-facebook-neeraj`.
41
+
42
+ `nimbleshop` is the name of the project.
43
+ `76-facebook` is the first 10 letters of the branch name.
44
+ `neeraj` is the first 5 letters of my github user name.
45
+
46
+ So in this case the url of the application will be
47
+ `http://nimbleshop-76-facebook-neeraj.herokuapp.com` .
48
+
49
+ In the `push2heroku.yml` file the keys `production` and `staging`
50
+ are branch names. And these branches are special branches. For these
51
+ branches the url generated will be just the application name and the
52
+ branch name. For example if I execute `rake push2heroku` from `staging`
53
+ branch then the heroku url will be
54
+ `http://nimbleshop-staging.herokuapp.com`.
55
+
56
+ However if I delete `staging` key from `push2heroku.yml` then `staging`
57
+ is no longer a special branch and the heroku url would be
58
+ `http://nimbleshop-staging-neeraj.herokuapp.com` .
59
+
60
+ ## Resetting the database
20
61
 
21
- First copy `push2heroku.yml` from [here]().
62
+ When the application is deployed for the very first time then you want
63
+ the database to reset and some sort of setup to be run. However on
64
+ subsequest deployment you do not need to run those setup tasks.
22
65
 
23
- `rake push2heroku`
66
+ To incorporate that on first deployment `push2heroku` will execute
67
+ commands mentioned under key `hard`. Here `hard` stands for hard push.
68
+ Subsequent pushes will be `soft` push.
24
69
 
25
- push2heroku uses `cedar` stack.
70
+ If you want to force `hard` push anytime then execute `rake push2heroku
71
+ HARD=true`.
26
72
 
27
- ## Contributing
73
+ ## License
28
74
 
29
- 1. Fork it
30
- 2. Create your feature branch (`git checkout -b my-new-feature`)
31
- 3. Commit your changes (`git commit -am 'Added some feature'`)
32
- 4. Push to the branch (`git push origin my-new-feature`)
33
- 5. Create new Pull Request
75
+ `push2heroku` is released under MIT License.
data/lib/push2heroku.rb CHANGED
@@ -7,6 +7,7 @@ module Push2heroku
7
7
  autoload :Base
8
8
  autoload :ConfigLoader
9
9
  autoload :Git
10
+ autoload :Util
10
11
  end
11
12
 
12
13
  require 'push2heroku/railtie'
@@ -1,24 +1,31 @@
1
1
  module Push2heroku
2
2
  class Base
3
3
 
4
- attr_accessor :branch_name, :commands, :current_user, :subdomain, :settings
4
+ attr_accessor :branch_name, :commands, :current_user, :heroku_app_name, :settings, :named_branches
5
+ attr_reader :hard, :project_name
6
+
7
+ def initialize(hard)
8
+ @project_name = File.basename(Dir.getwd)
9
+ @hard = hard.blank? ? false : true
5
10
 
6
- def initialize
7
11
  git = Git.new
8
12
  @branch_name = git.current_branch
9
13
  @current_user = git.current_user
10
- @settings = ConfigLoader.new('push2heroku.yml').load(branch_name)
11
- @commands = []
12
- @subdomain = "#{url_prefix}-#{url_suffix}"
13
- end
14
14
 
15
- def self.process
16
- new.push
15
+ @named_branches = ConfigLoader.new('push2heroku.yml').named_branches
16
+
17
+ @heroku_app_name = "#{url_prefix}-#{url_suffix}".downcase.chomp('-')[0..29] #heroku only allows upto 30 characters in name
18
+
19
+ ENV['BRANCH_NAME'] = branch_name
20
+ ENV['HEROKU_APP_NAME'] = heroku_app_name
21
+ @settings = ConfigLoader.new('push2heroku.yml').settings(branch_name)
22
+
23
+ @commands = []
17
24
  end
18
25
 
19
26
  def push
20
27
  build_commands
21
- commands.each { |cmd| puts ">"*20 + cmd }
28
+ feedback_to_user
22
29
  commands.each do |cmd|
23
30
  begin
24
31
  sh cmd
@@ -31,31 +38,46 @@ module Push2heroku
31
38
  private
32
39
 
33
40
  def url_suffix
34
- return branch_name if %w(staging production).include?(branch_name)
41
+ return branch_name if named_branches.include?(branch_name)
35
42
 
36
43
  [branch_name[0..10], current_user[0..5]].join('-').gsub(/[^0-9a-zA-Z]+/,'-').downcase
37
44
  end
38
45
 
39
46
  def url_prefix
40
- settings.app_name.gsub(/[^0-9a-zA-Z]+/,'-').downcase
47
+ project_name.gsub(/[^0-9a-zA-Z]+/,'-').downcase
41
48
  end
42
49
 
43
50
  def build_commands
44
- commands << "heroku create #{subdomain} --stack cedar --remote h#{branch_name}"
45
- commands << "git push h#{branch_name} #{branch_name}:master -f "
46
-
51
+ commands << settings.pre_config_commands
47
52
  build_config_commands
48
-
49
- commands << "heroku run rake db:migrate --app #{subdomain} --trace"
50
- commands << "heroku run rake setup --app #{subdomain} --trace"
51
- commands << "heroku open --app #{subdomain}"
53
+ commands << ( Util.hard_push?(self) ? settings.post_config_commands.hard : settings.post_config_commands.soft )
54
+ commands << "bundle exec heroku open --app #{heroku_app_name}"
55
+ commands.flatten!
52
56
  end
53
57
 
54
58
  def build_config_commands
59
+ return unless settings.config
60
+ cmd = []
55
61
  settings.config.each do |key, value|
56
- commands << "heroku config:add #{key.upcase}=#{value} --app #{subdomain}"
62
+ cmd << "#{key.upcase}=#{value}"
57
63
  end
64
+ commands << "bundle exec heroku config:add #{cmd.join(' ')} --app #{heroku_app_name}"
58
65
  end
59
66
 
67
+ def feedback_to_user
68
+ puts '='*50
69
+ puts 'The application will be deployed at:'
70
+ puts "http://#{heroku_app_name}.herokuapp.com"
71
+ puts '='*50
72
+ puts ''
73
+ puts '='*50
74
+ puts 'Following commands will be executed:'
75
+ commands.each do |cmd|
76
+ puts ''
77
+ puts cmd
78
+ end
79
+ puts '='*50
80
+ puts ''
81
+ end
60
82
  end
61
83
  end
@@ -1,21 +1,37 @@
1
1
  module Push2heroku
2
2
  class ConfigLoader
3
3
 
4
- attr_reader :filename
4
+ attr_reader :filename, :hash
5
5
 
6
6
  def initialize(filename)
7
7
  @filename = filename
8
+ @hash = load_config
8
9
  end
9
10
 
10
- def load(key)
11
- file = Rails.root.join('config', filename)
12
- hash = YAML.load(ERB.new(File.read(file)).result)
13
-
11
+ def settings(branch_name)
14
12
  common_hash = hash['common'] || {}
15
- env_hash = hash[key.to_s] || {}
16
-
13
+ env_hash = hash[branch_name.to_s] || {}
17
14
  final_hash = common_hash.deep_merge(env_hash)
18
15
  Hashr.new(final_hash)
19
16
  end
17
+
18
+ def named_branches
19
+ hash.keys - ['common']
20
+ end
21
+
22
+ private
23
+
24
+ def load_config
25
+ file = Rails.root.join('config', filename)
26
+
27
+ unless File.exists? file
28
+ puts "you do not have config/push2heroku.yml file. Please execute "
29
+ puts "rails generate push2heroku:install"
30
+ abort
31
+ end
32
+ YAML.load(ERB.new(File.read(file)).result)
33
+ end
34
+
35
+
20
36
  end
21
37
  end
@@ -5,12 +5,12 @@ module Push2heroku
5
5
  if result.empty?
6
6
  raise "It seems your app is not a git repo"
7
7
  else
8
- result.select { |b| b =~ /^\*/ }.first.split(" ").last.strip.downcase
8
+ result.select { |b| b =~ /^\*/ }.first.split(" ").last.strip
9
9
  end
10
10
  end
11
11
 
12
12
  def current_user
13
- `git config user.name`.chop!.downcase
13
+ `git config user.name`.chop!
14
14
  end
15
15
  end
16
16
  end
@@ -4,7 +4,8 @@ module Push2heroku
4
4
  rake_tasks do
5
5
  desc "pushes to heroku"
6
6
  task :push2heroku => :environment do
7
- Base.process
7
+ hard = ENV['HARD']
8
+ Base.new(hard).push
8
9
  end
9
10
  end
10
11
 
@@ -0,0 +1,13 @@
1
+ class Util
2
+
3
+ def self.hard_push?(base)
4
+ remote_branch_name = "h#{base.branch_name}"
5
+ base.hard || !remote_branch_exists?(remote_branch_name)
6
+ end
7
+
8
+ def self.remote_branch_exists?(remote_branch_name)
9
+ out = `cd #{Rails.root.expand_path} && git branch -r`
10
+ out.include?(remote_branch_name)
11
+ end
12
+
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Push2heroku
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/push2heroku.gemspec CHANGED
@@ -16,5 +16,5 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Push2heroku::VERSION
17
17
 
18
18
  gem.add_dependency("hashr", "= 0.0.19")
19
- gem.add_dependency("heroku")
19
+ gem.add_dependency("heroku", "= 2.25.0")
20
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: push2heroku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,30 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-25 00:00:00.000000000Z
12
+ date: 2012-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashr
16
- requirement: &70184765576220 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - =
19
+ - - '='
20
20
  - !ruby/object:Gem::Version
21
21
  version: 0.0.19
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70184765576220
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.0.19
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: heroku
27
- requirement: &70184765575800 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
- - - ! '>='
35
+ - - '='
31
36
  - !ruby/object:Gem::Version
32
- version: '0'
37
+ version: 2.25.0
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70184765575800
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.25.0
36
46
  description: push2heroku
37
47
  email:
38
48
  - neerajdotname@gmail.com
@@ -50,6 +60,7 @@ files:
50
60
  - lib/push2heroku/config_loader.rb
51
61
  - lib/push2heroku/git.rb
52
62
  - lib/push2heroku/railtie.rb
63
+ - lib/push2heroku/util.rb
53
64
  - lib/push2heroku/version.rb
54
65
  - push2heroku.gemspec
55
66
  homepage: ''
@@ -64,15 +75,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
75
  - - ! '>='
65
76
  - !ruby/object:Gem::Version
66
77
  version: '0'
78
+ segments:
79
+ - 0
80
+ hash: 2308710282152006324
67
81
  required_rubygems_version: !ruby/object:Gem::Requirement
68
82
  none: false
69
83
  requirements:
70
84
  - - ! '>='
71
85
  - !ruby/object:Gem::Version
72
86
  version: '0'
87
+ segments:
88
+ - 0
89
+ hash: 2308710282152006324
73
90
  requirements: []
74
91
  rubyforge_project:
75
- rubygems_version: 1.8.15
92
+ rubygems_version: 1.8.24
76
93
  signing_key:
77
94
  specification_version: 3
78
95
  summary: push2heroku