Browse code

updated rakefile to support github pages deployments

B Mathis authored on 24/11/2009 at 22:40:47
Showing 1 changed files
... ...
@@ -10,6 +10,14 @@ port = "4000"     # preview project port eg. http://localhost:4000
10 10
 site = "site"     # compiled site directory
11 11
 source = "source" # source file directory
12 12
 
13
+# Github pages deploy config
14
+# For github user pages, use "master"
15
+# For github project pages use "gh-pages"
16
+# If you're not using this, you can remove it
17
+# Read http://pages.github.com for guidance
18
+
19
+github_pages_branch = "gh-pages"
20
+
13 21
 def ok_failed(condition)
14 22
   if (condition)
15 23
     puts "OK"
... ...
@@ -86,11 +94,27 @@ task :watch do
86 86
 end
87 87
 
88 88
 desc "generate and deploy website"
89
-multitask :deploy => [:default, :clean_debug] do
89
+multitask :deploy_rsync => [:default, :clean_debug] do
90 90
   print ">>> Deploying website <<<"
91 91
   ok_failed system("rsync -avz --delete #{site}/ #{ssh_user}:#{document_root}")
92 92
 end
93 93
 
94
+desc "generate and deploy website to github user pages"
95
+multitask :github_user_deploy => [:default, :clean_debug] do
96
+  require 'git'
97
+  repo = Git.open('.')
98
+  repo.branch("#{github_pages_branch}").checkout
99
+  (Dir["*"] - ["#{site}/*"]).each { |f| rm_rf(f) }
100
+  Dir["#{site}/*"].each {|f| mv(f, ".")}
101
+  rm_rf("#{site}/*")
102
+  Dir["**/*"].each {|f| repo.add(f) }
103
+  repo.status.deleted.each {|f, s| repo.remove(f)}
104
+  message = ENV["MESSAGE"] || "Site updated at #{Time.now.utc}"
105
+  repo.commit(message)
106
+  repo.push
107
+  repo.branch("source").checkout
108
+end
109
+
94 110
 desc "start up an instance of serve on the output files"
95 111
 task :start_serve => :stop_serve do
96 112
   cd "#{site}" do