Permalink
Browse files

Add a buildable mixin

  • Loading branch information...
1 parent 146282f commit a76964f368f5aec837223117ca91a0a743e52a68 @foca foca committed May 8, 2009
Showing with 91 additions and 47 deletions.
  1. +11 −39 README.rdoc
  2. +1 −0 lib/bob.rb
  3. +70 −0 lib/bob/buildable.rb
  4. +2 −0 test/helper/buildable_stub.rb
  5. +4 −5 test/scm/git_test.rb
  6. +3 −3 test/scm/svn_test.rb
View
@@ -1,52 +1,24 @@
= Bob the Builder
-Given a Buildable object with the following public API:
-
-* <tt>buildable.kind</tt>
-
- Should return a Symbol with whatever kind of repository the buildable's code is
- in (:git, :svn, etc).
-
-* <tt>buildable.uri</tt>
-
- Returns a string like "git://github.com/integrity/bob.git", pointing to the code
- repository.
-
-* <tt>buildable.branch</tt>
-
- What branch of the repository should we build?
-
-* <tt>buildable.build_script</tt>
-
- Returns a string containing the build script to be run when "building".
-
-* <tt>buildable.start_building(commit_id)</tt>
-
- `commit_id` is a String that contains whatever is appropriate for the repo type,
- so it would be a SHA1 hash for git repos, or a numeric id for svn, etc. This is a
- callback so the buildable can determine how long it takes to build. It doesn't
- need to return anything.
-
-* <tt>buildable.finish_building(commit_id, build_status, build_output)</tt>
-
- Callback for when the build finishes. It doesn't need to return anything. It will
- receive a string with the commit identifier, a boolean for the build exit status
- (true for successful builds, false fore failed ones) and a string with the build
- output (both STDOUT and STDERR).
+Given a Buildable object with a determined API (described in it's documentation),
+Bob will, when called like:
- A successful build is one where the build script returns a zero status code.
+ Bob.build(buildable, commit_id) # or Bob.build(buildable, [commit_id, commit_id, ...])
-Bob will, when called like:
+or from your buildable (if you are using the Bob::Buildable mixin provided) as:
- Bob.build(buildable, commit_id)
+ buildable.build(commit_id) # or buildable.build([commit_id, commit_id, ...])
1. Checkout the buildable on the specified commit
-2. Call <tt>buildable.start_building</tt>
-3. Run the script provided in <tt>build_script</tt> in the buildable.
-4. When the build process finishes, it will call <tt>finish_building</tt> with
+2. Call <tt>Buildable#start_building</tt>
+3. Run the script provided in <tt>Buildable#build_script</tt> in the buildable.
+4. When the build process finishes, it will call <tt>Buildable#finish_building</tt> with
the commit_id, the build status (true if the script returns a status code
of 0, false otherwise), and a string with the build output (both STDOUT and STDERR).
+If you pass an array of commits, the steps 1-4 will be repeated for each commit provided,
+in order.
+
== Do I need this?
Probably not. Check out integrity[http://integrityapp.com] for a full fledged
View
@@ -4,6 +4,7 @@
require "time"
require "addressable/uri"
+require "bob/buildable"
require "bob/builder"
require "bob/scm"
require "bob/background_engines"
View
@@ -0,0 +1,70 @@
+module Bob
+ # Mixin to add to your classes.
+ module Buildable
+ # Builds the list of commits you pass. You must provide an
+ # enumerable with commit identifiers appropriate to the
+ # repository the code is in (SHAs if git, rev numbers if svn,
+ # etc), or a single string with a commit id.
+ def build(commits)
+ Bob.build(self, commits)
+ end
+
+ # What kind of repository this buildable represents. Must
+ # return a Symbol (:git, :svn, etc.)
+ #
+ # <b>You must implement this in the classes where you mixin this module</b>
+ def kind
+ raise NotImplementedError
+ end
+
+ # Full URI to the repository to clone/checkout.
+ #
+ # <b>You must implement this in the classes where you mixin this module</b>
+ def uri
+ raise NotImplementedError
+ end
+
+ # Branch of the code you want to watch in order to build.
+ #
+ # <b>You must implement this in the classes where you mixin this module</b>
+ def branch
+ raise NotImplementedError
+ end
+
+ # Script that will be run in the buildable's checked out code,
+ # if it returns a status code of 0 it will be considered a
+ # successfull build. Else it will be considered a failed build.
+ #
+ # <b>You must implement this in the classes where you mixin this module</b>
+ def build_script
+ raise NotImplementedError
+ end
+
+ # Callback sent when a build starts. The first argument is a
+ # string with whatever identifier is appropriate for a repository
+ # of this kind. The second is a hash with information about the
+ # commit.
+ #
+ # <tt>:author</tt>:: A string with the name/email of the committer
+ # <tt>:message</tt>:: The commit message
+ # <tt>:committed_at</tt>:: A Time object with the timestamp of the
+ # commit
+ #
+ # <b>You must implement this in the classes where you mixin this module</b>
+ def start_building(commit_id, commit_info)
+ raise NotImplementedError
+ end
+
+ # Callback sent after a build finishes. The first argument is a
+ # string with whatever identifier is appropriate for a respository
+ # of this kind. The second is a boolean which is true if the build
+ # was successful or false if it failed. And the last one is a string
+ # with the full output returned by the build process (STDOUT and
+ # STDERR interleaved)
+ #
+ # <b>You must implement this in the classes where you mixin this module</b>
+ def finish_building(commit_id, build_status, build_output)
+ raise NotImplementedError
+ end
+ end
+end
@@ -23,6 +23,7 @@ def finish_building(commit_id, status, output)
class GitBuildableStub
include BuildableStub
+ include Bob::Buildable
def kind
:git
@@ -39,6 +40,7 @@ def branch
class SvnBuildableStub
include BuildableStub
+ include Bob::Buildable
def kind
:svn
@@ -4,7 +4,7 @@ class BobGitTest < Test::Unit::TestCase
def setup
super
- @repo = GitRepo.new(:test_repo)
+ @repo = GitRepo.new(:test_repo)
@repo.create
@buildable = GitBuildableStub.new(@repo)
@@ -15,7 +15,7 @@ def setup
commit_id = repo.commits.first[:identifier]
- Bob.build(buildable, commit_id)
+ buildable.build(commit_id)
status, output = buildable.builds[commit_id]
assert_equal :successful, status
@@ -33,7 +33,7 @@ def setup
commit_id = repo.commits.first[:identifier]
- Bob.build(buildable, commit_id)
+ buildable.build(commit_id)
status, output = buildable.builds[commit_id]
assert_equal :failed, status
@@ -48,9 +48,8 @@ def setup
test "with multiple commits" do
2.times { repo.add_failing_commit }
- commits = repo.commits.collect { |c| c[:identifier] }
- Bob.build(buildable, commits)
+ buildable.build(repo.commits.collect { |c| c[:identifier] })
assert_equal 2, commits.length
assert_equal 2, buildable.metadata.length
@@ -13,7 +13,7 @@ def setup
test "with a successful build" do
repo.add_successful_commit
- Bob.build(buildable, "2")
+ buildable.build("2")
assert_equal 1, buildable.metadata.length
@@ -32,7 +32,7 @@ def setup
repo.add_failing_commit
commit_id = repo.commits.first[:identifier]
- Bob.build(buildable, commit_id)
+ buildable.build(commit_id)
status, output = buildable.builds[commit_id]
assert_equal :failed, status
@@ -49,7 +49,7 @@ def setup
repo.add_successful_commit
2.times { repo.add_failing_commit }
- Bob.build(buildable, repo.commits.collect { |c| c[:identifier] })
+ buildable.build(repo.commits.collect { |c| c[:identifier] })
assert_equal 3, buildable.metadata.length
assert_equal 3, buildable.builds.length

0 comments on commit a76964f

Please sign in to comment.