bard 0.4.0 → 0.5.0

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.
@@ -2,14 +2,122 @@
2
2
 
3
3
  This immaculate work of engineering genius allows mere mortals to collaborate with beings of transcendent intelligence like Micah, Michael, and Nick.
4
4
 
5
- == Requirements
6
- gem install thor
7
- gem install systemu
8
- gem install term-ansicolor
9
- gem install git_remote_branch
5
+ === Requirements
10
6
  git --version >= 1.6.0
11
7
 
12
- == Note on Patches/Pull Requests
8
+ === Joining Bard
9
+
10
+ ==== On any platform:
11
+ - gem install gemcutter
12
+ - gem tumble
13
+ - gem install bard
14
+
15
+ ==== On Linux:
16
+
17
+ - Install RubyGems:
18
+ $> wget ...
19
+ $> ...
20
+
21
+ - Install Rake:
22
+ $> sudo gem install rake
23
+ ( NOTE: the sudo )
24
+
25
+ - Install Apache
26
+ $> sudo apt-get install apache2
27
+
28
+ - Install Mysql
29
+ $> sudo apt-get install mysql-server
30
+ $> sudo /etc/init.d/mysql start
31
+ ( No password for root, if it asks )
32
+
33
+ - Install Passenger
34
+ $> sudo gem install passenger
35
+
36
+ $> sudo apt-get install apache2-prefork-dev as root.
37
+ $> sudo apt-get install libapr1-dev as root.
38
+ $> sudo apt-get install libaprutil1
39
+
40
+ $> sudo passenger-install-apache2-module
41
+
42
+ - Setup rails environment:
43
+ Add line to /etc/apache2/apache2.conf:
44
+ RailsEnv development
45
+ $> apache2ctl restart
46
+
47
+ ==== On Mac:
48
+ - ???Wtf ? I dunno. eff macs
49
+
50
+ == Todos
51
+
52
+ === Adding Adva to an exising project
53
+ - Git clone latest tagged release from github
54
+ - Set up integration branch on staging
55
+ - Add as submodule
56
+ - Bard pull will "just work" (tm)
57
+
58
+ === Joining an existing project
59
+ bard join will probably either do all these steps automatically, or help you do them:
60
+ This list summarizes the existing steps needed to join a project.
61
+
62
+ $> bard join <project-name>
63
+
64
+ - Clone the project
65
+ - (git clone staging@staging.botandrose.com:<project-name>)
66
+ - Init and update submodules
67
+
68
+ - Set up local environment:
69
+ - Apache
70
+ Put in /etc/apache2/sites-avaliable/<project-name>:
71
+ <VirtualHost *:80>
72
+ ServerName <project-name>.local
73
+ DocumentRoot $HOME/$BardRoot/<project-name>/public
74
+ </VirtualHost>
75
+
76
+ $> a2ensite <project-name>
77
+ $> apache2ctl restart
78
+
79
+ - Set up /etc/hosts:
80
+ append this line to /etc/hosts:
81
+ 127.0.0.1 <project-name>.local
82
+
83
+ - Setup database yaml
84
+ - sensible default:
85
+ login: &login
86
+ adapter: mysql
87
+ database: <project-name>
88
+ username: root
89
+ password:
90
+ socket: /var/run/mysqld/mysqld.sock
91
+
92
+ development:
93
+ <<: *login
94
+
95
+ test: &TEST
96
+ <<: *login
97
+ database: <project-name>_test
98
+
99
+ cucumber:
100
+ <<: *TEST
101
+
102
+
103
+ - Set up gems:
104
+ $> rake gems:install
105
+
106
+ - Set up database
107
+ $> rake db:create
108
+ $> rake db:migrate
109
+
110
+ - Set up cap:
111
+ $> capify .
112
+ Add line to Capfile:
113
+ load '../cap.tasks'
114
+ Have cap.tasks.rb in your root work directory (eg. $HOME/work/bard )
115
+
116
+ - Seed database from staging
117
+ $> cap data:pull:staging
118
+
119
+
120
+ === Note on Patches/Pull Requests
13
121
 
14
122
  * Fork the project.
15
123
  * Make your feature addition or bug fix.
@@ -22,4 +130,4 @@
22
130
 
23
131
  == Copyright
24
132
 
