herkko 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 879673de11ce7eb529e4356895103ed89a184a13
4
- data.tar.gz: fc9394e4eb03e2e4e339d28951dc4445f775c54c
3
+ metadata.gz: 38ce9fb0c1c0bcf36cd9ee05a9992adfa8ef0177
4
+ data.tar.gz: d383b1fc91c655ff8476fac4902e3b362ad711a8
5
5
  SHA512:
6
- metadata.gz: 48b3fb77e95574d6ae9bb71968740eb895c9aaf6a548407d6ecf1c430a6ba76449f47112ffc1657787c3e4673674b84004d36f0b4cfc2f409d85f873719bdc4d
7
- data.tar.gz: 2154638e81b8eccb4bfe9a15cc0ef6038e2dda666cb417ea9effedf36611594d36111a368511b8860f0e30ed613ab83ba56c244fc05bbedd432ece18f4124597
6
+ metadata.gz: f79acc52f47187e90833c81e564de33572385b5894b5fa38fd32ea828ece01c8dd6376f491b0e6f84c474987e7687bf96fd0c3df826394a12aa5854638f569cf
7
+ data.tar.gz: 67eaf3b8a15d9688b0057112dd539d5fcef39fc5afc580cb0f33840105f83eab18b13b931b22f4728283bf25621739fb4b9672a29eda5df183130f2e4aff5b5c
data/lib/herkko/runner.rb CHANGED
@@ -14,17 +14,29 @@ module Herkko
14
14
  end
15
15
 
16
16
  def run
17
+ if ["version", "--version"].include?(environment)
18
+ return version
19
+ end
20
+
17
21
  return print_usage if environment.nil? || command.nil?
18
22
 
19
23
  if respond_to?(command)
20
- send(command, *arguments)
24
+ send(command)
21
25
  else
22
- Herkko.run_and_puts("heroku", arguments + ["-r#{environment}"])
26
+ Herkko.run_with_output("heroku", arguments + ["-r#{environment}"])
23
27
  end
24
28
  end
25
29
 
30
+ def version
31
+ Herkko.puts "Herkko #{Herkko::VERSION}"
32
+ end
33
+
26
34
  def print_usage
27
- Herkko.info "TODO: Usage instructions"
35
+ Herkko.puts <<END
36
+ Herkko
37
+
38
+ Run `herkko [environment] [command]` for example `herkko production deploy`.
39
+ END
28
40
  end
29
41
 
30
42
  def deploy
@@ -33,30 +45,39 @@ module Herkko
33
45
 
34
46
  Herkko.info("Deploying changes:")
35
47
 
48
+ puts
36
49
  puts changelog
50
+ puts
37
51
 
38
- if check_ci == :green
39
- Herkko.info "CI is green. Deploying..."
40
-
41
- run_migrations = migrations_needed?
42
- push_new_code
52
+ ci_state = if skip_ci_check?
53
+ :skip
54
+ else
55
+ check_ci
56
+ end
43
57
 
44
- if run_migrations
45
- migrate
46
- else
47
- Herkko.info "No need to migrate."
48
- end
58
+ if ci_state == :green
59
+ Herkko.info "CI is green. Deploying..."
49
60
 
50
- if seed_file_changed?
51
- Herkko.info "NOTE: Seed file seem the have changed. Make sure to run it if needed."
52
- end
61
+ deploy!
62
+ elsif ci_state == :skip
63
+ Herkko.info "Skipping CI. Deploying..."
53
64
 
54
- # TODO: puts "Print the after deployment checklist from a file"
65
+ deploy!
66
+ elsif ci_state == :yellow
67
+ Herkko.info "CI is running. Wait a while."
55
68
  else
56
69
  Herkko.info "CI is red. Fix it!"
57
70
  end
58
71
  end
59
72
 
73
+ def console
74
+ Herkko.run_with_output "heroku run rails console -r #{environment}"
75
+ end
76
+
77
+ def seed
78
+ Herkko.run_with_output "heroku run rake db:seed -r #{environment}"
79
+ end
80
+
60
81
  def check_ci
61
82
  Herkko.info "Checking CI..."
62
83
  Herkko::Travis.status_for(current_branch)
@@ -64,7 +85,7 @@ module Herkko
64
85
 
