From 83f21964508638bdd623a7d5f7efe54f682ef4de Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Sat, 26 Feb 2022 19:39:10 -0600
Subject: [PATCH 3/6] cirrus: upload changed html docs as artifacts

Always run doc build; to allow 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 | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index 72671a66eda..1bb6463cb84 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -559,7 +559,7 @@ task:
 
 
 ###
-# Verify docs can be built
+# Verify docs can be built, and (only on cfbot) upload changed docs as artifacts
 ###
 
 task:
@@ -570,7 +570,7 @@ task:
     BUILD_JOBS: 1
 
   only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*(docs|html).*'
-  #skip: "!changesInclude('.cirrus.yml', 'doc/**')"
+  #skip: "!changesInclude('.cirrus.yml', 'doc/**', 'src/tools/ci/copy-changed-docs')"
 
   container:
     image: $CONTAINER_REPO/linux_debian_bullseye_ci:latest
@@ -583,8 +583,27 @@ task:
     cat /proc/cmdline
     ulimit -a -H && ulimit -a -S
     export
+    git diff --name-only HEAD~
 
   # Exercise HTML and other docs:
   docs_build_script: |
+    #git diff --name-only --cherry-pick --exit-code postgres/master... doc && exit
     time ./configure
     make -s -j${BUILD_JOBS} -C doc
+    cp -rl doc new-docs
+
+    # Build HTML docs from the previous commit.  This logic is sufficient for cfbot, but not otherwise.
+    #echo "$CIRRUS_CHANGE_TITLE" |grep -Ev '^\[CF [0-9]+/[0-9]+\]' >/dev/null && echo skipping && exit
+    git log -1 --format='%an' |grep -Fxv 'Commitfest Bot' >/dev/null && echo skipping && exit
+    git checkout HEAD~ -- doc
+    make -s -C doc clean
+    make -s -C doc html
+    cp -rl doc old-docs
+
+  copy_changed_docs_script: |
+    #echo "$CIRRUS_CHANGE_TITLE" |grep -Ev '^\[CF [0-9]+/[0-9]+\]' >/dev/null && echo skipping && exit
+    git log -1 --format='%an' |grep -Fxv 'Commitfest Bot' >/dev/null && echo skipping && exit
+    src/tools/ci/copy-changed-docs
+
+  html_docs_artifacts:
+    paths: ['html_docs/**/*.html', 'html_docs/**/*.png', 'html_docs/**/*.css']
-- 
2.17.1