25
- Copyright (c) 2009 Micah Geisel. See LICENSE for details.
133
+ Copyright (c) 2009 Micah Geisel, Nick Hogle. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bard}
8
- s.version = "0.4.0"
8
+ s.version = "0.5.0"
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"]
12
- s.date = %q{2009-09-30}
12
+ s.date = %q{2009-10-05}
13
13
  s.default_executable = %q{bard}
14
14
  s.description = %q{This immaculate work of engineering genius allows mere mortals to collaborate with beings of transcendent intelligence like Micah, Michael, and Nick.}
15
15
  s.email = %q{info@botandrose.com}
@@ -6,3 +6,79 @@ Feature: Bard can check its environment for missing dependencies and potential p
6
6
  And I should see the current version of git
7
7
  And I should see the current version of rubygems
8
8
  And I should see the current version of ruby
9
+
10
+ Scenario: Bard check examines a local project for problems
11
+ Given a shared rails project
12
+ When I type "bard check ."
13
+ Then I should see "No problems"
14
+
15
+ Scenario: Bard check detects missing database
16
+ Given a shared rails project
17
+ And the database is missing
18
+ When I type "bard check ."
19
+ Then I should see the fatal error "missing database"
20
+
21
+ Scenario: Bard check detects pending migrations
22
+ Given a shared rails project
23
+ And I have committed a set of changes that includes a new migration
24
+ When I type "bard check ."
25
+ Then I should see the fatal error "pending migrations"
26
+
27
+ Scenario: Bard check detects missing config/database.yml
28
+ Given a shared rails project
29
+ And "config/database.yml" is missing
30
+ When I type "bard check ."
31
+ Then I should see the fatal error "missing config/database.yml"
32
+
33
+ Scenario: Bard check detects missing submodules
34
+ Given a shared rails project
35
+ And a submodule
36
+ And the submodule is missing
37
+ When I type "bard check ."
38
+ Then I should see the fatal error "missing submodule"
39
+
40
+ Scenario: Bard check detects missing gems
41
+ Given a shared rails project
42
+ And I have committed a set of changes that adds the test gem as a dependency
43
+ And I dont have the test gem installed
44
+ When I type "bard check ."
45
+ Then I should see the fatal error "missing gems"
46
+
47
+ Scenario: Bard check detects master branch checked out
48
+ Given a shared rails project
49
+ And I am on the master branch
50
+ When I type "bard check ."
51
+ Then I should see the fatal error "master branch"
52
+
53
+ Scenario: Bard check detects missing integration branch
54
+ Given a shared rails project
55
+ And there is no integration branch
56
+ When I type "bard check ."
57
+ Then I should see the fatal error "missing integration branch"
58
+
59
+ Scenario: Bard check detects missing RAILS_ENV environment variable
60
+ Given a shared rails project
61
+ And my "RAILS_ENV" environment variable is ""
62
+ When I type "bard check ."
63
+ Then I should see the warning "RAILS_ENV is not set"
64
+
65
+ Scenario: Bard check detects missing staging hook
66
+ Given a shared rails project
67
+ And my "RAILS_ENV" environment variable is "staging"
68
+ And there is no git hook on the staging server
69
+ When I type "bard check ." on the staging server
70
+ Then I should see the fatal error "missing git hook"
71
+
72
+ Scenario: Bard check detects unexecutable staging hook
73
+ Given a shared rails project
74
+ And my "RAILS_ENV" environment variable is "staging"
75
+ And the git hook on the staging server is not executable
76
+ When I type "bard check ." on the staging server
77
+ Then I should see the fatal error "unexecutable git hook"
78
+
79
+ Scenario: Bard check detects improper staging hook
80
+ Given a shared rails project
81
+ And my "RAILS_ENV" environment variable is "staging"
82
+ And the git hook on the staging server is bad
83
+ When I type "bard check ." on the staging server
84
+ Then I should see the fatal error "improper git hook"
@@ -1,20 +1,65 @@
1
1
  Then /^I should see the current version of bard$/ do
2
2
  version = File.read("#{ROOT}/VERSION").chomp
