Skip to content

Instantly share code, notes, and snippets.

@knewter
Created March 28, 2013 18:49
Show Gist options
  • Save knewter/5265784 to your computer and use it in GitHub Desktop.
Save knewter/5265784 to your computer and use it in GitHub Desktop.
Just a lil' release.rb script I have for a project I work on
#!/usr/bin/env ruby
begin
class VersionAlreadyTaggedError < StandardError; end
class UncommittedFilesError < StandardError; end
class UnstagedFilesError < StandardError; end
# Get VERSION file contents
version = File.read('VERSION').chomp
# Check to see if this version has already been tagged
exists = `git tag -l|grep v#{version}`.chomp != ""
if(exists)
raise VersionAlreadyTaggedError
end
# Check to see if there are any uncommitted files. No releasing with that sir!
uncommitted_files = `git status|grep "Changes to be committed"`.chomp != ""
if(uncommitted_files)
raise UncommittedFilesError
end
unstaged_files = `git status|grep "Changes not staged for commit"`.chomp != ""
if(unstaged_files)
raise UnstagedFilesError
end
# Merge development into master
STDOUT.puts "Merging development into master"
`git checkout master`
`git merge development`
`git push origin master`
# Tag this release and push it
version = "v#{version}" # We prefix versions with "v"
STDOUT.puts "Tagging version #{version}"
`git tag -a #{version} -m"Tagging version #{version}"`
STDOUT.puts "Pushing tags"
`git push origin --tags`
STDOUT.puts "Version #{version} has been released!"
# Check out development
STDOUT.puts "Checking out development branch"
`git checkout development`
# Error handling down below, if you hit one of these you weren't successful at
# releasing
rescue VersionAlreadyTaggedError
STDOUT.puts "This version has already been released. Please update the VERSION file, commit it, and try again."
rescue UncommittedFilesError
STDOUT.puts "There are some uncommitted files. Please check those in and try again."
rescue UnstagedFilesError
STDOUT.puts "There are some unstaged files. Please commit them or stash them and try again."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment