Rakefile
My goal for this site is to make it as easy for me to use as possible. That’s why I’m using Jekyll (which I’ll blog about another time). I also want to automate as much of the blogging, version control, and deployment as possible. Up until today I was using a simple rsync alias to get the new files on the “live” hosted server. But I thought it would be more fun and more convenient to have a little more automation, so I scoured GitHub for some good examples and found one written by Scott Kyle, which I took and modified.
My favorite part is the rake deploy command. If I have uncommitted changes in the site repo, it’ll abort the Rake operation and open GitX so I can commit my recent work. If everything is committed, it’ll build the files, run git push, and then do the rsync update.
1 # Adapted from Scott Kyle's Rakefile
2 # http://github.com/appden/appden.github.com/blob/master/Rakefile
3
4 task :default => :server
5
6 desc 'Build site with Jekyll'
7 task :build do
8 jekyll '--no-server --no-auto'
9 end
10
11 desc 'Build and start server with --auto'
12 task :server do
13 jekyll '--server --auto'
14 end
15
16 desc 'git commit or push'
17 task :gitx do
18 xed = false
19 IO.popen('git status') do |io|
20 io.each_line do |line|
21 if ( line =~ /^#\s*modified:/ && !xed ) then
22 sh 'gitx'
23 xed = true
24 raise "\n!!! Do a git commit first !!!\n\n"
25 end
26 end
27 end
28 if ( !xed ) then
29 sh 'git push'
30 puts "Committed files were pushed"
31 end
32 end
33
34 desc 'Build and deploy'
35 task :deploy => [:build, :gitx] do
36 sh 'rsync -auz --progress _site/ uname@server:/path/to/file/'
37 end
38
39 def jekyll(opts = '')
40 sh 'rm -rf _site'
41 sh 'jekyll ' + opts
42 end