Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cpjolicoeur/cerberus
Browse files Browse the repository at this point in the history
  • Loading branch information
cpjolicoeur committed Mar 20, 2010
2 parents 2f19c2e + 1a3490d commit 3b10f2c
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 10 deletions.
9 changes: 7 additions & 2 deletions Changelog.txt
@@ -1,5 +1,11 @@
= Cerberus Changelog

== Version 0.7.1
New configuration options for publisher

* added "extra_subject" publisher option
* added Mercurial SCM support

== Version 0.7
New config options, Bazaar SCM support, removed GMailer bugfixes

Expand All @@ -8,8 +14,7 @@ New config options, Bazaar SCM support, removed GMailer bugfixes
* removed GMailer library. Use default Mail publisher instead
* added 'build_dir' option for setting custom build directory
* added 'setup_script' option for a custom script to be run before build command
* Projects using the Git SCM were not getting the full diff output in their
Publishers
* Projects using the Git SCM were not getting the full diff output in their Publishers

== Version 0.6
New Ruby builder, bugfixes, and refactoring
Expand Down
3 changes: 2 additions & 1 deletion Copyright.txt
Expand Up @@ -13,4 +13,5 @@ Niklas Koponen
Mike Gunderloy
Joe Van Dyk
Andrew Timberlake
Paul Hinze
Paul Hinze
McClain Looney
2 changes: 2 additions & 0 deletions Rakefile
Expand Up @@ -3,6 +3,7 @@ require 'rake'
require 'rake/testtask'
require 'rake/packagetask'
require 'rake/gempackagetask'
require 'rake/clean'

require './lib/cerberus/constants'

Expand All @@ -25,6 +26,7 @@ Rake::TestTask.new(:test) do |t|
t.verbose = true
end

