From ac196d04716296d363f3825bc3c30bf8b3eea6e7 Mon Sep 17 00:00:00 2001
From: Paul Abel <128620221+pdabelf5@users.noreply.github.com>
Date: Tue, 2 Jan 2024 14:26:27 +0000
Subject: [PATCH] load test matrix from json file (#4795)

* load test matrix from json file
---
 .github/actions/smoke-tests/action.yaml |  3 +-
 .github/data/matrix-regression.json     | 11 +++
 .github/data/matrix-smoke.json          | 93 +++++++++++++++++++++++++
 .github/workflows/ci.yml                | 43 +++---------
 4 files changed, 115 insertions(+), 35 deletions(-)
 create mode 100644 .github/data/matrix-regression.json
 create mode 100644 .github/data/matrix-smoke.json

diff --git a/.github/actions/smoke-tests/action.yaml b/.github/actions/smoke-tests/action.yaml
index 5497ef8788..b5d7c49945 100644
--- a/.github/actions/smoke-tests/action.yaml
+++ b/.github/actions/smoke-tests/action.yaml
@@ -87,7 +87,8 @@ runs:
         make -f tests/Makefile create-kind-cluster K8S_CLUSTER_NAME=${{ github.run_id }} K8S_CLUSTER_VERSION=${{ inputs.k8s-version }} K8S_TIMEOUT=${{ inputs.k8s-timeout }}
         make -f tests/Makefile image-load PREFIX=nginx/${{ steps.ingress-type.outputs.name }} TAG=${{ steps.ingress-type.outputs.tag }} K8S_CLUSTER_NAME=${{ github.run_id }}
         marker="${{ inputs.marker }}"
-        sanitized_marker="${marker// /_}"
+        nospaces="${marker// /_}"
+        sanitized_marker="${nospaces//\'/}"
         name="${sanitized_marker:-${{ inputs.k8s-version }}}"
         echo "cluster_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${{ github.run_id }}-control-plane)" >> $GITHUB_OUTPUT
         echo "cluster=$(echo nginx-${{ inputs.image }}-$name)" >> $GITHUB_OUTPUT
diff --git a/.github/data/matrix-regression.json b/.github/data/matrix-regression.json
new file mode 100644
index 0000000000..86751ca69e
--- /dev/null
+++ b/.github/data/matrix-regression.json
@@ -0,0 +1,11 @@
+{
+  "k8s": [],
+  "images": [
+    {
+      "image": "debian"
+    },
+    {
+      "image": "debian-plus"
+    }
+  ]
+}
diff --git a/.github/data/matrix-smoke.json b/.github/data/matrix-smoke.json
new file mode 100644
index 0000000000..d142317864
--- /dev/null
+++ b/.github/data/matrix-smoke.json
@@ -0,0 +1,93 @@
+{
+  "images": [
+    {
+      "image": "debian",
+      "marker": "ingresses"
+    },
+    {
+      "image": "alpine",
+      "marker": "vsr"
+    },
+    {
+      "image": "alpine",
+      "marker": "'policies and not policies_rl and not policies_ac and not policies_jwt and not policies_mtls'"
+    },
+    {
+      "image": "alpine",
+      "marker": "'policies_rl or policies_ac or policies_jwt or policies_mtls'"
+    },
+    {
+      "image": "debian",
+      "marker": "'vs and not vs_ipv6 and not vs_rewrite and not vs_responses and not vs_grpc and not vs_redirects and not vs_externalname and not vs_externaldns and not vs_certmanager'"
+    },
+    {
+      "image": "debian",
+      "marker": "'vs_grpc or vs_redirects or vs_externalname or vs_externaldns'"
+    },
+    {
+      "image": "debian",
+      "marker": "'vs_responses or vs_ipv6 or vs_rewrite or vs_certmanager'"
+    },
+    {
+      "image": "ubi",
+      "marker": "ts"
+    },
+    {
+      "image": "debian-plus",
+      "marker": "'vs and not vs_ipv6 and not vs_rewrite and not vs_responses and not vs_grpc and not vs_redirects and not vs_externalname and not vs_externaldns and not vs_certmanager'"
+    },
+    {
+      "image": "debian-plus",
+      "marker": "'vs_grpc or vs_redirects or vs_externalname or vs_externaldns'"
+    },
+    {
+      "image": "debian-plus",
+      "marker": "'vs_responses or vs_ipv6 or vs_rewrite or vs_certmanager'"
+    },
+    {
+      "image": "debian-plus",
+      "marker": "ts"
+    },
+    {
+      "image": "alpine-plus",
+      "marker": "ingresses"
+    },
+    {
+      "image": "alpine-plus",
+      "marker": "vsr"
+    },
+    {
+      "image": "ubi-plus",
+      "marker": "'policies and not policies_ac and not policies_jwt and not policies_mtls'"
+    },
+    {
+      "image": "ubi-plus",
+      "marker": "'policies_ac or policies_jwt or policies_mtls'"
+    },
+    {
+      "image": "debian-plus-nap",
+      "marker": "appprotect_waf_policies_allow"
+    },
+    {
+      "image": "debian-plus-nap",
+      "marker": "'appprotect_waf_policies and not appprotect_waf_policies_allow'"
+    },
+    {
+      "image": "debian-plus-nap",
+      "marker": "appprotect_waf_policies_grpc"
+    },
+    {
+      "image": "debian-plus-nap",
+      "marker": "'appprotect_watch or appprotect_batch or appprotect_integration'"
+    },
+    {
+      "image": "debian-plus-nap",
+      "marker": "'dos and not dos_learning'"
+    },
+    {
+      "image": "debian-plus-nap",
+      "marker": "dos_learning"
+    }
+  ],
+  "k8s": []
+}
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8637d50bf4..2d93531e0d 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -66,10 +66,9 @@ jobs:
             | head -n 7 \
             | sort -V \
             | sed 's/v//g' \
-            | sed 's/^/\\\"/' \
-            | sed 's/$/\\\",/' \
-            | tr '\n' ' ' \
-            | sed 's/, $//')
+            | sed 's/$//' \
+            | sed 's/, $//' \
+            | jq -R -s -c 'split("\n")[:-1]')
           echo "latest_kindest_node_versions=$kindest_versions" >> $GITHUB_OUTPUT
 
       - name: Check if go.mod and go.sum are up to date
