Oh, and yeah, we should include the branch name in the cache key.
Something like the attached.  For some reason CI is not allowing me to
see the output from macOS right now (?!) so I couldn't see what
"Populate macports cache" printed out[1], but I think this should be
right... will try again tomorrow.

I guess the alternative would be to set the package list the same
across all branches, even though they need different stuff, so they
could share the same cache without fighting over it?

[1] https://cirrus-ci.com/task/6707217489985536
From 191236b828e737de2b1a9b62140d0f9b2c9dbb70 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.mu...@gmail.com>
Date: Mon, 18 Nov 2024 21:46:38 +1300
Subject: [PATCH v2] ci: Fix cached MacPorts installation management.

1.  The error reporting of "port setrequested list-of-packages..."
changed, hiding errors we were relying on to know if all packages in our
list were already installed.  Use a loop instead.

2.  The cached MacPorts installation was shared between PostgreSQL
major branches, though each branch wanted different packages.  Add the
branch name to the cache key, so that different branches, when tested in
one github account/repo such as postgres/postgres, stop fighting with
each other, adding and removing packages.

Back-patch to 15 where CI began.

Diagnosed-by: Andres Freund <and...@anarazel.de>
Discussion: https://postgr.es/m/au2uqfuy2nf43nwy2txmc5t2emhwij7kzupygto3d2ffgtrdgr%40ckvrlwyflnh2
---
 .cirrus.tasks.yml                    |  2 ++
 src/tools/ci/ci_macports_packages.sh | 10 ++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
index fc413eb11ef..cd8e1b5eb0b 100644
--- a/.cirrus.tasks.yml
+++ b/.cirrus.tasks.yml
@@ -466,6 +466,8 @@ task:
       # Include the OS major version in the cache key.  If the OS image changes
       # to a different major version, we need to reinstall.
       sw_vers -productVersion | sed 's/\..*//'
+      # Include the branch name, because branches want different packages
+      echo ${CIRRUS_BRANCH}
       # Also start afresh if we change our MacPorts install script.
       md5 src/tools/ci/ci_macports_packages.sh
     reupload_on_changes: true
diff --git a/src/tools/ci/ci_macports_packages.sh b/src/tools/ci/ci_macports_packages.sh
index b3df6d36a4e..41cb83593f7 100755
--- a/src/tools/ci/ci_macports_packages.sh
+++ b/src/tools/ci/ci_macports_packages.sh
@@ -61,9 +61,15 @@ fi
 
 # if setting all the required packages as requested fails, we need
 # to install at least one of them
-if ! sudo port setrequested $packages > /dev/null 2>&1 ; then
-    echo not all required packages installed, doing so now
+echo "checking if all required packages are installed"
+for package in $packages ; do
+  if ! sudo port setrequested $package > /dev/null 2>&1 ; then
     update_cached_image=1
+  fi
+done
+echo "done"
+if [ "$update_cached_image" -eq 1 ]; then
+    echo not all required packages installed, doing so now
     # to keep the image small, we deleted the ports tree from the image...
     sudo port selfupdate
     # XXX likely we'll need some other way to force an upgrade at some
-- 
2.47.0

Reply via email to