SDL: Fix saving/restoring cache: GitHub's cache module modified its arguments

From f9125121cc36c689d94cb1dcc3305d1cb45dfe54 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sun, 18 Jun 2023 20:05:14 +0200
Subject: [PATCH] Fix saving/restoring cache: GitHub's cache module modified
 its arguments

Co-authored-by: Pierre Wendling <pierre.wendling.4@gmail.com>
---
 packed/index.js | 6 ++++--
 src/main.ts     | 9 +++++++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/packed/index.js b/packed/index.js
index cb9541e79d79..35b73b319fdf 100644
--- a/packed/index.js
+++ b/packed/index.js
@@ -252,7 +252,8 @@ async function run() {
     core.info(`SDL version is ${SDL_VERSION.toString()}`);
     const CACHE_KEY = `setup-sdl-${STATE_HASH}`;
     const CACHE_PATHS = [PACKAGE_DIR];
-    const found_cache_key = await cache.restoreCache(CACHE_PATHS, CACHE_KEY);
+    // Pass a copy of CACHE_PATHS since cache.restoreCache modifies/modified its arguments
+    const found_cache_key = await cache.restoreCache(CACHE_PATHS.slice(), CACHE_KEY);
     if (!found_cache_key) {
         core.info("No match found in cache. Building SDL from scratch.");
         if (USE_NINJA) {
@@ -273,7 +274,8 @@ async function run() {
             shell: SHELL,
         });
         core.info(`Caching ${CACHE_PATHS}.`);
-        await cache.saveCache(CACHE_PATHS, CACHE_KEY);
+        // Pass a copy of CACHE_PATHS since cache.saveCache modifies/modified its arguments
+        await cache.saveCache(CACHE_PATHS.slice(), CACHE_KEY);
     }
     core.exportVariable(`SDL${SDL_VERSION.major}_ROOT`, PACKAGE_DIR);
     core.setOutput("prefix", PACKAGE_DIR);
diff --git a/src/main.ts b/src/main.ts
index 6586df886a6b..5d46c5a7a4e6 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -247,7 +247,11 @@ async function run() {
 
   const CACHE_KEY = `setup-sdl-${STATE_HASH}`;
   const CACHE_PATHS = [PACKAGE_DIR];
-  const found_cache_key = await cache.restoreCache(CACHE_PATHS, CACHE_KEY);
+  // Pass a copy of CACHE_PATHS since cache.restoreCache modifies/modified its arguments
+  const found_cache_key = await cache.restoreCache(
+    CACHE_PATHS.slice(),
+    CACHE_KEY
+  );
 
   if (!found_cache_key) {
     core.info("No match found in cache. Building SDL from scratch.");
@@ -273,7 +277,8 @@ async function run() {
     });
 
     core.info(`Caching ${CACHE_PATHS}.`);
-    await cache.saveCache(CACHE_PATHS, CACHE_KEY);
+    // Pass a copy of CACHE_PATHS since cache.saveCache modifies/modified its arguments
+    await cache.saveCache(CACHE_PATHS.slice(), CACHE_KEY);
   }
 
   core.exportVariable(`SDL${SDL_VERSION.major}_ROOT`, PACKAGE_DIR);