Code tagged with subversion
Even though Capistrano “tags” each release by creating a new folder on the production server(s), it might be interesting to have a historical perspective in your repository anyway.
This makes it easier to know exactly what went up for a release.
I would like to share the following Capistrano recipe for your pleasure:
config/deploy.rb
require 'uri'
task :after_deploy do
source = repository
dest = URI.parse(repository).merge("../releases/#{File.basename(release_path)}")
cmd = "svn copy --revision=#{revision} --quiet --message \"Auto tagging release #{release_path}\" #{source} #{dest}"
puts cmd
`#{cmd}`
end
First, we start by requiring uri, because Subversion does not like relative URLs.
Next, we find the location into which to tag the release, and finally, we just do it.
Simple, effective.
Enjoy !
require 'fileutils'
puts "########################################"
puts "This script creates a new rails project and do the initial svn import with ignoring/deleting files from subversion"
puts "Please send your feedback to Akhil Bansal"
puts "I have tested this script and it works great on my system."
puts ""
puts ""
puts " ###### ATTENTION #######"
puts ""
puts ""
puts "Use this script at your own risk, if your computer explodes its not my fault :-) "
puts "#######################################"
puts "Enter svn username: "
username = gets.strip
puts "Enter the svn url: "
svn_url =gets.strip
puts "Enter Rails Application Path:(eg: /home/akhil/ror): "
app_path = gets.strip
puts "Enter Application Name: "
app_name = gets.strip
puts "######################################"
puts "Please verify the following variables: "
puts "Svn Username: #{username}"
puts "Svn URL: #{svn_url}"
puts "Application Path: #{app_path}"
puts "Application name: #{app_name}"
puts "Proceed (y/n)"
proceed = gets
proceed = proceed.strip.upcase
if proceed == 'N'
puts "Terminating..."
exit 0
elsif proceed == 'Y'
if system("rails -v")
s="/"
elsif system("rails.cmd -v")
s="\\"
else
puts "Cannot find rails. Terminating..."
exit 0
end
app_root=app_path+s+ app_name
puts "Generating rails project: (#{app_root})"
if system("rails #{app_root}")
s="/"
elsif system("rails.cmd #{app_root}")
s="\\"
else
puts "Cannot create rails project. Terminating..."
exit 0
end
puts "SVNinitial import: "
system("svn import #{app_root} #{svn_url} -m \"Initial Import\" --username #{username}")
FileUtils.remove_dir(app_root, true)
puts "Checking out from svn: "
system("svn checkout #{svn_url} #{app_root}")
FileUtils.cd(app_root, :verbose => true)
puts "Removing all log files from SVN"
system("svn remove log"+s+"*")
puts "commiting..."
system("svn commit -m \"removing all log files from subversion \" ")
puts "Ignoring all log files under log dir"
system("svn propset svn:ignore \"*.log\" log"+s)
puts "Updating and commiting..."
system("svn update log"+s)
system("svn commit -m \"Ignoring all files in "+s+"log"+s+" ending in .log \" ")
puts "Removing tmp directory from SVN"
system("svn remove tmp"+s)
puts "commiting..."
system("svn commit -m \"removing the temp directory from subversion \" ")
puts "Ignoring tmp dir"
system("svn propset svn:ignore \"*\" tmp"+s)
puts "Updating and commiting again...."
system("svn update tmp"+s)
system("svn commit -m \"Ignore the whole tmp"+s+" directory, might not work on subdirectories? \" ")
puts "Moving database.yml to database.example"
system("svn move config"+s+"database.yml config"+s+"database.example")
puts "commiting..."
system("svn commit -m \"Moving database.yml to database.example to provide a template for anyone who checks out the code \" ")
puts "Ignoring database.yml , updating and commiting..."
system("svn propset svn:ignore 'database.yml' config"+s)
system("svn update config"+s)
system("svn commit -m \"Ignoring database.yml\" ")
puts "Finished."
else
puts "Unknown Input. Terminating..."
exit 0
end
If you’ve ever been working on a Rails application and found yourself [stupidly] slipping in your testing, I have just the tool for you.
Using rake and rubyosa, you can now automatically post your Code to Test Ratio as your iChat status message—meaning you can now use shame and self-humiliation to keep you motivated.
After you’ve installed rubyosa, add shame.rake to your lib/tasks directory. The file contains:
require 'rbosa'
require 'code_statistics'
task :shame do
stats = CodeStatistics.new(*STATS_DIRECTORIES)
code = stats.send :calculate_code
tests = stats.send :calculate_tests
ichat = OSA.app('ichat')
msg = "Code To Test Ratio: 1:#{sprintf("%.1f", tests.to_f/code)}"
ichat.status_message = msg
$stderr.puts %|iChat status set to: #{msg.inspect}|
end
The most common problems Rails developers have with versioning their project are the config/database.yml file and log/ folder. Personally, I have found that doc/appdoc/ and doc/apidoc/ sometimes gets in the way. More on that later.
The following essay discusses how I manage my Rails projects with Subversion. It is assumed you already know about Rails and how to create new Rails applications. I also assume you have a working knowledge of Subversion. If you need help on using Subversion itself, you should really read one of these two books, ideally both:
* Version Control with Subversion
* Pragmatic Version Control using Subversion
If you are on a Windows machine, most of the commands will work as is. Notable exceptions are those that use the backquote (`), find, grep and the yes commands.