Merge branch '21494-sdk-doc-linkchecker'
[arvados.git] / doc / Rakefile
index 6b1b0d2ac3c0aaef1f77d831020d3e7bf58df4dd..3ec494f57dcffab28248dc827d3cf7f69a1fae82 100644 (file)
@@ -19,6 +19,8 @@
 #
 # and then visit http://localhost:8000 in a browser.
 
+require "uri"
+
 require "rubygems"
 require "colorize"
 
@@ -31,18 +33,30 @@ def can_run?(*command, **options)
 end
 
 class JavaSDK
+  def self.build_path
+    "sdk/java-v2"
+  end
+
   def self.can_build?
     can_run?("gradle", "--version")
   end
 end
 
 class PythonSDK
+  def self.build_path
+    "sdk/python/arvados"
+  end
+
   def self.can_build?
     can_run?("./pysdk_pdoc.py", "--version")
   end
 end
 
 class RSDK
+  def self.build_path
+    "sdk/R"
+  end
+
   def self.can_build?
     can_run?("R", "--version")
   end
@@ -195,15 +209,25 @@ file "sdk/java-v2/javadoc/index.html" do |t|
 end
 
 task :linkchecker => [ :generate ] do
-  if !can_run?("linkchecker", "--version")
-    puts "Warning: linkchecker not found, skipping run".colorize(:light_red)
-    next
-  end
   # we need --check-extern to check relative links, weird but true
-  system(
-    "linkchecker", "index.html", "--check-extern", "--ignore-url=!file://",
+  opts = [
+    "--check-extern",
+    "--ignore-url=!^file://",
+  ]
+  ([JavaSDK, PythonSDK, RSDK] - $build_sdks).map(&:build_path).each do |sdk_path|
+    sdk_url = URI.join(ENV["baseurl"], sdk_path)
+    url_re = Regexp.escape(sdk_url.to_s)
+    opts << "--ignore-url=^#{url_re}[./]"
+  end
+  result = system(
+    "linkchecker", *opts, "index.html",
     chdir: ".site",
-  ) or exit $?.exitstatus
+  )
+  if result.nil?
+    fail "could not run linkchecker command (is it installed?)"
+  elsif !result
+    fail "linkchecker exited #{$?.exitstatus}"
+  end
 end
 
 task :import_vscode_training do