65
86
  def migrate
66
87
  Herkko.info "Migrating database..."
67
- Herkko.run_and_puts %{
88
+ Herkko.run_with_output %{
68
89
  heroku run rake db:migrate -r #{environment} &&
69
90
  heroku restart -r #{environment}
70
91
  }
@@ -72,11 +93,34 @@ module Herkko
72
93
 
73
94
  def push_new_code
74
95
  Herkko.info "Pushing code to Heroku..."
75
- Herkko.run_and_puts("git", "push", environment)
96
+ puts
97
+ Herkko.run_with_output("git", "push", environment, "master")
98
+ puts
76
99
  end
77
100
 
78
101
  private
79
102
 
103
+ def deploy!
104
+ run_migrations = migrations_needed?
105
+ push_new_code
106
+
107
+ if run_migrations
108
+ migrate
109
+ else
110
+ Herkko.info "No need to migrate."
111
+ end
112
+
113
+ if seed_file_changed?
114
+ Herkko.info "NOTE: Seed file seem the have changed. Make sure to run it if needed."
115
+ end
116
+
117
+ # TODO: puts "Print the after deployment checklist from a file"
118
+ end
119
+
120
+ def skip_ci_check?
121
+ arguments.include?("--skip-ci-check")
122
+ end
123
+
80
124
  def current_branch
81
125
  Herkko.run("git", "rev-parse", "--abbrev-ref", "HEAD")[0].strip
82
126
  end
@@ -100,15 +144,15 @@ module Herkko
100
144
  def file_changed?(file_path)
101
145
  files = Herkko.run("git", "diff", "--name-only", currently_deployed_to(environment), to_be_deployed_sha)[0]
102
146
 
103
- files.split("\n").any? {|filename| filename.match(Regex.new(file_path)) }
147
+ files.split("\n").any? {|filename| filename.match(Regexp.new(file_path)) }
104
148
  end
105
149
 
106
150
  def fetch_currently_deployed_version
107
- Herkko.run_and_puts("git", "fetch", environment)
151
+ Herkko.run_with_output("git", "fetch", environment)
108
152
  end
109
153
 
110
154
  def changelog
111
- Herkko.run("git", "log", "--name-only", "#{currently_deployed_to(environment)}..#{to_be_deployed_sha}")[0]
155
+ Herkko.run("git", "log", "--pretty=short", "#{currently_deployed_to(environment)}..#{to_be_deployed_sha}")[0]
112
156
  end
113
157
  end
114
158
  end
data/lib/herkko/travis.rb CHANGED
@@ -8,8 +8,11 @@ module Herkko
8
8
  Herkko.info "There was an error with checking Travis: #{status[1]}"
9
9
  :red
10
10
  else
11
- if status[0].match(/passed/)
11
+ case status[0].split(":")[0]
12
+ when /passed/
12
13
  :green
14
+ when /started/
15
+ :yellow
13
16
  else
14
17
  :red
15
18
  end
@@ -1,3 +1,3 @@
1
1
  module Herkko
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/herkko.rb CHANGED
@@ -5,20 +5,24 @@ module Herkko
5
5
  @@debug = false
6
6
 
7
7
  def self.info(text)
8
- puts "-> " + text
8
+ Kernel.puts "-> " + text
9
+ end
10
+
11
+ def self.puts(text)
12
+ Kernel.puts text
9
13
  end
10
14
 
11
15
  def self.run(*command)
12
16
  if @@debug
13
- puts "--> #{command.join(" ")}"
17
+ Kernel.puts "--> #{command.join(" ")}"
14
18
  end
15
19
 
16
20
  Open3.capture3(*command)
17
21
  end
18
22
 
19
- def self.run_and_puts(*command)
23
+ def self.run_with_output(*command)
20
24
  if @@debug
21
- puts "--> #{command.join(" ")}"
25
+ Kernel.puts "--> #{command.join(" ")}"
22
26
  end
23
27
 
24
28
  Kernel.system(*command)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: herkko
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vesa Vänskä
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-17 00:00:00.000000000 Z
11
+ date: 2016-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  requirements: []
81
81
  rubyforge_project:
82
- rubygems_version: 2.2.2
82
+ rubygems_version: 2.5.1
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: Herkko is a deployment tool for Heroku.