Skip to content

Commit e76fe0c

Browse files
committed
Rake task to update gh-pages without having another checkout
1 parent 15a2f99 commit e76fe0c

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

Rakefile

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
require 'nanoc3/tasks'
22

3-
desc "compile and copy output to ../developer.github.pages"
43
task :publish => [:clean] do
54
sh "nanoc compile"
6-
sh "cp -r output/ ../developer.github.pages"
5+
6+
# this should not be necessary, but I can't figure out how to
7+
# just keep a goddamn static file in the root with nanoc
8+
File.open("output/CNAME", 'w+') do |f|
9+
f.puts("developer.github.com")
10+
end
11+
12+
ENV['GIT_DIR'] = File.expand_path(`git rev-parse --git-dir`.chomp)
13+
old_sha = `git rev-parse refs/remotes/origin/gh-pages`.chomp
14+
Dir.chdir('output') do
15+
ENV['GIT_INDEX_FILE'] = gif = '/tmp/dev.gh.i'
16+
ENV['GIT_WORK_TREE'] = Dir.pwd
17+
File.unlink(gif) if File.file?(gif)
18+
`git add -A`
19+
tsha = `git write-tree`.strip
20+
puts "Created tree #{tsha}"
21+
if old_sha.size == 40
22+
csha = `echo 'boom' | git commit-tree #{tsha} -p #{old_sha}`.strip
23+
else
24+
csha = `echo 'boom' | git commit-tree #{tsha}`.strip
25+
end
26+
puts "Created commit #{csha}"
27+
puts `git show #{csha} --stat`
28+
puts "Updating gh-pages from #{old_sha}"
29+
`git update-ref refs/heads/gh-pages #{csha}`
30+
`git push origin gh-pages`
31+
end
732
end

0 commit comments

Comments
 (0)