20259: Add documentation for banner and tooltip features
[arvados.git] / doc / Rakefile
1 #!/usr/bin/env rake
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: CC-BY-SA-3.0
5
6 # As a convenience to the documentation writer, you can touch a file
7 # called 'no-sdk' in the 'doc' directory and it will suppress
8 # generating the documentation for the SDKs, which (the R docs
9 # especially) take a fair bit of time and slow down the edit-preview
10 # cycle.
11 #
12 # To generate and view the documentation locally, run this command
13 #
14 #   rake && sensible-browser .site/index.html
15 #
16 # Or alternatively:
17 #
18 #   baseurl=http://localhost:8000 rake && rake run
19 #
20 # and then visit http://localhost:8000 in a browser.
21
22 require "rubygems"
23 require "colorize"
24
25 module Zenweb
26   class Site
27     @binary_files = %w[png jpg gif eot svg ttf woff2? ico pdf m4a t?gz xlsx]
28   end
29 end
30
31 task :generate => [ :realclean, 'sdk/python/arvados/index.html', 'sdk/R/arvados/index.html', 'sdk/java-v2/javadoc/index.html' ] do
32   vars = ['baseurl', 'arvados_cluster_uuid', 'arvados_api_host', 'arvados_workbench_host']
33   if ! ENV.key?('baseurl') || ENV['baseurl'] == ""
34     if !ENV.key?('WORKSPACE') || ENV['WORKSPACE'] == ""
35       puts "The `baseurl` variable was not specified and the `WORKSPACE` environment variable is not set. Defaulting `baseurl` to file://#{pwd}/.site"
36       ENV['baseurl'] = "file://#{pwd}/.site/"
37     else
38       puts "The `baseurl` variable was not specified, defaulting to a value derived from the `WORKSPACE` environment variable"
39       ENV['baseurl'] = "file://#{ENV['WORKSPACE']}/doc/.site/"
40     end
41   end
42   vars.each do |v|
43     if ENV[v]
44       website.config.h[v] = ENV[v]
45     end
46   end
47 end
48
49 file ["install/new_cluster_checklist_Azure.xlsx", "install/new_cluster_checklist_AWS.xlsx"] do |t|
50   cp(t, t)
51 end
52
53 file "sdk/python/arvados/index.html" do |t|
54   if ENV['NO_SDK'] || File.exists?("no-sdk")
55     next
56   end
57   `which pdoc`
58   if $? == 0
59     STDERR.puts `pdoc --html -o sdk/python ../sdk/python/arvados/ 2>&1`
60     raise if $? != 0
61   else
62     puts "Warning: pdoc3 not found, Python documentation will not be generated".colorize(:light_red)
63   end
64 end
65
66 file "sdk/R/arvados/index.html" do |t|
67   if ENV['NO_SDK'] || File.exists?("no-sdk")
68     next
69   end
70   `which R`
71   if $? == 0
72     tgt = Dir.pwd
73     Dir.mkdir("sdk/R")
74     Dir.mkdir("sdk/R/arvados")
75     puts("tgt", tgt)
76     cp('css/R.css', 'sdk/R/arvados')
77     docfiles = []
78     Dir.chdir("../sdk/R/") do
79       Dir.entries("man").each do |rd|
80         if rd[-3..-1] == ".Rd"
81           htmlfile = "#{rd[0..-4]}.html"
82           `R CMD Rdconv -t html man/#{rd} > #{tgt}/sdk/R/arvados/#{htmlfile}`
83           docfiles << htmlfile
84         end
85       end
86     end
87     raise if $? != 0
88
89     File.open("../sdk/R/README.md", "r") do |rd|
90     File.open("sdk/R/index.html.md", "w") do |fn|
91       fn.write(<<-EOF
92 ---
93 layout: default
94 navsection: sdk
95 navmenu: R
96 title: "R SDK Overview"
97 ...
98
99 #{rd.read}
100 EOF
101               )
102       end
103     end
104
105     File.open("sdk/R/arvados/index.html.textile.liquid", "w") do |fn|
106       fn.write(<<-EOF
107 ---
108 layout: default
109 navsection: sdk
110 navmenu: R
111 title: "R Reference"
112 ...
113 {% comment %}
114 Copyright (C) The Arvados Authors. All rights reserved.
115
116 SPDX-License-Identifier: CC-BY-SA-3.0
117 {% endcomment %}
118
119 EOF
120               )
121
122       docfiles.sort.each do |d|
123         fn.write("* \"#{d[0..-6]}\":#{d}\n")
124       end
125
126     end
127   else
128     puts "Warning: R not found, R documentation will not be generated".colorize(:light_red)
129   end
130 end
131
132 file "sdk/java-v2/javadoc/index.html" do |t|
133   if ENV['NO_SDK'] || File.exists?("no-sdk")
134     next
135   end
136   `which java`
137   if $? == 0
138     `which gradle`
139     if $? != 0
140       puts "Warning: gradle not found, java sdk documentation will not be generated".colorize(:light_red)
141     else
142       tgt = Dir.pwd
143       docfiles = []
144       Dir.chdir("../sdk/java-v2") do
145         STDERR.puts `gradle javadoc 2>&1`
146         raise if $? != 0
147         puts `sed -i "s/@import.*dejavu.css.*//g" build/docs/javadoc/stylesheet.css`
148         raise if $? != 0
149       end
150       cp_r("../sdk/java-v2/build/docs/javadoc", "sdk/java-v2")
151       raise if $? != 0
152     end
153   else
154     puts "Warning: java not found, java sdk documentation will not be generated".colorize(:light_red)
155   end
156 end
157
158 task :linkchecker => [ :generate ] do
159   Dir.chdir(".site") do
160     `which linkchecker`
161     if $? == 0
162       # we need --check-extern to check relative links, weird but true
163       system "linkchecker index.html --check-extern --ignore-url='!file://'" or exit $?.exitstatus
164     else
165       puts "Warning: linkchecker not found, skipping run".colorize(:light_red)
166     end
167   end
168 end
169
170 task :import_vscode_training do
171   Dir.chdir("user") do
172   rm_rf "arvados-vscode-cwl-training"
173   `git clone https://github.com/arvados/arvados-vscode-cwl-training`
174   githash = `git --git-dir arvados-vscode-cwl-training/.git log -n1 --format=%H HEAD`
175   File.open("cwl/arvados-vscode-training.html.md.liquid", "w") do |fn|
176     File.open("arvados-vscode-cwl-training/README.md", "r") do |rd|
177       fn.write(<<-EOF
178 ---
179 layout: default
180 navsection: userguide
181 title: "Developing CWL Workflows with VSCode"
182 ...
183 {% comment %}
184 Copyright (C) The Arvados Authors. All rights reserved.
185
186 SPDX-License-Identifier: CC-BY-SA-3.0
187
188 Imported from https://github.com/arvados/arvados-vscode-cwl-training
189 git hash: #{githash}
190 {% endcomment %}
191
192 EOF
193               )
194                fn.write(rd.read())
195     end
196   end
197   rm_rf "arvados-vscode-cwl-training"
198   end
199 end
200
201 task :clean do
202   rm_rf "sdk/python/arvados"
203   rm_rf "sdk/R"
204   rm_rf "sdk/java-v2/javadoc"
205 end
206
207 require "zenweb/tasks"
208 load "zenweb-textile.rb"
209 load "zenweb-liquid.rb"
210 load "zenweb-fix-body.rb"
211
212 task :extra_wirings do
213   $website.pages["sdk/python/python.html.textile.liquid"].depends_on("sdk/python/arvados/index.html")
214 end