From 83b3b2a340ab3bacdd06baa341fb7b457da1f1b3 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Sat, 29 Dec 2012 16:24:26 -0800 Subject: [PATCH] More robust site:publish. --- Rakefile | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Rakefile b/Rakefile index 3daf6306..ed81f05d 100644 --- a/Rakefile +++ b/Rakefile @@ -133,28 +133,38 @@ namespace :site do sh "cd site && jekyll --server" end - desc "Commit the local site to the gh-pages branch and deploy" + desc "Commit the local site to the gh-pages branch and publish to GitHub Pages" task :publish do # Ensure the gh-pages dir exists so we can generate into it. puts "Checking for gh-pages dir..." unless File.exist?("./gh-pages") puts "No gh-pages directory found. Run the following commands first:" - puts " `git clone git@github.com:mojombo/god gh-pages" + puts " `git clone git@github.com:mojombo/jekyll gh-pages" puts " `cd gh-pages" puts " `git checkout gh-pages`" exit(1) end - # Copy the rest of the site over. - puts "Copying static..." + # Ensure gh-pages branch is up to date. + Dir.chdir('gh-pages') do + sh "git pull origin gh-pages" + end + + # Copy to gh-pages dir. + puts "Copying site to gh-pages branch..." Dir.glob("site/*") do |path| next if path == "_site" sh "cp -R #{path} gh-pages/" end - # Commit the changes + # Commit and push. + puts "Committing and pushing to GitHub Pages..." sha = `git log`.match(/[a-z0-9]{40}/)[0] - sh "cd gh-pages && git add . && git commit -m 'Updating to #{sha}.' && git push" + Dir.chdir('gh-pages') do + sh "git add ." + sh "git commit -m 'Updating to #{sha}.'" + sh "git push origin gh-pages" + end puts 'Done.' end end