Skip to content

Commit 9678cc6

Browse files
committed
📚 Add "rake ghpages" for publishing rdoc
https://ruby.github.io/net-imap is now configured to automatically publish the docs directory of the gh-pages branch. This is the current version of the rake task I used to create that branch. This (or something like it) should be able to run from a Github action, to automatically update after every new release is tagged. But it can be run manually until that is set up. There are probably better ways to post the latest documentation to https://ruby.github.io/net-imap, so this may be just a temporary solution.
1 parent fff6dc6 commit 9678cc6

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

rakelib/ghpages.rake

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# frozen_string_literal: true
2+
3+
task :ghpages do
4+
docd = ENV["RDOC_BRANCH"] or abort "Usage: rake ghpages RDOC_BRANCH=<git-ref>"
5+
pages = ENV["RDOC_PAGES_BRANCH"] || "gh-pages"
6+
7+
version = IO.popen(%w[git describe] << docd, &:read).chomp \
8+
and $?.success? && !version.empty? \
9+
or abort "ERROR: could not discover version."
10+
11+
`git status --porcelain`.empty? or abort "ERROR: Working copy must be clean."
12+
13+
when_writing "Preparing #{pages} branch" do
14+
sh "git", "switch", pages
15+
sh "git rev-parse @{u}"
16+
end
17+
18+
when_writing "Updating #{pages} branch to #{docd} => #{version}" do
19+
# simulating `git merge -d theirs`
20+
sh "git", "reset", "--hard", docd
21+
sh "git reset --soft @{u}"
22+
sh "git rev-parse #{docd} > .git/MERGE_HEAD"
23+
end
24+
25+
when_writing "Updating #{pages} branch with documentation from #{docd}" do
26+
# running inside another rake process, in case something important has
27+
# changed between the invocation branch and the documented branch.
28+
Bundler.with_original_env do
29+
sh "bundle check || bundle install"
30+
sh "bundle exec rake"
31+
sh "bundle exec rake rerdoc"
32+
end
33+
rm_rf "docs"
34+
mv "doc", "docs"
35+
touch "docs/.nojekyll" # => skips default pages action build step
36+
sh "git add --force --all docs"
37+
end
38+
39+
when_writing "Committing #{pages} changes for #{version}" do
40+
sh "git", "commit", "-m", "Generated rdoc html for #{version}"
41+
puts "*** Latest changes committed. Deploy with 'git push origin HEAD'"
42+
end
43+
end

0 commit comments

Comments
 (0)