Skip to content

Commit

Permalink
📚 Add "rake ghpages" [🚧 WIP]
Browse files Browse the repository at this point in the history
There are better ways to post the latest documentation to
https://ruby.github.io/net-imap.  This is just a temporary solution.
  • Loading branch information
nevans committed Dec 1, 2022
1 parent 023e410 commit 26b4d74
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions rakelib/ghpages.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

task :ghpages do
docd = ENV["RDOC_DOCUMENTED_BRANCH"] || "master"
pages = ENV["RDOC_PAGES_BRANCH"] || "gh-pages"

version = IO.popen(%w[git describe] << docd, &:read).chomp \
and $?.success? && !version.empty? \
or abort "ERROR: could not discover version."

`git status --porcelain`.empty? or abort "ERROR: Working copy must be clean."

when_writing "Updating #{pages} branch to match #{docd} => #{version}" do
system(*%w[git switch], pages) or abort "ERROR: switching to #{pages}"
system(*%w[git reset --hard], docd) or abort "ERROR: setting #{pages} == #{docd}"
system(*%w[git reset --soft @{u}]) or abort "ERROR: setting #{pages} => upstream"
end

when_writing "Updating #{pages} branch with documentation from #{docd}" do
# running inside another rake process, in case something important has
# changed between the invocation branch and the documented branch.
Bundler.with_original_env do
system("bundle install || bundle update kpeg") or abort "ERROR: bundler failed"
system(*%w[bundle exec rake]) or warn "warning: build failed"
system(*%w[bundle exec rake rerdoc]) or abort "ERROR: rdoc generation failed"
end
rm_rf "docs"
mv "doc", "docs"
touch "docs/.nojekyll" # => skips default pages action build step
system(*%w[git add --force --all docs]) or abort "ERROR: adding docs to git"
end

when_writing "Committing #{pages} changes for #{version}" do
commit_msg = "Generated rdoc html for #{version}"
system(*%w[git commit -m], commit_msg) or abort "ERROR: committing #{pages}"

puts "*** Latest changes committed. Deploy with 'git push origin HEAD'"
end
end

0 comments on commit 26b4d74

Please sign in to comment.