Skip to content

Commit

Permalink
log new build (Builder#build) [integrity#20]
Browse files Browse the repository at this point in the history
  • Loading branch information
sr committed Nov 18, 2008
1 parent 66ed544 commit ccb5912
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
5 changes: 5 additions & 0 deletions lib/integrity/builder.rb
Expand Up @@ -13,6 +13,7 @@ def initialize(project)
end

def build(commit)
Integrity.logger.info "Building #{commit} (#{@branch}) of #{@build.project.name} in #{export_directory} using #{scm_name}"
@scm.with_revision(commit) { run_build_script }
@build
ensure
Expand All @@ -32,6 +33,10 @@ def export_directory
Integrity.config[:export_directory] / "#{SCM.working_tree_path(@uri)}-#{@branch}"
end

def scm_name
@scm.name.split("::").last
end

def run_build_script
IO.popen "(cd #{@scm.working_directory} && #{build_script}) 2>&1", "r" do |pipe|
@build.output = pipe.read
Expand Down
2 changes: 1 addition & 1 deletion lib/integrity/scm/git.rb
Expand Up @@ -14,7 +14,7 @@ def initialize(uri, branch, working_directory)
@branch = branch.to_s
@working_directory = working_directory
end

def with_revision(revision)
fetch_code
checkout(revision)
Expand Down
21 changes: 14 additions & 7 deletions spec/builder_spec.rb
Expand Up @@ -4,7 +4,7 @@
def mock_project(messages={})
@project ||= begin
uri = Addressable::URI.parse("git://github.com/foca/integrity.git")
messages = { :uri => uri, :command => "rake", :branch => "master" }.merge(messages)
messages = { :uri => uri, :command => "rake", :branch => "master", :name => "Integrity" }.merge(messages)
mock("project", messages)
end
end
Expand All @@ -26,24 +26,21 @@ def mock_build(messages={})
end

def mock_scm(messages={})
@scm ||= begin
scm = mock "scm", { :with_revision => true }.merge(messages)

@scm ||= mock("scm", {:with_revision => true}.merge(messages)).tap do |scm|
scm.stub!(:commit_identifier).with('6eba34d94b74fe68b96e35450fadf241113e44fc').and_return('6eba34d94b74fe68b96e35450fadf241113e44fc')
scm.stub!(:commit_metadata).with('6eba34d94b74fe68b96e35450fadf241113e44fc').and_return(
:author => 'Simon Rozet <simon@rozet.name>',
:message => 'A commit message',
:date => Time.parse('Mon Jul 21 15:24:34 2008 +0200')
)
scm.stub!(:working_directory).and_return('/var/integrity/exports/foca-integrity')

scm
scm.stub!(:name).and_return("Integrity::SCM::Git")
end
end

before do
Integrity.stub!(:config).and_return(:export_directory => "/var/integrity/exports")
Integrity::Builder.class_eval { public :export_directory, :run_build_script }
Integrity::Builder.class_eval { public :export_directory, :run_build_script, :scm_name }
Integrity::SCM.stub!(:working_tree_path).and_return("foca-integrity")
end

Expand All @@ -67,6 +64,10 @@ def mock_scm(messages={})
@builder = Integrity::Builder.new(mock_project)
end

specify "#scm_name should give the name of the SCM being used" do
@builder.scm_name.should == "Git"
end

describe "Calculating the export directory" do
it "should start with the base export directory set in the global options" do
@builder.export_directory.should =~ %r(^/var/integrity/exports)
Expand All @@ -80,6 +81,12 @@ def mock_scm(messages={})
describe "When building a specific commit" do
before { @builder.stub!(:run_build_script) }

it "should log the build" do
Integrity.logger.should_receive(:info).
with("Building 6eba34d94b74fe68b96e35450fadf241113e44fc (master) of Integrity in /var/integrity/exports/foca-integrity-master using Git")
@builder.build('6eba34d94b74fe68b96e35450fadf241113e44fc')
end

it "should fetch the latest code from the scm and run the build script" do
mock_scm.should_receive(:with_revision).
with('6eba34d94b74fe68b96e35450fadf241113e44fc').and_yield do
Expand Down

0 comments on commit ccb5912

Please sign in to comment.