Beaten to the punch, and a request

I'm wrapping up a tutorial on Rake for IBM (but probably won't be published
for 2-3 months), and I wanted to make a request to the community. Does
anyone have an interesting, useful rake task or rule they'd be interested in
sharing? I'd like to include a short cookbook at the end of the article with
some example code and explanations. You'll get credit in the text if I end up
using your code (or build something based on it). You can respond to me off
list if you like, but it might make for an interesting discussion here.

···

--
thanks,
-pate
-------------------------
We are often unable to tell people what they need to know, because
they want to know something else, and would therefore only
misunderstand what we said
- the Raven (George MacDonald, Lilith)

pat eyler wrote:

I'm wrapping up a tutorial on Rake for IBM (but probably won't be published
for 2-3 months), and I wanted to make a request to the community. Does anyone have an interesting, useful rake task or rule they'd be interested in
sharing? I'd like to include a short cookbook at the end of the article with
some example code and explanations. You'll get credit in the text if I end up
using your code (or build something based on it). You can respond to me off
list if you like, but it might make for an interesting discussion here.

Hey bud,

How's the new job going ?

Where did you get positioned ??? Still in Seattle?

Anyways, just shoutin' to my homie.

Ciao for now.

j.

pat eyler <pat.eyler@gmail.com> writes:

I'm wrapping up a tutorial on Rake for IBM (but probably won't be published
for 2-3 months), and I wanted to make a request to the community. Does
anyone have an interesting, useful rake task or rule they'd be interested in
sharing? I'd like to include a short cookbook at the end of the article with
some example code and explanations. You'll get credit in the text if I end up
using your code (or build something based on it). You can respond to me off
list if you like, but it might make for an interesting discussion here.

I made Rake package my software with help from darcs:

  PROJECT = "mycoolapp"

  desc "Do predistribution stuff"
  task :predist => [:chmod, :changelog, :doc]
  
  desc "Make an archive as .tar.gz"
  task :dist => :test do
    system "export DARCS_REPO=#{File.expand_path "."}; " +
           "darcs dist -d #{PROJECT}#{get_darcs_tree_version}"
  end
  
  desc "Make binaries executable"
  task :chmod do
    Dir["bin/*"].each { |binary| File.chmod(0775, binary) }
  end
  
  desc "Generate a ChangeLog"
  task :changelog do
    system "darcs changes --repo=#{ENV["DARCS_REPO"] || "."} >ChangeLog"
  end
  
  # Helper to retrieve the "revision number" of the darcs tree.
  def get_darcs_tree_version
    return "" unless File.directory? "_darcs"
  
    changes = `darcs changes`
    count = 0
    tag = "0.0"
    
    changes.each("\n\n") { |change|
      head, title, desc = change.split("\n", 3)
      
      if title =~ /^ \*/
        # Normal change.
        count += 1
      elsif title =~ /tagged (.*)/
        # Tag. We look for these.
        tag = $1
        break
      else
        warn "Unparsable change: #{change}"
      end
    }
  
    "-#{tag}.#{count}"
  end

I set the darcs preferences to call "rake predist" after checking out,
so I can just run "rake dist" and quickly get a packaged version of my
project, named after the last tag (I use version numbers for those,
0.1, 0.2 etc.) and the number of patches following it; it includes
rdoc HTML, a Changelog and has permissions set right.

Nothing revolutionary, but very useful.

···

thanks,
-pate

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org

pat eyler <pat.eyler@gmail.com> writes:

I'm wrapping up a tutorial on Rake for IBM (but probably won't be
published
for 2-3 months), and I wanted to make a request to the community. Does
anyone have an interesting, useful rake task or rule they'd be
interested in
sharing? I'd like to include a short cookbook at the end of the
article with
some example code and explanations. You'll get credit in the text if I
end up
using your code (or build something based on it). You can respond to me
off
list if you like, but it might make for an interesting discussion here.

I think the release task in the RubyGems Rakefile is moderately
interesting. When we are ready to do a new release of the RubyGems
software, all we type is:

   rake release REL=0.8.13

It will

* check for proper release numbers,
* make sure there is no outstanding checkins,
* run the unit and functional tests
  (and abort the release if there are any failures),
* update the release number embeded in the code
  (and check _that_ in),
* create the package tar and zip files (and the upgrade gem)
* tag the CVS version with the release number.

Now that we have MetaProject (formally XForge), we could have it
automatically upload the files to RubyForge as well.

You can view the entire Rakefile here:

http://rubyforge.org/cgi-bin/viewcvs.cgi/rubygems/Rakefile?rev=1.54&cvsroot=rubygems&content-type=text/vnd.viewcvs-markup

or here is the relevent portion of the file:

# --------------------------------------------------------------------
# Creating a release

desc "Make a new release"
task :release => [
  :prerelease,
  :clobber,
  :alltests,
  :update_version,
  :package,
  :tag] do

  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 = `cvs -q update`
    unless data =~ /^$/
      fail "CVS 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 RubyGem version to #{PKG_VERSION}"
    open("lib/rubygems/rubygems_version.rb", "w") do |f|
      f.puts "# DO NOT EDIT"
      f.puts "# This file is auto-generated by build scripts."
      f.puts "# See: rake update_version"
      f.puts "module Gem"
      f.puts " RubyGemsVersion = '#{PKG_VERSION}'"
      f.puts "end"
    end
    if ENV['RELTEST']
      announce "Release Task Testing, skipping commiting of new version"
    else
      sh %{cvs commit -m "Updated to version #{PKG_VERSION}"
lib/rubygems/rubygems_version.rb}
    end
  end
end

task :tag => [:prerelease] do
  reltag = "REL_#{PKG_VERSION.gsub(/\./, '_')}"
  reltag << ENV['REUSE'].gsub(/\./, '_') if ENV['REUSE']
  announce "Tagging CVS with [#{reltag}]"
  if ENV['RELTEST']
    announce "Release Task Testing, skipping CVS tagging"
  else
    sh %{cvs tag #{reltag}}
  end
end

···

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)