From d0d46260a6e2af5b9cd160d9362c31549e930d2d Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Sat, 15 Jan 2022 11:27:28 -0600
Subject: [PATCH 3/3] cirrus: upload changed html docs as artifacts

Build docs during separate task; to all them to be shown in cfbot, they should
not be skipped if the linux build fails.

This could be done on the client side (cfbot).  One advantage of doing it here
is that fewer docs are uploaded - many patches won't upload docs at all.

https://cirrus-ci.com/task/5396696388599808

ci-os-only: linux
---
 .cirrus.yml | 69 ++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 55 insertions(+), 14 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index ea87c890cc3..7ff8f72937a 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -191,6 +191,7 @@ task:
   configure_script: |
     su postgres <<-EOF
       ./configure \
+        --cache gcc.cache \
         --enable-cassert --enable-debug --enable-tap-tests \
         --enable-nls \
         \
@@ -555,19 +556,59 @@ task:
       make -s -j${BUILD_JOBS} clean
       time make -s -j${BUILD_JOBS} world-bin
 
-  ###
-  # Verify docs can be built
-  ###
-  # XXX: Only do this if there have been changes in doc/ since last build
-  always:
-    docs_build_script: |
-      time ./configure \
-        --cache gcc.cache \
-        CC="ccache gcc" \
-        CXX="ccache g++" \
-        CLANG="ccache clang"
-      make -s -j${BUILD_JOBS} clean
-      time make -s -j${BUILD_JOBS} -C doc
-
   always:
     upload_caches: ccache
+
+
+# Verify docs can be built, and upload changed docs as artifacts
+task:
+  name: HTML docs
+
+  env:
+    CPUS: 1
+
+  only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*(docs|html).*'
+
+  container:
+    image: $CONTAINER_REPO/linux_debian_bullseye_ci:latest
+    cpu: $CPUS
+
+  sysinfo_script: |
+    id
+    uname -a
+    cat /proc/cmdline
+    ulimit -a -H && ulimit -a -S
+    export
+
+    git remote -v
+    git branch -a
+    git remote add postgres https://github.com/postgres/postgres
+    time git fetch -v postgres master
+    git log -1 postgres/master
+    git diff --name-only postgres/master..
+
+  docs_build_script: |
+    # Do nothing if the patch doesn't update doc:
+    git diff --name-only --cherry-pick --exit-code postgres/master... doc && exit
+
+    # Exercise HTML and other docs:
+    ./configure >/dev/null
+    make -s -C doc
+    cp -a doc new-docs
+
+    # Build HTML docs from the parent commit
+    git checkout postgres/master -- doc
+    make -s -C doc clean
+    make -s -C doc html
+    cp -a doc old-docs
+
+    # Copy HTML which differ into html_docs
+    mkdir html_docs
+    cp new-docs/src/sgml/html/*.css new-docs/src/sgml/html/*.svg html_docs/
+    for f in `git diff --no-index --name-only old-docs/src/sgml/html new-docs/src/sgml/html`
+    do
+      cp $f html_docs/
+    done
+
+  html_docs_artifacts:
+    paths: ['html_docs/**/*.html', 'html_docs/**/*.png', 'html_docs/**/*.css']
-- 
2.17.1

