From 0321edff99eacf8cbdf91763c35c4ccafb2ad98f Mon Sep 17 00:00:00 2001
From: Dmitrii Unterov <du228@cam.ac.uk>
Date: Thu, 7 Mar 2024 14:46:26 +0000
Subject: [PATCH] ci: add SHORT_TEST_PREFIX variable

---
 tests/cleanup.sh | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tests/cleanup.sh b/tests/cleanup.sh
index a7ba708..a2a09a4 100755
--- a/tests/cleanup.sh
+++ b/tests/cleanup.sh
@@ -13,6 +13,11 @@ cleanup() {
 trap 'cleanup' EXIT INT TERM
 
 TEST_PREFIX="test-rapp"
+# Workaround to detect cloud functions created by GCP Minimal Site Monitoring module.
+# The cloud functions created by this module use `short_service_name`, (first 8 symbols).
+# https://gitlab.developers.cam.ac.uk/uis/devops/infra/terraform/gcp-site-monitoring/-/blob/master/locals.tf?ref_type=heads#L74
+# SHORT_TEST_PREFIX is used later in this script in "Cleaning up Cloud Functions..." block.
+SHORT_TEST_PREFIX="${TEST_PREFIX:0:8}"
 GCP_PROJECT="infra-testing-int-e2395220"
 GCP_PROJECT_META="infra-testing-meta-21f09a44"
 GCP_REGION="europe-west2"
@@ -45,7 +50,7 @@ done
 echo "Cleaning up Cloud Functions..."
 mapfile -t functions < <(
     gcloud --project="$GCP_PROJECT" functions list \
-        --filter="name ~ .*${TEST_PREFIX}.*" --format="value(name)"
+        --filter="name ~ .*${SHORT_TEST_PREFIX}.*" --format="value(name)"
 )
 
 for function in "${functions[@]}"; do
-- 
GitLab