bard 0.6.2 → 0.6.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/VERSION +1 -1
- data/bard.gemspec +2 -1
- data/features/bard_check.feature +16 -16
- data/lib/bard.rb +19 -84
- data/lib/bard/check.rb +76 -0
- metadata +2 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.3
|
data/bard.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bard}
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Micah Geisel", "Nick Hogle"]
|
@@ -41,6 +41,7 @@ Gem::Specification.new do |s|
|
|
41
41
|
"features/support/grit_ext.rb",
|
42
42
|
"features/support/io.rb",
|
43
43
|
"lib/bard.rb",
|
44
|
+
"lib/bard/check.rb",
|
44
45
|
"lib/bard/git.rb",
|
45
46
|
"lib/bard/io.rb",
|
46
47
|
"spec/bard_spec.rb",
|
data/features/bard_check.feature
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Feature: Bard can check its environment for missing dependencies and potential problems
|
2
2
|
|
3
3
|
Scenario: Bard check returns its version
|
4
|
-
When I type "bard check"
|
4
|
+
When I type "bard check -v"
|
5
5
|
Then I should see the current version of bard
|
6
6
|
And I should see the current version of git
|
7
7
|
And I should see the current version of rubygems
|
@@ -9,96 +9,96 @@ Feature: Bard can check its environment for missing dependencies and potential p
|
|
9
9
|
|
10
10
|
Scenario: Bard check examines a local project for problems
|
11
11
|
Given a shared rails project
|
12
|
-
When I type "bard check
|
12
|
+
When I type "bard check"
|
13
13
|
Then I should see "No problems"
|
14
14
|
|
15
15
|
Scenario: Bard check detects missing database
|
16
16
|
Given a shared rails project
|
17
17
|
And the database is missing
|
18
|
-
When I type "bard check
|
18
|
+
When I type "bard check"
|
19
19
|
Then I should see the fatal error "missing database"
|
20
20
|
|
21
21
|
Scenario: Bard check detects pending migrations
|
22
22
|
Given a shared rails project
|
23
23
|
And I have committed a set of changes that includes a new migration
|
24
|
-
When I type "bard check
|
24
|
+
When I type "bard check"
|
25
25
|
Then I should see the fatal error "pending migrations"
|
26
26
|
|
27
27
|
Scenario: Bard check detects missing config/database.yml
|
28
28
|
Given a shared rails project
|
29
29
|
And "config/database.yml" is missing
|
30
|
-
When I type "bard check
|
30
|
+
When I type "bard check"
|
31
31
|
Then I should see the fatal error "missing config/database.yml"
|
32
32
|
|
33
33
|
Scenario: Bard check detects missing submodules
|
34
34
|
Given a shared rails project
|
35
35
|
And a submodule
|
36
36
|
And the submodule is missing
|
37
|
-
When I type "bard check
|
37
|
+
When I type "bard check"
|
38
38
|
Then I should see the fatal error "missing submodule"
|
39
39
|
|
40
40
|
Scenario: Bard check detects submodules with detached heads
|
41
41
|
Given a shared rails project
|
42
42
|
And a submodule
|
43
43
|
And the submodule has a detached head
|
44
|
-
When I type "bard check
|
44
|
+
When I type "bard check"
|
45
45
|
Then I should see the fatal error "submodule has a detached head"
|
46
46
|
|
47
47
|
Scenario: Bard check detects missing gems
|
48
48
|
Given a shared rails project
|
49
49
|
And I have committed a set of changes that adds the test gem as a dependency
|
50
50
|
And I dont have the test gem installed
|
51
|
-
When I type "bard check
|
51
|
+
When I type "bard check"
|
52
52
|
Then I should see the fatal error "missing gems"
|
53
53
|
|
54
54
|
Scenario: Bard check detects master branch checked out
|
55
55
|
Given a shared rails project
|
56
56
|
And I am on the master branch
|
57
|
-
When I type "bard check
|
57
|
+
When I type "bard check"
|
58
58
|
Then I should see the fatal error "master branch"
|
59
59
|
|
60
60
|
Scenario: Bard check detects missing integration branch
|
61
61
|
Given a shared rails project
|
62
62
|
And there is no integration branch
|
63
|
-
When I type "bard check
|
63
|
+
When I type "bard check"
|
64
64
|
Then I should see the fatal error "missing integration branch"
|
65
65
|
|
66
66
|
Scenario: Bard check detects non-tracking integration branch
|
67
67
|
Given a shared rails project
|
68
68
|
And the integration branch isnt tracking origin/integration
|
69
|
-
When I type "bard check
|
69
|
+
When I type "bard check"
|
70
70
|
Then I should see the fatal error "tracking"
|
71
71
|
|
72
72
|
Scenario: Bard check detects missing RAILS_ENV environment variable
|
73
73
|
Given a shared rails project
|
74
74
|
And my "RAILS_ENV" environment variable is ""
|
75
|
-
When I type "bard check
|
75
|
+
When I type "bard check"
|
76
76
|
Then I should see the warning "RAILS_ENV is not set"
|
77
77
|
|
78
78
|
Scenario: Bard check detects missing staging hook
|
79
79
|
Given a shared rails project
|
80
80
|
And my "RAILS_ENV" environment variable is "staging"
|
81
81
|
And there is no git hook on the staging server
|
82
|
-
When I type "bard check
|
82
|
+
When I type "bard check" on the staging server
|
83
83
|
Then I should see the fatal error "missing git hook"
|
84
84
|
|
85
85
|
Scenario: Bard check detects unexecutable staging hook
|
86
86
|
Given a shared rails project
|
87
87
|
And my "RAILS_ENV" environment variable is "staging"
|
88
88
|
And the git hook on the staging server is not executable
|
89
|
-
When I type "bard check
|
89
|
+
When I type "bard check" on the staging server
|
90
90
|
Then I should see the fatal error "unexecutable git hook"
|
91
91
|
|
92
92
|
Scenario: Bard check detects improper staging hook
|
93
93
|
Given a shared rails project
|
94
94
|
And my "RAILS_ENV" environment variable is "staging"
|
95
95
|
And the git hook on the staging server is bad
|
96
|
-
When I type "bard check
|
96
|
+
When I type "bard check" on the staging server
|
97
97
|
Then I should see the fatal error "improper git hook"
|
98
98
|
|
99
99
|
Scenario: Bard check detects missing receive.denyCurrentBranch git variable on staging
|
100
100
|
Given a shared rails project
|
101
101
|
And my "RAILS_ENV" environment variable is "staging"
|
102
102
|
And the staging server git config for receive.denyCurrentBranch is not "ignore"
|
103
|
-
When I type "bard check
|
103
|
+
When I type "bard check" on the staging server
|
104
104
|
Then I should see the fatal error "denyCurrentBranch"
|
data/lib/bard.rb
CHANGED
@@ -8,46 +8,26 @@ require 'thor'
|
|
8
8
|
require 'bard/git'
|
9
9
|
require 'bard/io'
|
10
10
|
|
11
|
+
require 'bard/check'
|
12
|
+
|
11
13
|
class Bard < Thor
|
12
14
|
include BardGit
|
13
15
|
include BardIO
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
'bard' => Net::HTTP.get(URI.parse("http://gemcutter.org/gems/bard.json")).match(/"version":"([0-9.]+)"/)[1],
|
19
|
-
'git' => '1.6.4',
|
20
|
-
'rubygems' => '1.3.4',
|
21
|
-
'ruby' => '1.8.6'
|
22
|
-
}
|
23
|
-
actual = {
|
24
|
-
'bard' => File.read(File.expand_path(File.dirname(__FILE__) + "../../VERSION")).chomp,
|
25
|
-
'git' => `git --version`[/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/],
|
26
|
-
'rubygems' => Gem::VERSION,
|
27
|
-
'ruby' => RUBY_VERSION
|
28
|
-
}
|
29
|
-
help = {
|
30
|
-
'bard' => 'please type `gem install bard` to update',
|
31
|
-
'git' => 'please visit http://git-scm.com/download and install the appropriate package for your architecture',
|
32
|
-
'rubygems' => 'please type `gem update --system` to update',
|
33
|
-
'ruby' => 'um... ask micah?'
|
34
|
-
}
|
35
|
-
|
36
|
-
%w(bard git rubygems ruby).each do |pkg|
|
37
|
-
if actual[pkg] < required[pkg]
|
38
|
-
puts red("#{pkg.ljust(9)} (#{actual[pkg]}) ... NEED (#{required[pkg]})")
|
39
|
-
puts red(" #{help[pkg]}")
|
40
|
-
else
|
41
|
-
puts green("#{pkg.ljust(9)} (#{actual[pkg]})")
|
42
|
-
end
|
43
|
-
end
|
17
|
+
VERSION = File.read(File.expand_path(File.dirname(__FILE__) + "../../VERSION")).chomp
|
18
|
+
|
19
|
+
method_options %w( verbose -v ) => :boolean
|
44
20
|
|
45
|
-
|
21
|
+
desc "check [PROJECT_PATH]", "check current project and environment for missing dependencies and common problems"
|
22
|
+
def check(project_path = nil)
|
23
|
+
project_path = "." if project_path.nil? and File.directory? ".git"
|
24
|
+
check_dependencies
|
25
|
+
check_project project_path if project_path
|
46
26
|
end
|
47
27
|
|
48
28
|
desc "pull", "pull changes to your local machine"
|
49
29
|
def pull
|
50
|
-
|
30
|
+
check_dependencies
|
51
31
|
|
52
32
|
ensure_project_root!
|
53
33
|
ensure_integration_branch!
|
@@ -82,7 +62,7 @@ class Bard < Thor
|
|
82
62
|
|
83
63
|
desc "push", "push local changes out to the remote"
|
84
64
|
def push
|
85
|
-
|
65
|
+
check_dependencies
|
86
66
|
|
87
67
|
ensure_project_root!
|
88
68
|
ensure_integration_branch!
|
@@ -107,7 +87,6 @@ class Bard < Thor
|
|
107
87
|
|
108
88
|
desc "deploy", "pushes, merges integration branch into master and deploys it to production"
|
109
89
|
def deploy
|
110
|
-
invoke :check
|
111
90
|
invoke :push
|
112
91
|
|
113
92
|
run_crucial "git fetch origin"
|
@@ -119,12 +98,13 @@ class Bard < Thor
|
|
119
98
|
|
120
99
|
run_crucial "git merge integration"
|
121
100
|
run_crucial "git push origin master"
|
101
|
+
run_crucial "git checkout integration"
|
122
102
|
end
|
123
103
|
|
124
104
|
if ENV['RAILS_ENV'] == "staging"
|
125
105
|
desc "stage", "!!! INTERNAL USE ONLY !!! reset HEAD to integration, update submodules, run migrations, install gems, restart server"
|
126
106
|
def stage
|
127
|
-
|
107
|
+
check_dependencies
|
128
108
|
|
129
109
|
if ENV['GIT_DIR'] == '.'
|
130
110
|
# this means the script has been called as a hook, not manually.
|
@@ -140,12 +120,12 @@ class Bard < Thor
|
|
140
120
|
head = File.read('.git/HEAD').chomp
|
141
121
|
# abort if we're on a detached head
|
142
122
|
exit unless head.sub! 'ref: ', ''
|
143
|
-
|
144
|
-
|
145
|
-
else
|
146
|
-
revs = gets.split ' '
|
147
|
-
old_rev, new_rev = revs if head == revs.pop
|
123
|
+
revs = gets.split ' '
|
124
|
+
old_rev, new_rev, branch = revs
|
148
125
|
|
126
|
+
if branch == "master"
|
127
|
+
run_crucial "cap deploy"
|
128
|
+
elsif read == branch
|
149
129
|
changed_files = run_crucial("git diff #{old_rev} #{new_rev} --diff-filter=ACMRD --name-only").split("\n")
|
150
130
|
|
151
131
|
if changed_files.any? { |f| f =~ %r(^db/migrate/.+) }
|
@@ -167,49 +147,4 @@ class Bard < Thor
|
|
167
147
|
end
|
168
148
|
end
|
169
149
|
end
|
170
|
-
|
171
|
-
private
|
172
|
-
def check_project(project)
|
173
|
-
errors = []
|
174
|
-
warnings = []
|
175
|
-
Dir.chdir project do
|
176
|
-
status, stdout, stderr = systemu "rake db:abort_if_pending_migrations"
|
177
|
-
errors << "missing config/database.yml, adapt from config/database.sample.yml." if stderr.include? "config/database.yml"
|
178
|
-
errors << "missing config/database.sample.yml, please complain to micah" if not File.exist? "config/database.sample.yml"
|
179
|
-
errors << "missing database, please run `rake db:create db:migrate" if stderr.include? "Unknown database"
|
180
|
-
errors << "pending migrations, please run `rake db:migrate`" if stdout.include? "pending migrations"
|
181
|
-
|
182
|
-
errors << "missing submodule, please run git submodule update --init" if `git submodule status` =~ /^-/
|
183
|
-
errors << "submodule has a detached head, please complain to micah" unless system 'git submodule foreach "git symbolic-ref HEAD"'
|
184
|
-
|
185
|
-
errors << "missing gems, please run `rake gems:install`" if `rake gems` =~ /\[ \]/
|
186
|
-
|
187
|
-
errors << "missing integration branch, please complain to micah" if `git branch` !~ /\bintegration\b/
|
188
|
-
errors << "integration branch isnt tracking the remote integration branch, please run `grb track integration`" if `git config branch.integration.merge` !~ %r%\brefs/heads/integration\b%
|
189
|
-
errors << "you shouldn't be working on the master branch, please work on the integration branch" if `cat .git/HEAD`.include? "refs/heads/master"
|
190
|
-
|
191
|
-
if ENV['RAILS_ENV'] == "staging"
|
192
|
-
if not File.exist? ".git/hooks/post-receive"
|
193
|
-
errors << "missing git hook, please complain to micah"
|
194
|
-
else
|
195
|
-
errors << "unexecutable git hook, please complain to micah" unless File.executable? ".git/hooks/post-receive"
|
196
|
-
errors << "improper git hook, please complain to micah" unless File.read(".git/hooks/post-receive").include? "bard stage $@"
|
197
|
-
end
|
198
|
-
errors << "the git config variable receive.denyCurrentBranch is not set to ignore, please complain to micah" if `git config receive.denyCurrentBranch`.chomp != "ignore"
|
199
|
-
end
|
200
|
-
|
201
|
-
warnings << "RAILS_ENV is not set, please complain to micah" if ENV['RAILS_ENV'].nil? or ENV['RAILS_ENV'].empty?
|
202
|
-
end
|
203
|
-
|
204
|
-
if not errors.empty?
|
205
|
-
fatal "#{errors.length} problems detected:\n #{errors.join("\n ")}"
|
206
|
-
elsif not warnings.empty?
|
207
|
-
warn "#{warnings.length} potential problems detected:\n #{warnings.join("\n ")}"
|
208
|
-
else
|
209
|
-
puts green("No problems detected in project: #{project}")
|
210
|
-
if ENV['RAILS_ENV'] != "staging"
|
211
|
-
puts "please run it on the staging server by typing `cap shell` and then `bard check [PROJECT_NAME]`"
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
150
|
end
|
data/lib/bard/check.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
class Bard < Thor
|
2
|
+
private
|
3
|
+
def check_dependencies
|
4
|
+
required = {
|
5
|
+
'bard' => Net::HTTP.get(URI.parse("http://gemcutter.org/gems/bard.json")).match(/"version":"([0-9.]+)"/)[1],
|
6
|
+
'git' => '1.6.4',
|
7
|
+
'rubygems' => '1.3.4',
|
8
|
+
'ruby' => '1.8.6'
|
9
|
+
}
|
10
|
+
actual = {
|
11
|
+
'bard' => Bard::VERSION,
|
12
|
+
'git' => `git --version`[/[0-9.]+/],
|
13
|
+
'rubygems' => Gem::VERSION,
|
14
|
+
'ruby' => RUBY_VERSION
|
15
|
+
}
|
16
|
+
help = {
|
17
|
+
'bard' => 'please type `gem install bard` to update',
|
18
|
+
'git' => 'please visit http://git-scm.com/download and install the appropriate package for your architecture',
|
19
|
+
'rubygems' => 'please type `gem update --system` to update',
|
20
|
+
'ruby' => 'um... ask micah?'
|
21
|
+
}
|
22
|
+
|
23
|
+
%w(bard git rubygems ruby).each do |pkg|
|
24
|
+
if actual[pkg] < required[pkg]
|
25
|
+
puts red("#{pkg.ljust(9)} (#{actual[pkg]}) ... NEED (#{required[pkg]})")
|
26
|
+
puts red(" #{help[pkg]}")
|
27
|
+
elsif options.verbose?
|
28
|
+
puts green("#{pkg.ljust(9)} (#{actual[pkg]})")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def check_project(project)
|
34
|
+
errors = []
|
35
|
+
warnings = []
|
36
|
+
Dir.chdir project do
|
37
|
+
status, stdout, stderr = systemu "rake db:abort_if_pending_migrations"
|
38
|
+
errors << "missing config/database.yml, adapt from config/database.sample.yml." if stderr.include? "config/database.yml"
|
39
|
+
errors << "missing config/database.sample.yml, please complain to micah" if not File.exist? "config/database.sample.yml"
|
40
|
+
errors << "missing database, please run `rake db:create db:migrate" if stderr.include? "Unknown database"
|
41
|
+
errors << "pending migrations, please run `rake db:migrate`" if stdout.include? "pending migrations"
|
42
|
+
|
43
|
+
errors << "missing submodule, please run git submodule update --init" if `git submodule status` =~ /^-/
|
44
|
+
errors << "submodule has a detached head, please complain to micah" unless system 'git submodule foreach "git symbolic-ref HEAD"'
|
45
|
+
|
46
|
+
errors << "missing gems, please run `rake gems:install`" if `rake gems` =~ /\[ \]/
|
47
|
+
|
48
|
+
errors << "missing integration branch, please complain to micah" if `git branch` !~ /\bintegration\b/
|
49
|
+
errors << "integration branch isnt tracking the remote integration branch, please run `grb track integration`" if `git config branch.integration.merge` !~ %r%\brefs/heads/integration\b%
|
50
|
+
errors << "you shouldn't be working on the master branch, please work on the integration branch" if `cat .git/HEAD`.include? "refs/heads/master"
|
51
|
+
|
52
|
+
if ENV['RAILS_ENV'] == "staging"
|
53
|
+
if not File.exist? ".git/hooks/post-receive"
|
54
|
+
errors << "missing git hook, please complain to micah"
|
55
|
+
else
|
56
|
+
errors << "unexecutable git hook, please complain to micah" unless File.executable? ".git/hooks/post-receive"
|
57
|
+
errors << "improper git hook, please complain to micah" unless File.read(".git/hooks/post-receive").include? "bard stage $@"
|
58
|
+
end
|
59
|
+
errors << "the git config variable receive.denyCurrentBranch is not set to ignore, please complain to micah" if `git config receive.denyCurrentBranch`.chomp != "ignore"
|
60
|
+
end
|
61
|
+
|
62
|
+
warnings << "RAILS_ENV is not set, please complain to micah" if ENV['RAILS_ENV'].nil? or ENV['RAILS_ENV'].empty?
|
63
|
+
end
|
64
|
+
|
65
|
+
if not errors.empty?
|
66
|
+
fatal "#{errors.length} problems detected:\n #{errors.join("\n ")}"
|
67
|
+
elsif not warnings.empty?
|
68
|
+
warn "#{warnings.length} potential problems detected:\n #{warnings.join("\n ")}"
|
69
|
+
else
|
70
|
+
puts green("No problems detected in project: #{project}")
|
71
|
+
if ENV['RAILS_ENV'] != "staging"
|
72
|
+
puts "please run it on the staging server by typing `cap shell` and then `bard check [PROJECT_NAME]`"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Micah Geisel
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- features/support/grit_ext.rb
|
136
136
|
- features/support/io.rb
|
137
137
|
- lib/bard.rb
|
138
|
+
- lib/bard/check.rb
|
138
139
|
- lib/bard/git.rb
|
139
140
|
- lib/bard/io.rb
|
140
141
|
- spec/bard_spec.rb
|