|
| 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