From 75404cb29b3a93eeaf2d33a4f5ee63c917ad8a6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Thu, 27 Oct 2011 14:20:07 +0200 Subject: [PATCH] improve a bunch of existing rake tasks --- Rakefile | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/Rakefile b/Rakefile index b5f4f952..87a748be 100644 --- a/Rakefile +++ b/Rakefile @@ -4,19 +4,21 @@ require 'rake/testtask' # Helpers # -def command?(command) - `which #{command} 2>/dev/null` - $?.success? +def command?(util) + Rake::Task[:load_path].invoke + context = Object.new + require 'hub/context' + context.extend Hub::Context + context.send(:command?, util) end -task :load_hub do - $LOAD_PATH.unshift 'lib' - require 'hub' +task :load_path do + $LOAD_PATH.unshift File.expand_path('../lib', __FILE__) end task :check_dirty do - if !`git status`.include?('nothing to commit') - abort "dirty index - not publishing!" + unless system 'git', 'diff', '--quiet', 'HEAD' + abort "Aborted: you have uncommitted changes" end end @@ -44,16 +46,16 @@ end # -# Ron +# Manual # if command? :ronn - desc "Show the manual" + desc "Show man page" task :man => "man:build" do exec "man man/hub.1" end - desc "Build the manual" + desc "Build man pages" task "man:build" => ["man/hub.1", "man/hub.1.html"] extract_examples = lambda { |readme_file| @@ -95,17 +97,20 @@ end # -# Gems +# Build # -desc "Build standalone script" -task :standalone => :load_hub do +file "hub" => FileList.new("lib/hub/*.rb", "man/hub.1") do |task| + Rake::Task[:load_path].invoke require 'hub/standalone' - Hub::Standalone.save('hub') + Hub::Standalone.save(task.name) end +desc "Build standalone script" +task :standalone => "hub" + desc "Install standalone script and man pages" -task :install => :standalone do +task :install => "hub" do prefix = ENV['PREFIX'] || ENV['prefix'] || '/usr/local' FileUtils.mkdir_p "#{prefix}/bin" @@ -115,16 +120,19 @@ task :install => :standalone do FileUtils.cp "man/hub.1", "#{prefix}/share/man/man1" end -desc "Publish to GitHub Pages" -task :pages => [ "man:build", :check_dirty, :standalone ] do +desc "Copy files to gh-pages branch, but don't publish" +task :gh_pages => [:check_dirty, "hub", "man/hub.1.html"] do cp "man/hub.1.html", "html" sh "git checkout gh-pages" sh "mv hub standalone" - sh "git add standalone*" sh "mv html hub.1.html" - sh "git add hub.1.html" + sh "git add standalone hub.1.html" sh "git commit -m 'update standalone'" +end + +desc "Publish to GitHub Pages" +task :pages => :gh_pages do sh "git push origin gh-pages" sh "git checkout master" - puts :done + puts "Done." end -- GitLab