Skip to content

Commit 26b4d74

Browse files
committed
📚 Add "rake ghpages" [🚧 WIP]
There are better ways to post the latest documentation to https://ruby.github.io/net-imap. This is just a temporary solution.
1 parent 023e410 commit 26b4d74

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

rakelib/ghpages.rake

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
task :ghpages do
4+
docd = ENV["RDOC_DOCUMENTED_BRANCH"] || "master"
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 "Updating #{pages} branch to match #{docd} => #{version}" do
14+
system(*%w[git switch], pages) or abort "ERROR: switching to #{pages}"
15+
system(*%w[git reset --hard], docd) or abort "ERROR: setting #{pages} == #{docd}"
16+
system(*%w[git reset --soft @{u}]) or abort "ERROR: setting #{pages} => upstream"
17+
end
18+
19+
when_writing "Updating #{pages} branch with documentation from #{docd}" do
20+
# running inside another rake process, in case something important has
21+
# changed between the invocation branch and the documented branch.
22+
Bundler.with_original_env do
23+
system("bundle install || bundle update kpeg") or abort "ERROR: bundler failed"
24+
system(*%w[bundle exec rake]) or warn "warning: build failed"
25+
system(*%w[bundle exec rake rerdoc]) or abort "ERROR: rdoc generation failed"
26+
end
27+
rm_rf "docs"
28+
mv "doc", "docs"
29+
touch "docs/.nojekyll" # => skips default pages action build step
30+
system(*%w[git add --force --all docs]) or abort "ERROR: adding docs to git"
31+
end
32+
33+
when_writing "Committing #{pages} changes for #{version}" do
34+
commit_msg = "Generated rdoc html for #{version}"
35+
system(*%w[git commit -m], commit_msg) or abort "ERROR: committing #{pages}"
36+
37+
puts "*** Latest changes committed. Deploy with 'git push origin HEAD'"
38+
end
39+
end

0 commit comments

Comments
 (0)