CLEAN.include %w(**/*~)
desc "Clean all generated files"
task :clean => :clobber_package do
root = File.dirname(__FILE__)
Expand Down
3 changes: 2 additions & 1 deletion Readme.markdown
Expand Up @@ -87,6 +87,7 @@ Cerberus currently supports the following SCM tools:
* Perforce
* CVS
* Bazaar
* Mercurial

Cerberus currently supports the following notification systems:

Expand Down Expand Up @@ -126,7 +127,7 @@ is included in the License.txt file.


[1]:http://www.martinfowler.com/articles/continuousIntegration.html
[2]:http://wiki.github.com/cpjolicoeur/cerberusci
[2]:http://wiki.github.com/cpjolicoeur/cerberus
[3]:http://groups.google.com/group/cerberusci
[4]:http://cpjolicoeur.lighthouseapp.com/projects/22299-cerberus
[5]:http://rubyforge.org/frs/?group_id=1794
Expand Down
4 changes: 4 additions & 0 deletions Todo.txt
Expand Up @@ -12,6 +12,9 @@
* make --verbose option work with all SCM, Builders and Publishers
* update rake builder to only check exit status or aborted msg
* Add smart algorithm for calculating of person's name who broke release
* update Rakefile
* move away from using meta_project gem to package and release source
* add "file" Builder to create raw txt file output
* Add on_success on_failure and on_finish options to builders
* Allow cerberus to run in daemon mode as a long running process instead of running via CRON

Expand All @@ -20,6 +23,7 @@
| WISH LIST |
=============

* Create "cerberus_web" to view Cerberus output from a website
* Make possibility to run tests for all revisions (not only latest for that moment)
* Send svn log not only for latest revision but from latest successfull. For that we need to store version of latest successful rev.
* IRC: make message colorized. Make messages shorter to avoid irc flood (and ban to user)
Expand Down
1 change: 1 addition & 0 deletions doc/site/src/credits.page
Expand Up @@ -18,3 +18,4 @@ The following people made notable contributions to the Cerberus tool:
* [Joe Van Dyk](http://fixieconsulting.com/) - Git SCM cleanup
* [Andrew Timberlake](http://ramblingsonrails.com) - Custom build script support
* [Paul Hinze](http://phinze.com/) - Bazaar SCM support
* [McClain Looney](http://github.com/mlooney) - Mercurial Support
3 changes: 2 additions & 1 deletion doc/site/src/index.page
Expand Up @@ -7,7 +7,7 @@ sort_info: 1

Cerberus is a lightweight and easy-to-use Continuous Builder software for Ruby. It could be run periodically from a scheduler and check if application tests are broken. In case of failed tests Cerberus sends notification to developers.

Cerberus works perfectly both on Windows and \*nix platforms and supports popular version control systems like Subversion, Git, Darcs and Perforce. It also has many ways in publishing build results such as e-mail, jabber, [Twitter](http://twitter.com), [Campfire](http://www.campfirenow.com), IRC and RSS files.
Cerberus works perfectly both on Windows and \*nix platforms and supports popular version control systems like Subversion, Git, Mercurial, Bazaar, Darcs and Perforce. It also has many ways in publishing build results such as e-mail, jabber, [Twitter](http://twitter.com), [Campfire](http://www.campfirenow.com), IRC and RSS files.

Cerberus requires:

Expand All @@ -18,6 +18,7 @@ Optional requirements:
* [rake](http://rubyforge.org/projects/rake) - 0.7 or higher
* [subversion](http://subversion.tigris.org/)
* [git](http://git.or.cz)
* [mercurial](http://mercurial.selenic.com/)
* [bazaar](http://bazaar-vcs.org/)
* [darcs](http://darcs.net/) client - 1.0.7 or higher
* [bjam](http://www.boost.org/tools/build/v2/index.html)
Expand Down
5 changes: 4 additions & 1 deletion lib/cerberus/component_lazy_loader.rb
Expand Up @@ -6,7 +6,8 @@ module SCM
:perforce => 'Perforce',
:cvs => 'CVS',
:bzr => 'Bazaar',
:git => 'Git'
:git => 'Git',
:hg => 'Mercurial'
}

def self.get(type)
Expand All @@ -30,6 +31,8 @@ def self.guess_type(path)
'bzr'
when test(?d, path+'/.git')
'git'
when test(?d, path+'/.hg')
'hg'
end
else
#guess SCM type by its url
Expand Down
1 change: 1 addition & 0 deletions lib/cerberus/config.example.yml
Expand Up @@ -23,6 +23,7 @@ publisher:
# url: http://someemail:password@cerberustool.campfirenow.com/room/51660
# rss:
# file: /usr/www/rss.xml
# extra_subject: "#deployment #tags"
#builder:
# rake:
# task: migrate test
Expand Down
2 changes: 1 addition & 1 deletion lib/cerberus/constants.rb
Expand Up @@ -4,5 +4,5 @@ module Cerberus

LOCK_WAIT = 30 * 60 # 30 minutes

VERSION = '0.7'
VERSION = '0.7.1'
end
2 changes: 1 addition & 1 deletion lib/cerberus/publisher/base.rb
Expand Up @@ -32,7 +32,7 @@ def self.formatted_message(state, manager, options)
raise "Unknown build state '#{state.current_state.to_s}'"
end

subject = "[#{options[:application_name]}] #{subject}"
subject = "[#{options[:application_name]}]#{options[:publisher, :extra_subject]} #{subject}"
generated_by = "--\nThis email generated by Cerberus tool ver. #{Cerberus::VERSION}, http://cerberus.rubyforge.org/"
body = [ manager.scm.last_commit_message ]
if options[:changeset_url]
Expand Down
87 changes: 87 additions & 0 deletions lib/cerberus/scm/hg.rb
@@ -0,0 +1,87 @@
require 'cerberus/utils'
require 'cerberus/scm/base'

class Cerberus::SCM::Mercurial < Cerberus::SCM::Base

def installed?
exec_successful? "#{@config[:bin_path]}hg --version"
end

def update!
@new =false
if test( ?d, File.join( @path,'.hg' ) )
r = get_localrev
get_updates
r_new = get_localrev
@has_changes = r_new !=r
else
FileUtils.rm_rf(@path) if test(?d, @path)
encoded_url = (@config[:scm, :url].include?(' ') ? "\"#{@config[:scm, :url]}\"" : @config[:scm, :url])
@new = true
@has_changes = true
@status = execute("clone", "#{encoded_url} #{@path}", false)
if branch = @config[:scm, :branch]
execute('update', "-C #{branch}")
end
end
extract_commit_info if @has_changes
end

def has_changes?
@has_changes
end


def new?
@new
end

def current_revision
@revision
end

def last_commit_message
@message
end

def last_author
@author
end

def output
@status
end

private
def get_localrev
execute("id", '-i').strip
end

def get_updates
execute("pull", '-u')
end

def remote_head
branch = @config[:scm, :branch] || 'default'
end

def execute(command, parameters = nil, with_path = true)
if with_path
cmd = "cd #{@config[:application_root]} && #{@config[:bin_path]}hg #{command} #{parameters}"
else
cmd = "#{@config[:bin_path]}hg #{command} #{parameters}"
end
`#{cmd}`
end

def extract_commit_info( branch='default' )
message = execute("log", "-b #{ branch } -r tip --template '{author}|{date|shortdate}|{node}|{desc}'").split("|")
m= { :author => message.shift, :date => message.shift, :revision => message.shift, :message => message.shift }
@message = m[:message]
@author = m[:author]
@date = m[:date]
@revision = m[:revision]
m
end

end
Binary file added test/data/mercurial.zip
Binary file not shown.
64 changes: 64 additions & 0 deletions test/functional_test.rb
Expand Up @@ -330,6 +330,70 @@ def test_ok
build.run
assert_equal false, build.scm.has_changes?
end

def test_mercurial
add_application('hgapp', HG_URL, :scm => {:type => 'hg'})

build = Cerberus::BuildCommand.new('hgapp')
build.run
assert build.scm.has_changes?
assert_equal 1, ActionMailer::Base.deliveries.size #first email that project was setup
mail = ActionMailer::Base.deliveries[0]
output = mail.body

#Check output that run needed tasks
assert_match /1 tests, 1 assertions, 0 failures, 0 errors/, output
assert output !~ /Task 'custom1' has been invoked/
assert_match /\[hgapp\] Cerberus set up for project/, mail.subject

status_file = HOME + '/work/hgapp/status.log'
assert File.exists?(status_file)
assert build_successful?(status_file)
assert 1, Dir[HOME + "/work/hgapp/logs/*.log"].size

#There were no changes - no reaction should be
build = Cerberus::BuildCommand.new('hgapp')
build.run
assert_equal false, build.scm.has_changes?
assert_equal 1, ActionMailer::Base.deliveries.size #first email that project was setup
assert 1, Dir[HOME + "/work/hgapp/logs/*.log"].size

#now we add new broken test
rand_val = rand(10000)
test_case_name = "test/#{rand_val}_test.rb"
File.open(HG_REPO + '/' + test_case_name, 'w') { |f|
f << %Q( require 'test/unit'
class A#{rand_val}Test < Test::Unit::TestCase
def test_ok
assert false
end
end )
}

curr_dir = Dir.pwd
Dir.chdir HG_REPO
`hg add #{test_case_name}`
`hg commit -m 'somepatch'`
Dir.chdir curr_dir

build = Cerberus::BuildCommand.new('hgapp')
build.run
assert build.scm.has_changes?
assert_equal 2, ActionMailer::Base.deliveries.size #first email that project was setup plus new alert email
assert 2, Dir[HOME + "/work/hgapp/logs/*.log"].size

build = Cerberus::BuildCommand.new('hgapp')
build.run
assert_equal false, build.scm.has_changes?
assert_equal 2, ActionMailer::Base.deliveries.size #first email that project was setup
assert 2, Dir[HOME + "/work/hgapp/logs/*.log"].size

#Now we broke remote repository (imitate that network unaccessable)
FileUtils.rm_rf HG_REPO
build = Cerberus::BuildCommand.new('hgapp')
build.run
assert_equal false, build.scm.has_changes?
end

def test_campfire_publisher
# there were not any messages causing login/password is incorrect. We just check that there was no any exceptions
Expand Down
5 changes: 3 additions & 2 deletions test/mail_publisher_test.rb
Expand Up @@ -11,7 +11,8 @@ def setup

def test_publisher
options = Cerberus::Config.new(nil, :publisher => {
:mail => {:recipients => 'anatol.pomozov@hello.com', :sender => "cerberus@example.com", :delivery_method => 'test'}},
:mail => {:recipients => 'anatol.pomozov@hello.com', :sender => "cerberus@example.com", :delivery_method => 'test'},
:extra_subject => "[#deployment]"},
:application_name => 'MyApp')
build = DummyManager.new('last message', 'this is output', 1232, 'anatol')

Expand All @@ -21,6 +22,6 @@ def test_publisher
assert_equal 1, mails.size
mail = mails[0]
assert_equal 'cerberus@example.com', mail.from_addrs[0].address
assert_equal '[MyApp] Cerberus set up for project (1232)', mail.subject
assert_equal '[MyApp][#deployment] Cerberus set up for project (1232)', mail.subject
end
end
13 changes: 13 additions & 0 deletions test/test_helper.rb
Expand Up @@ -21,6 +21,9 @@ class Test::Unit::TestCase

GIT_REPO = TEMP_DIR + '/git_repo'
GIT_URL = 'file:///' + GIT_REPO.gsub(/\\/,'/').gsub(/^\//,'').gsub(' ', '%20')

HG_REPO = TEMP_DIR + '/hg_repo'
HG_URL = 'file:///' + HG_REPO.gsub(/\\/, '/').gsub(/^\//, '').gsub(' ', '%20')

def self.refresh_repos
# setup base subversion repos
Expand Down Expand Up @@ -50,6 +53,16 @@ def self.refresh_repos
zf.extract(e, fpath)
}
}

# setup base hg repos
FileUtils.mkpath HG_REPO
Zip::ZipFile::open("#{File.dirname(__FILE__)}/data/mercurial.zip") { |zf|
zf.each { |e|
fpath = File.join(HG_REPO, e.name)
FileUtils.mkdir_p(File.dirname(fpath))
zf.extract(e, fpath)
}
}
end

refresh_repos
Expand Down

0 comments on commit 3b10f2c

Please sign in to comment.