3
- @stdout.should include "bard (#{version})"
3
+ @stdout.should =~ /bard\s+\(#{Regexp.escape(version)}\)/
4
4
  end
5
5
 
6
6
  Then /^I should see the current version of git$/ do
7
7
  version = `git --version`[/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/]
8
- @stdout.should include "git (#{version})"
8
+ @stdout.should =~ /git\s+\(#{Regexp.escape(version)}\)/
9
9
  end
10
10
 
11
11
  Then /^I should see the current version of rubygems$/ do
12
12
  version = `gem --version`.chomp
13
- @stdout.should include "rubygems (#{version})"
13
+ @stdout.should =~ /rubygems\s+\(#{Regexp.escape(version)}\)/
14
14
  end
15
15
 
16
16
  Then /^I should see the current version of ruby$/ do
17
17
  version = `ruby --version`[/[0-9]+\.[0-9]+\.[0-9]+/]
18
- @stdout.should include "ruby (#{version})"
18
+ @stdout.should =~ /ruby\s+\(#{Regexp.escape(version)}\)/
19
+ end
20
+
21
+ Given /^"([^\"]*)" is missing$/ do |file|
22
+ type "rm #{file}"
23
+ end
24
+
25
+ Given /^the database is missing$/ do
26
+ File.open "config/database.yml", "w" do |f|
27
+ f.puts <<-DB
28
+ development:
29
+ adapter: mysql
30
+ username: root
31
+ password:
32
+ database: bad_bad_bad
33
+ socket: /var/run/mysqld/mysqld.sock
34
+ DB
35
+ end
36
+ end
37
+
38
+ Given /^the submodule is missing$/ do
39
+ type "rm -rf submodule"
40
+ type "mkdir submodule"
41
+ end
42
+
43
+ Given /^my "([^\"]*)" environment variable is "([^\"]*)"$/ do |key, value|
44
+ @env ||= Hash.new
45
+ @env[key] = value
46
+ end
47
+
48
+ Given /^there is no git hook on the staging server$/ do
49
+ Dir.chdir "#{ROOT}/tmp/origin" do
50
+ type "rm .git/hooks/post-receive"
51
+ end
52
+ end
53
+
54
+ Given /^the git hook on the staging server is not executable$/ do
55
+ Dir.chdir "#{ROOT}/tmp/origin" do
56
+ type "chmod 664 .git/hooks/post-receive"
57
+ end
58
+ end
59
+
60
+ Given /^the git hook on the staging server is bad$/ do
61
+ Dir.chdir "#{ROOT}/tmp/origin" do
62
+ type "echo 'bad' > .git/hooks/post-receive"
63
+ end
19
64
  end
20
65
 
@@ -2,6 +2,23 @@ Given /^I am on a non\-integration branch$/ do
2
2
  type "git checkout -b bad_bad_bad"
3
3
  end
4
4
 
5
+ Given /^I am on the master branch$/ do
6
+ type "git checkout master"
7
+ end
8
+
9
+ Given /^there is no integration branch$/ do
10
+ type "git checkout master"
11
+ type "git branch -d integration"
12
+ end
13
+
14
+ Given /^there is no integration branch on the staging server$/ do
15
+ type "git branch -d origin/integration"
16
+ Dir.chdir "#{ROOT}/tmp/origin" do
17
+ type "git checkout master"
18
+ type "git branch -d integration"
19
+ end
20
+ end
21
+
5
22
  Given /^a dirty working directory$/ do
6
23
  File.open("dirty_file", "w") { |f| f.puts "dirty dirty" }
7
24
  end
@@ -29,10 +29,13 @@ BASH
29
29
  end
30
30
 
31
31
  When /^I type "([^\"]*)"$/ do |command|
32
- if command =~ /^bard/
33
- command = "#{ROOT}/bin/#{command}"
32
+ type command.sub /\b(bard)\b/, "#{ROOT}/bin/bard"
33
+ end
34
+
35
+ When /^I type "([^\"]*)" on the staging server$/ do |command|
36
+ Dir.chdir "#{ROOT}/tmp/origin" do
37
+ When %(I type "#{command}")
34
38
  end
35
- type command
36
39
  end
37
40
 
38
41
  Then /^I should see the fatal error "([^\"]*)"$/ do |error_message|
@@ -42,3 +45,7 @@ end
42
45
  Then /^I should see the warning "([^\"]*)"$/ do |warning_message|
43
46
  @stderr.should include(warning_message)
44
47
  end
48
+
49
+ Then /^I should see "([^\"]*)"$/ do |message|
50
+ @stdout.should include(message)
51
+ end
@@ -1,5 +1,5 @@
1
1
  def type(command)
2
- @status, @stdout, @stderr = systemu command
2
+ @status, @stdout, @stderr = systemu command, :env => @env
3
3
  if ENV['DEBUG']
4
4
  puts '-' * 20
5
5
  puts "Executing command: #{command}"
@@ -2,6 +2,7 @@ $:.unshift File.expand_path(File.dirname(__FILE__))
2
2
  require 'term/ansicolor'
3
3
  require 'systemu'
4
4
  require 'grit'
5
+ require 'thor'
5
6
 
6
7
  require 'bard/git'
7
8
  require 'bard/io'
@@ -10,19 +11,23 @@ class Bard < Thor
10
11
  include BardGit
11
12
  include BardIO
12
13
 
13
- desc "check", "check environment for missing dependencies"
14
- def check
15
- required = Hash.new
16
- required['bard'] = `gem list bard --remote`[/[0-9]+\.[0-9]+\.[0-9]+/]
17
- required['git'] = '1.6.0'
18
- required['rubygems'] = '1.3.4'
19
- required['ruby'] = '1.8.6'
20
-
21
- actual = Hash.new
22
- actual['bard'] = `gem list bard`[/[0-9]+\.[0-9]+\.[0-9]+/]
23
- actual['git'] = `git --version`[/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/]
24
- actual['rubygems'] = `gem --version`.chomp
25
- actual['ruby'] = `ruby --version`[/[0-9]+\.[0-9]+\.[0-9]+/]
14
+ desc "check [PROJECT]", "check PROJECT or environment for missing dependencies"
15
+ def check(project = nil)
16
+ return check_project(project) if project
17
+ puts ENV['ASDF']
18
+
19
+ required = {
20
+ 'bard' => `gem list bard --remote`[/[0-9]+\.[0-9]+\.[0-9]+/],
21
+ 'git' => '1.6.0',
22
+ 'rubygems' => '1.3.4',
23
+ 'ruby' => '1.8.6'
24
+ }
25
+ actual = {
26
+ 'bard' => `gem list bard`[/[0-9]+\.[0-9]+\.[0-9]+/],
27
+ 'git' => `git --version`[/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/],
28
+ 'rubygems' => `gem --version`.chomp,
29
+ 'ruby' => `ruby --version`[/[0-9]+\.[0-9]+\.[0-9]+/]
30
+ }
26
31
 
27
32
  %w(bard git rubygems ruby).each do |pkg|
28
33
  if actual[pkg] < required[pkg]
@@ -128,4 +133,40 @@ class Bard < Thor
128
133
  system "touch tmp/restart.txt"
129
134
  end
130
135
  end
136
+
137
+ private
138
+ def check_project(project)
139
+ errors = []
140
+ warnings = []
141
+ Dir.chdir project do
142
+ status, stdout, stderr = systemu "rake db:abort_if_pending_migrations"
143
+ errors << "missing config/database.yml" if stderr.include? "config/database.yml"
144
+ errors << "missing database" if stderr.include? "Unknown database"
145
+ errors << "pending migrations" if stdout.include? "pending migrations"
146
+
147
+ errors << "missing submodule" if `git submodule status` =~ /^-/
148
+ errors << "missing gems" if `rake gems` =~ /\[ \]/
149
+ errors << "you shouldn't be working on the master branch" if `cat .git/HEAD`.include? "refs/heads/master"
150
+ errors << "missing integration branch" if `git branch` !~ /\bintegration\b/
151
+
152
+ if ENV['RAILS_ENV'] == "staging"
153
+ if File.exist? ".git/hooks/post-receive"
154
+ errors << "unexecutable git hook" unless File.executable? ".git/hooks/post-receive"
155
+ errors << "improper git hook" unless File.read(".git/hooks/post-receive").include? "bard stage $@"
156
+ else
157
+ errors << "missing git hook"
158
+ end
159
+ end
160
+
161
+ warnings << "RAILS_ENV is not set" if ENV['RAILS_ENV'].nil? or ENV['RAILS_ENV'].empty?
162
+ end
163
+
164
+ if not errors.empty?
165
+ fatal "#{errors.length} problems detected:\n #{errors.join("\n ")}"
166
+ elsif not warnings.empty?
167
+ warn "#{warnings.length} potential problems detected:\n #{warnings.join("\n ")}"
168
+ else
169
+ puts green("No problems detected in project: #{project}")
170
+ end
171
+ end
131
172
  end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe "Bard" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
3
+ describe Bard do
4
+ it "should work" do
5
+ true
6
6
  end
7
7
  end
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
3
4
  require 'bard'
4
5
  require 'spec'
5
6
  require 'spec/autorun'
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.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-09-30 00:00:00 -07:00
13
+ date: 2009-10-05 00:00:00 -07:00
14
14
  default_executable: bard
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency