Skip to content

Commit

Permalink
[build] update rakefile to generate commits per language for document…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
titusfortner committed Jun 21, 2024
1 parent 03d5789 commit 90e3f12
Showing 1 changed file with 10 additions and 80 deletions.
90 changes: 10 additions & 80 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,7 @@ namespace :node do
raise
end

unless arguments[:skip_update]
puts 'Updating JavaScript documentation'
puts update_gh_pages ? 'JavaScript Docs updated!' : 'JavaScript Doc update cancelled'
end
update_gh_pages unless arguments[:skip_update]
end

desc 'Update JavaScript changelog'
Expand Down Expand Up @@ -563,10 +560,7 @@ namespace :py do
raise
end

unless arguments[:skip_update]
puts 'Updating Python documentation'
puts update_gh_pages ? 'Python Docs updated!' : 'Python Doc update cancelled'
end
update_gh_pages unless arguments[:skip_update]
end

desc 'Install Python wheel locally'
Expand Down Expand Up @@ -700,10 +694,7 @@ namespace :rb do
FileUtils.mkdir_p('build/docs/api')
FileUtils.cp_r('bazel-bin/rb/docs.sh.runfiles/_main/docs/api/rb/.', 'build/docs/api/rb')

unless arguments[:skip_update]
puts 'Updating Ruby documentation'
puts update_gh_pages ? 'Ruby Docs updated!' : 'Ruby Doc update cancelled'
end
update_gh_pages unless arguments[:skip_update]
end

desc 'Update Ruby changelog'
Expand Down Expand Up @@ -810,10 +801,7 @@ namespace :dotnet do
end
end

unless arguments[:skip_update]
puts 'Updating .NET documentation'
puts update_gh_pages ? '.NET Docs updated!' : '.NET Doc update cancelled'
end
update_gh_pages unless arguments[:skip_update]
end

desc 'Update .NET changelog'
Expand Down Expand Up @@ -896,10 +884,7 @@ namespace :java do
task :docs, [:skip_update] do |_task, arguments|
Rake::Task['javadocs'].invoke

unless arguments[:skip_update]
puts 'Updating Java documentation'
puts update_gh_pages ? 'Java Docs updated!' : 'Java Doc update cancelled'
end
update_gh_pages unless arguments[:skip_update]
end

desc 'Update Maven dependencies'
Expand Down Expand Up @@ -1013,16 +998,13 @@ end
namespace :all do
desc 'Update all API Documentation'
task :docs do
FileUtils.rm_rf('build/docs/api')

Rake::Task['java:docs'].invoke(true)
Rake::Task['py:docs'].invoke(true)
Rake::Task['rb:docs'].invoke(true)
Rake::Task['dotnet:docs'].invoke(true)
Rake::Task['node:docs'].invoke(true)

puts 'Updating All API Docs'
puts update_gh_pages ? 'AP Docs updated!' : 'API Doc update cancelled'
update_gh_pages
end

desc 'Build all artifacts for all language bindings'
Expand Down Expand Up @@ -1052,7 +1034,7 @@ namespace :all do
Rake::Task['rb:release'].invoke(*args)
Rake::Task['dotnet:release'].invoke(*args)
Rake::Task['node:release'].invoke(*args)
Rake::Task['all:docs'].invoke

Rake::Task['all:version'].invoke('nightly')

puts 'Committing nightly version updates'
Expand Down Expand Up @@ -1164,70 +1146,18 @@ def updated_version(current, desired = nil, nightly = nil)
end
end

# TODO: make this less insane
# rubocop:disable all
def update_gh_pages
origin_reference = @git.current_branch
origin_reference ||= begin
# This allows updating docs from a tagged commit instead of a branch
puts 'commit is not at HEAD, checking for matching tag'
tag = @git.tags.detect { |t| t.sha == @git.revparse('HEAD') }
tag ? tag.name : raise(StandardError, 'Must be on a tagged commit or at the HEAD of a branch to update API Docs')
end

puts 'Checking out gh-pages'
begin
@git.checkout('gh-pages')
rescue Git::FailedError => e
# This happens when the working directory is not clean and things need to be stashed or committed
line = e.message.lines[2].gsub('output: "error: ', '')
puts line.gsub('\t', "\t").split('\n')[0...-2].join("\n")
# TODO: we could offer to automatically fix with a stash, but there may be edge cases
print 'Manually Fix and Retry? (Y/n):'
response = $stdin.gets.chomp.downcase
return false unless %w[y yes].include?(response)

retry
end

puts 'Updating gh-pages branch from upstream repository'
begin
@git.pull
rescue Git::FailedError => e
# This happens when upstream is not already set
line = e.message.lines[2].gsub('output: "error: ', '')
puts line.gsub('\t', "\t").split('\n').delete_if(&:empty?)[-2...-1].join("\n")
print 'Manually Fix and Retry? (Y/n):'
response = $stdin.gets.chomp.downcase
return restore_git(origin_reference) unless %w[y yes].include?(response)

retry
end
@git.checkout('gh-pages')

%w[java rb py dotnet javascript].each do |language|
next unless Dir.exist?("build/docs/api/#{language}") && !Dir.empty?("build/docs/api/#{language}")

puts "Deleting #{language} directory in docs/api since corresponding directory in build/docs/api is not empty"
FileUtils.rm_rf("docs/api/#{language}")
puts 'Moving documentation files from untracked build directory to tracked docs directory'
FileUtils.mv("build/docs/api/#{language}", "docs/api/#{language}")
end

print 'Do you want to commit the changes? (Y/n): '
response = $stdin.gets.chomp.downcase
return restore_git(origin_reference) unless %w[y yes].include?(response)

puts 'Committing changes'
commit!('updating all API docs', ['docs/api/'])

puts 'Pushing changes to upstream repository'
@git.push

puts "Checking out originating branch/tag — #{origin_reference}"
@git.checkout(origin_reference)
true
commit!("updating #{language} API docs", ["docs/api/#{language}/"])
end
end
# rubocop:disable all

def restore_git(origin_reference)
puts 'Stashing docs changes for gh-pages'
Expand Down

0 comments on commit 90e3f12

Please sign in to comment.