# -*- ruby -*- (Make emacs happy) # Rakefile for enhost begin require 'rubygems' require 'rake/gempackagetask' rescue Exception nil end require 'rake/clean' require 'rake/testtask' require 'rake/rdoctask' #CLEAN.include('**/*.o') CLOBBER.include('doc/*') def announce(msg='') STDERR.puts msg end # Determine the current version if `ruby ./bin/enhost --version` =~ /\S+$/ CURRENT_VERSION = $& else CURRENT_VERSION = "0.0.0" end if ENV['REL'] PKG_VERSION = ENV['REL'] else PKG_VERSION = CURRENT_VERSION end DOWNDIR = "/export/docroots/reductivelabs.com/htdocs/downloads" # The default task is run if rake is given no explicit arguments. desc "Default Task" task :default => :unittests # Test Tasks --------------------------------------------------------- #task :u => :unittests #task :a => :alltests #task :alltests => :unittests #Rake::TestTask.new(:unittests) do |t| # t.test_files = FileList['tests/*.rb'] # t.warning = true # t.verbose = false #end # SVN Tasks ---------------------------------------------------------- # ... none. # Install rake using the standard install.rb script. desc "Install the application" task :install do ruby "install.rb" end # Create a task to build the RDOC documentation tree. rd = Rake::RDocTask.new(:html) { |rdoc| rdoc.rdoc_dir = 'html' rdoc.template = 'html' rdoc.title = "Enhost" rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README' rdoc.rdoc_files.include('README', 'COPYING', 'TODO', 'CHANGELOG') rdoc.rdoc_files.include('bin/enhost') CLEAN.include("html") } # ==================================================================== # Create a task that will package the Rake software into distributable # tar, zip and gem files. PKG_FILES = FileList[ 'install.rb', 'COPYING', 'README', '[A-Z]*', 'bin/**/*', 'test/**/*.rb', 'doc/**/*', 'etc/*' ] PKG_FILES.delete_if {|item| item.include?(".svn")} if ! defined?(Gem) puts "Package Target requires RubyGEMs" else spec = Gem::Specification.new do |s| #### Basic information. s.name = 'enhost' s.version = PKG_VERSION s.summary = "Enhost stores collected facts in LDAP." s.description = <<-EOF Enhost is a simple script to upload facts collected from Facter into LDAP. EOF #### Dependencies and requirements. s.add_dependency('facter', '> 1.1.2') #s.requirements << "" s.files = PKG_FILES.to_a #### Load-time details: library and application (you will need one or both). s.bindir = "bin" # Use these for applications. s.executables = ["enhost"] s.default_executable = "enhost" #### Documentation and testing. s.has_rdoc = true s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a s.rdoc_options << '--title' << 'Enhost' << '--main' << 'README' << '--line-numbers' #### Author and project details. s.author = "Luke Kanies" s.email = "dev@reductivelabs.com" s.homepage = "http://reductivelabs.com/projects/enhost" #s.rubyforge_project = "enhost" end Rake::GemPackageTask.new(spec) do |pkg| #pkg.need_zip = true pkg.need_tar = true end CLEAN.include("pkg") end # Misc tasks ========================================================= #ARCHIVEDIR = '/...' #task :archive => [:package] do # cp FileList["pkg/*.tgz", "pkg/*.zip", "pkg/*.gem"], ARCHIVEDIR #end # Define an optional publish target in an external file. If the # publish.rf file is not found, the publish targets won't be defined. #load "publish.rf" if File.exist? "publish.rf" # Support Tasks ------------------------------------------------------ def egrep(pattern) Dir['**/*.rb'].each do |fn| count = 0 open(fn) do |f| while line = f.gets count += 1 if line =~ pattern puts "#{fn}:#{count}:#{line}" end end end end end desc "Look for TODO and FIXME tags in the code" task :todo do egrep "/#.*(FIXME|TODO|TBD)/" end #desc "Look for Debugging print lines" #task :dbg do # egrep /\bDBG|\bbreakpoint\b/ #end #desc "List all ruby files" #task :rubyfiles do # puts Dir['**/*.rb'].reject { |fn| fn =~ /^pkg/ } # puts Dir['bin/*'].reject { |fn| fn =~ /CVS|(~$)|(\.rb$)/ } #end # -------------------------------------------------------------------- # Creating a release desc "Make a new release" task :release => [ :prerelease, :clobber, :update_version, :tag, :package, :fedorarpm, :copy] do #:alltests, announce announce "**************************************************************" announce "* Release #{PKG_VERSION} Complete." announce "* Packages ready to upload." announce "**************************************************************" announce end # Validate that everything is ready to go for a release. task :prerelease do announce announce "**************************************************************" announce "* Making RubyGem Release #{PKG_VERSION}" announce "* (current version #{CURRENT_VERSION})" announce "**************************************************************" announce # Is a release number supplied? unless ENV['REL'] fail "Usage: rake release REL=x.y.z [REUSE=tag_suffix]" end # Is the release different than the current release. # (or is REUSE set?) if PKG_VERSION == CURRENT_VERSION && ! ENV['REUSE'] fail "Current version is #{PKG_VERSION}, must specify REUSE=tag_suffix to reuse version" end # Are all source files checked in? if ENV['RELTEST'] announce "Release Task Testing, skipping checked-in file test" else announce "Checking for unchecked-in files..." data = `svn -q update` unless data =~ /^$/ fail "SVN update is not clean ... do you have unchecked-in files?" end announce "No outstanding checkins found ... OK" end end task :update_version => [:prerelease] do if PKG_VERSION == CURRENT_VERSION announce "No version change ... skipping version update" else announce "Updating Facter version to #{PKG_VERSION}" open("bin/enhost") do |rakein| open("bin/enhost.new", "w") do |rakeout| rakein.each do |line| if line =~ /^(\s*)ENHOST_VERSION\s*=\s*/ rakeout.puts "#{$1}ENHOST_VERSION = '#{PKG_VERSION}'" else rakeout.puts line end end end end mv "bin/enhost.new", "bin/enhost" open("conf/redhat/enhost.spec") do |rakein| open("conf/redhat/enhost.spec.new", "w") do |rakeout| rakein.each do |line| if line =~ /^Version:\s*/ rakeout.puts "Version: #{PKG_VERSION}" elsif line =~ /^Release:\s*/ rakeout.puts "Release: 1%{?dist}" else rakeout.puts line end end end end mv "conf/redhat/enhost.spec.new", "conf/redhat/enhost.spec" if ENV['RELTEST'] announce "Release Task Testing, skipping commiting of new version" else sh %{svn commit -m "Updated to version #{PKG_VERSION}" bin/enhost} end end end desc "Tag all the SVN files with the latest release number (REL=x.y.z)" task :tag => [:prerelease] do reltag = "REL_#{PKG_VERSION.gsub(/\./, '_')}" reltag << ENV['REUSE'].gsub(/\./, '_') if ENV['REUSE'] announce "Tagging SVN copy with [#{reltag}]" if ENV['RELTEST'] announce "Release Task Testing, skipping SVN tagging" else sh %{svn copy ../trunk/ ../tags/#{reltag}} sh %{cd ../tags; svn ci -m 'Adding Release tag #{reltag}'} end end desc "Copy the newly created package into the downloads directory" task :copy => [:package, :html] do sh %{cp pkg/enhost-#{PKG_VERSION}.gem #{DOWNDIR}/gems} sh %{generate_yaml_index.rb -d #{DOWNDIR}} sh %{cp pkg/enhost-#{PKG_VERSION}.tgz #{DOWNDIR}/enhost} sh %{ln -sf enhost-#{PKG_VERSION}.tgz #{DOWNDIR}/enhost/enhost-latest.tgz} sh %{cp -r html #{DOWNDIR}/enhost/apidocs} sh %{rsync -av /home/luke/rpm/. #{DOWNDIR}/rpm} end desc "SSH to fedora and make the rpm" task :fedorarpm => [:package] do sh %{ssh fedora1 'cd svn/enhost/trunk; rake rpm'} end desc "Create an RPM" task :rpm do tarball = File.join(Dir.getwd, "pkg", "enhost-#{PKG_VERSION}.tgz") sourcedir = `rpm --define 'name enhost' --define 'version #{PKG_VERSION}' --eval '%_sourcedir'`.chomp basedir = File.dirname(sourcedir) FileUtils.mkdir_p(basedir) if ! FileTest::exist?(sourcedir) FileUtils.mkdir_p(sourcedir) end target = "#{sourcedir}/enhost-#{PKG_VERSION}.tgz" sh %{cp -r #{tarball} #{sourcedir}} sh %{cp conf/redhat/enhost.spec %s/enhost.spec} % basedir FileUtils::cd(basedir) system("rpmbuild -ba enhost.spec") end # $Id: Rakefile 35 2006-03-09 06:51:07Z luke $