From c0c823f393924680880bbbedc16256c6533ff1a8 Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Mon, 28 Feb 2022 23:18:19 -0600
Subject: [PATCH 7/7] f!html: index file

This allows linking to the artifacts from the last successful build, which
itself allows *not* rebuilding when sources haven't changed.

ci/os/only: html
---
 .cirrus.yml                    |  2 +-
 src/tools/ci/copy-changed-docs | 16 ++++++++++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index 48e85b73649..60f1528a9f1 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -628,7 +628,7 @@ task:
     cp -r doc old-docs
 
   copy_changed_docs_script: |
-    src/tools/ci/copy-changed-docs
+    src/tools/ci/copy-changed-docs "$CIRRUS_BRANCH"
 
   html_docs_artifacts:
     paths: ['html_docs/*.html', 'html_docs/*.png', 'html_docs/*.css']
diff --git a/src/tools/ci/copy-changed-docs b/src/tools/ci/copy-changed-docs
index 0a942838f5c..a23f4dca9b5 100755
--- a/src/tools/ci/copy-changed-docs
+++ b/src/tools/ci/copy-changed-docs
@@ -3,9 +3,15 @@
 set -e
 
 outdir=html_docs
+base_branch=$1
 
 mkdir "$outdir"
-cp new-docs/src/sgml/html/*.css new-docs/src/sgml/html/*.svg "$outdir/"
+cp new-docs/src/sgml/html/*.css new-docs/src/sgml/html/*.svg "$outdir"
+
+# The index is useful to allow a static link to the artifacts for the most-recent, successful CI run for a branch
+# https://api.cirrus-ci.com/v1/artifact/github/USERNAME/postgres/Documentation/html_docs/html_docs/00-doc.html?branch=BRANCH
+index="$outdir/00-doc.html"
+echo "<html><head><title>Index of docs changed since: $base_branch</title></head><body><ul>" >"$index"
 
 changed=`git diff --no-index --name-only old-docs/src/sgml/html new-docs/src/sgml/html` ||
 	[ $? -eq 1 ]
@@ -13,4 +19,10 @@ changed=`git diff --no-index --name-only old-docs/src/sgml/html new-docs/src/sgm
 for f in $changed
 do
 	cp "$f" "$outdir"
-done
+	fn=${f##*/}
+	# ?branch=... is needed for the static link for the branch
+	# It's not used if accessing artifacts for *this* CI run
+	echo "<li><a href='$fn?branch=$base_branch'>$fn</a>"
+done >>"$index"
+
+echo "</ul></body></html>" >>"$index"
-- 
2.17.1