@@ -273,41 +272,17 @@ jobs:
     outputs:
       matrix: ${{ steps.set-matrix.outputs.matrix }}
     steps:
+      - name: Checkout Repository
+        uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
+
       - id: set-matrix
         run: |
-          if [ "${{ github.event_name }}" != "schedule" ]; then
-            echo "matrix={\"images\": \
-                                                [{\"image\": \"debian\", \"marker\": \"ingresses\"}, \
-                                                {\"image\": \"alpine\", \"marker\":\"vsr\"}, \
-                                                {\"image\": \"alpine\", \"marker\":\"'policies and not policies_rl and not policies_ac and not policies_jwt and not policies_mtls'\"}, \
-                                                {\"image\": \"alpine\", \"marker\":\"'policies_rl or policies_ac or policies_jwt or policies_mtls'\"}, \
-                                                {\"image\": \"debian\", \"marker\": \"'vs and not vs_ipv6 and not vs_rewrite and not vs_responses and not vs_grpc and not vs_redirects and not vs_externalname and not vs_externaldns and not vs_certmanager'\"}, \
-                                                {\"image\": \"debian\", \"marker\": \"'vs_grpc or vs_redirects or vs_externalname or vs_externaldns'\"}, \
-                                                {\"image\": \"debian\", \"marker\": \"'vs_responses or vs_ipv6 or vs_rewrite or vs_certmanager'\"}, \
-                                                {\"image\": \"ubi\", \"marker\": \"ts\"}, \
-                                                {\"image\": \"debian-plus\", \"marker\": \"'vs and not vs_ipv6 and not vs_rewrite and not vs_responses and not vs_grpc and not vs_redirects and not vs_externalname and not vs_externaldns and not vs_certmanager'\"}, \
-                                                {\"image\": \"debian-plus\", \"marker\": \"'vs_grpc or vs_redirects or vs_externalname or vs_externaldns'\"}, \
-                                                {\"image\": \"debian-plus\", \"marker\": \"'vs_responses or vs_ipv6 or vs_rewrite or vs_certmanager'\"}, \
-                                                {\"image\": \"debian-plus\", \"marker\": \"ts\"}, \
-                                                {\"image\": \"alpine-plus\", \"marker\":\"ingresses\"}, \
-                                                {\"image\": \"alpine-plus\", \"marker\": \"vsr\"}, \
-                                                {\"image\": \"ubi-plus\", \"marker\":\"'policies and not policies_ac and not policies_jwt and not policies_mtls'\"}, \
-                                                {\"image\": \"ubi-plus\", \"marker\":\"'policies_ac or policies_jwt or policies_mtls'\"}, \
-                                                {\"image\": \"debian-plus-nap\", \"marker\": \"appprotect_waf_policies_allow\"}, \
-                                                {\"image\": \"debian-plus-nap\", \"marker\": \"'appprotect_waf_policies and not appprotect_waf_policies_allow'\"}, \
-                                                {\"image\": \"debian-plus-nap\", \"marker\": \"appprotect_waf_policies_grpc\"}, \
-                                                {\"image\": \"debian-plus-nap\", \"marker\": \"'appprotect_watch or appprotect_batch or appprotect_integration'\"}, \
-                                                {\"image\": \"debian-plus-nap\", \"marker\": \"'dos and not dos_learning'\"}, \
-                                                {\"image\": \"debian-plus-nap\", \"marker\": \"dos_learning\"}], \
-                                              \"k8s\": [\"${{ needs.checks.outputs.k8s_latest }}\"]}" >> $GITHUB_OUTPUT
+          if [ "${{ github.event_name }}" == "schedule" ]; then
+            echo "matrix=$(cat .github/data/matrix-regression.json | jq -c --argjson latest '${{ needs.checks.outputs.latest_kindest_node_versions }}' '.k8s += $latest')" >> $GITHUB_OUTPUT
           else
-            echo "matrix={\"k8s\": [${{ needs.checks.outputs.latest_kindest_node_versions }}], \
-                                             \"images\": [{\"image\": \"debian\"}, {\"image\": \"debian-plus\"}]}" >> $GITHUB_OUTPUT
+            echo "matrix=$(cat .github/data/matrix-smoke.json | jq -c --arg latest "${{ needs.checks.outputs.k8s_latest }}" '.k8s += [$latest]')" >> $GITHUB_OUTPUT
           fi
 
-      - name: Checkout Repository
-        uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
-
       - name: Docker Buildx
         uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0