@@ -8,6 +8,7 @@ require 'net/telnet'
8
8
require 'stringio'
9
9
require 'fileutils'
10
10
require 'open-uri'
11
+ require 'git'
11
12
12
13
include Rake ::DSL
13
14
@@ -50,6 +51,7 @@ $DEBUG = orig_verbose != Rake::FileUtilsExt::DEFAULT
50
51
$DEBUG = true if ENV [ 'debug' ] == 'true'
51
52
52
53
verbose ( $DEBUG)
54
+ @git = Git . open ( __dir__ )
53
55
54
56
def java_version
55
57
File . foreach ( 'java/version.bzl' ) do |line |
@@ -538,6 +540,11 @@ namespace :node do
538
540
desc 'Release Node npm package'
539
541
task deploy : :release
540
542
543
+ desc 'Generate Node documentation — currently not working'
544
+ task :docs , [ :skip_update ] do |_task , arguments |
545
+ puts "WARNING — Cannot currently update API Docs for JavaScript bindings"
546
+ end
547
+
541
548
desc 'Update Node version'
542
549
task :version , [ :version ] do |_task , arguments |
543
550
old_version = node_version
@@ -579,7 +586,7 @@ namespace :py do
579
586
end
580
587
581
588
desc 'Generate Python documentation'
582
- task :docs do
589
+ task :docs , [ :skip_update ] do | _task , arguments |
583
590
FileUtils . rm_rf ( 'build/docs/api/py/' )
584
591
FileUtils . rm_rf ( 'build/docs/doctrees/' )
585
592
begin
@@ -588,6 +595,11 @@ namespace :py do
588
595
puts 'Ensure that tox is installed on your system'
589
596
raise
590
597
end
598
+
599
+ unless arguments [ :skip_update ]
600
+ puts "Updating Python documentation"
601
+ puts update_gh_pages ? "Python Docs updated!" : "Python Doc update cancelled"
602
+ end
591
603
end
592
604
593
605
desc 'Install Python wheel locally'
@@ -645,10 +657,15 @@ namespace :rb do
645
657
end
646
658
647
659
desc 'Generate Ruby documentation'
648
- task :docs do
660
+ task :docs , [ :skip_update ] do | _task , arguments |
649
661
FileUtils . rm_rf ( 'build/docs/api/rb/' )
650
662
Bazel . execute ( 'run' , [ ] , '//rb:docs' )
651
663
FileUtils . cp_r ( 'bazel-bin/rb/docs.rb.sh.runfiles/selenium/docs/api/rb/.' , 'build/docs/api/rb' )
664
+
665
+ unless arguments [ :skip_update ]
666
+ puts "Updating Ruby documentation"
667
+ puts update_gh_pages ? "Ruby Docs updated!" : "Ruby Doc update cancelled"
668
+ end
652
669
end
653
670
654
671
desc 'Update Ruby version'
@@ -701,7 +718,8 @@ namespace :dotnet do
701
718
end
702
719
703
720
desc 'Generate .NET documentation'
704
- task :docs do
721
+ task :docs , [ :skip_update ] do |_task , arguments |
722
+ FileUtils . rm_rf ( 'build/docs/api/dotnet/' )
705
723
begin
706
724
sh 'dotnet tool update -g docfx'
707
725
rescue StandardError
@@ -716,11 +734,16 @@ namespace :dotnet do
716
734
when 127
717
735
raise 'Ensure the dotnet/tools directory is added to your PATH environment variable (e.g., `~/.dotnet/tools`)'
718
736
when 255
719
- puts 'Build failed, likely because of DevTools namespacing. This is ok; continuing'
737
+ puts '.NET documentation build failed, likely because of DevTools namespacing. This is ok; continuing'
720
738
else
721
739
raise
722
740
end
723
741
end
742
+
743
+ unless arguments [ :skip_update ]
744
+ puts "Updating .NET documentation"
745
+ puts update_gh_pages ? ".NET Docs updated!" : ".NET Doc update cancelled"
746
+ end
724
747
end
725
748
726
749
desc 'Update .NET version'
@@ -765,7 +788,14 @@ namespace :java do
765
788
task install : :'maven-install'
766
789
767
790
desc 'Generate Java documentation'
768
- task docs : :javadocs
791
+ task :docs , [ :skip_update ] do |_task , arguments |
792
+ Rake ::Task [ 'javadocs' ] . invoke
793
+
794
+ unless arguments [ :skip_update ]
795
+ puts "Updating Java documentation"
796
+ puts update_gh_pages ? "Java Docs updated!" : "Java Doc update cancelled"
797
+ end
798
+ end
769
799
770
800
desc 'Update Maven dependencies'
771
801
task :update do
@@ -839,10 +869,16 @@ end
839
869
namespace :all do
840
870
desc 'Update all API Documentation'
841
871
task :docs do
842
- Rake ::Task [ 'java:docs' ] . invoke
843
- Rake ::Task [ 'py:docs' ] . invoke
844
- Rake ::Task [ 'rb:docs' ] . invoke
845
- Rake ::Task [ 'dotnet:docs' ] . invoke
872
+ FileUtils . rm_rf ( 'build/docs/api' ) if Dir . exist? ( 'build/docs/api' )
873
+
874
+ Rake ::Task [ 'java:docs' ] . invoke ( true )
875
+ Rake ::Task [ 'py:docs' ] . invoke ( true )
876
+ Rake ::Task [ 'rb:docs' ] . invoke ( true )
877
+ Rake ::Task [ 'dotnet:docs' ] . invoke ( true )
878
+ Rake ::Task [ 'node:docs' ] . invoke ( true )
879
+
880
+ puts "Updating All API Docs"
881
+ puts update_gh_pages ? "AP Docs updated!" : "API Doc update cancelled"
846
882
end
847
883
848
884
desc 'Build all artifacts for all language bindings'
@@ -910,3 +946,76 @@ def updated_version(current, desired = nil)
910
946
end
911
947
version . join ( '.' )
912
948
end
949
+
950
+ def update_gh_pages
951
+ origin_reference = @git . current_branch
952
+ origin_reference ||= begin
953
+ # This allows updating docs from a tagged commit instead of a branch
954
+ puts "commit is not at HEAD, checking for matching tag"
955
+ tag = @git . tags . detect { |tag | tag . sha == @git . revparse ( "HEAD" ) }
956
+ tag ? tag . name : raise ( StandardError , "Must be on a tagged commit or at the HEAD of a branch to update API Docs" )
957
+ end
958
+
959
+ puts "Checking out gh-pages"
960
+ begin
961
+ @git . checkout ( 'gh-pages' )
962
+ rescue Git ::FailedError => ex
963
+ # This happens when the working directory is not clean and things need to be stashed or committed
964
+ line = ex . message . lines [ 2 ] . gsub ( "output: \" error: " , '' )
965
+ puts line . gsub ( '\t' , "\t " ) . split ( '\n' ) [ 0 ...-2 ] . join ( "\n " )
966
+ # TODO: we could offer to automatically fix with a stash, but there may be edge cases
967
+ print "Manually Fix and Retry? (Y/n):"
968
+ response = STDIN . gets . chomp . downcase
969
+ return false unless response == 'y' || response == 'yes'
970
+
971
+ retry
972
+ end
973
+
974
+ puts "Updating gh-pages branch from upstream repository"
975
+ begin
976
+ @git . pull
977
+ rescue Git ::FailedError => ex
978
+ # This happens when upstream is not already set
979
+ line = ex . message . lines [ 2 ] . gsub ( "output: \" error: " , '' )
980
+ puts line . gsub ( '\t' , "\t " ) . split ( '\n' ) . delete_if ( &:empty? ) [ -2 ...-1 ] . join ( "\n " )
981
+ print "Manually Fix and Retry? (Y/n):"
982
+ response = STDIN . gets . chomp . downcase
983
+ return restore_git ( origin_reference ) unless response == 'y' || response == 'yes'
984
+
985
+ retry
986
+ end
987
+
988
+ %w[ java rb py dotnet ] . each do |language |
989
+ if Dir . exist? ( "build/docs/api/#{ language } " ) && !Dir . empty? ( "build/docs/api/#{ language } " )
990
+ puts "Deleting #{ language } directory in docs/api since corresponding directory in build/docs/api is not empty"
991
+ FileUtils . rm_rf ( "docs/api/#{ language } " )
992
+ puts "Moving documentation files from untracked build directory to tracked docs directory"
993
+ FileUtils . mv ( "build/docs/api/#{ language } " , "docs/api/#{ language } " )
994
+ end
995
+ end
996
+
997
+ puts "Staging changes for commit"
998
+ @git . add ( 'docs/api' , all : true )
999
+
1000
+ print 'Do you want to commit the changes? (Y/n): '
1001
+ response = STDIN . gets . chomp . downcase
1002
+ return restore_git ( origin_reference ) unless response == 'y' || response == 'yes'
1003
+
1004
+ puts "Committing changes"
1005
+ @git . commit ( 'updating all API docs' )
1006
+
1007
+ puts "Pushing changes to upstream repository"
1008
+ @git . push
1009
+
1010
+ puts "Checking out originating branch/tag — #{ origin_reference } "
1011
+ @git . checkout ( origin_reference )
1012
+ true
1013
+ end
1014
+
1015
+ def restore_git ( origin_reference )
1016
+ puts "Stashing docs changes for gh-pages"
1017
+ Git ::Stash . new ( @git , "docs changes for gh-pages" )
1018
+ puts "Checking out originating branch/tag — #{ origin_reference } "
1019
+ @git . checkout ( origin_reference )
1020
+ false
1021
+ end
0 commit comments