Skip to content

Commit

Permalink
[Rakefile] Add release task
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopelosin committed May 23, 2013
1 parent 6166ab8 commit 89cf54c
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 8 deletions.
19 changes: 16 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
.*.sw?
.rbenv-version
*.gem
*.rbc
.bundle
.config
.yardoc
doc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
95 changes: 91 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,103 @@

desc 'Run specs'
task :spec do
sh "bacon #{specs('**')}"
end

task :default => :spec

#-----------------------------------------------------------------------------#

desc 'Generate yardoc'
task :doc do
sh "rm -rf yardoc"
sh "yardoc"
end

desc 'Run specs'
task :spec do
sh "bacon #{specs('**')}"
#-----------------------------------------------------------------------------#

namespace :bundler do
require "bundler/gem_tasks"
end

task :default => :spec
#-----------------------------------------------------------------------------#

desc "Run all specs, build and install gem, commit version change, tag version change, and push everything"
task :release do

unless ENV['SKIP_CHECKS']
if `git symbolic-ref HEAD 2>/dev/null`.strip.split('/').last != 'master'
$stderr.puts "[!] You need to be on the `master' branch in order to be able to do a release."
exit 1
end

if `git tag`.strip.split("\n").include?(gem_version)
$stderr.puts "[!] A tag for version `#{gem_version}' already exists. Change the version in lib/claide.rb"
exit 1
end

puts "You are about to release `#{gem_version}', is that correct? [y/n]"
exit if $stdin.gets.strip.downcase != 'y'

diff_lines = `git diff --name-only`.strip.split("\n")

diff_lines.delete('Gemfile.lock')
diff_lines.delete('Changelog.md')
if diff_lines != ['lib/claide.rb']
$stderr.puts "[!] Only change the version number in a release commit!"
$stderr.puts diff_lines
exit 1
end
end

require 'date'

# Ensure that the branches are up to date with the remote
sh "git pull"

puts "* Running specs"
silent_sh('rake spec')

tmp = File.expand_path('../tmp', __FILE__)
tmp_gems = File.join(tmp, 'gems')

Rake::Task['bundler:build'].invoke

puts "* Testing gem installation (tmp/gems)"
silent_sh "rm -rf '#{tmp}'"
silent_sh "gem install --install-dir='#{tmp_gems}' #{gem_pkg_path}"

# Then release
sh "git commit lib/claide.rb -m 'Release #{gem_version}'"
sh "git tag -a #{gem_version} -m 'Release #{gem_version}'"
sh "git push origin master"
sh "git push origin --tags"

Rake::Task['bundler:release'].invoke

end

#-----------------------------------------------------------------------------#

def gem_version
require File.expand_path('../lib/claide', __FILE__)
CLAide::VERSION
end

def gem_pkg_path
"pkg/claide-#{gem_version}.gem"
end

def silent_sh(command)
output = `#{command} 2>&1`
unless $?.success?
puts output
exit 1
end
output
end

def specs(dir)
FileList["spec/#{dir}/*_spec.rb"].shuffle.join(' ')
end

1 change: 0 additions & 1 deletion claide.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ require 'claide'
Gem::Specification.new do |s|
s.name = "claide"
s.version = CLAide::VERSION
s.date = Date.today
s.license = "MIT"
s.email = ["eloy.de.enige@gmail.com", "fabiopelosin@gmail.com"]
s.homepage = "https://github.com/CocoaPods/CLAide"
Expand Down

0 comments on commit 89cf54c

Please sign in to comment.