From c1b361d8083d252944b3ccf328ccd07d68417be8 Mon Sep 17 00:00:00 2001
From: thangle <thang.le@skyscanner.net>
Date: Fri, 10 May 2024 12:14:03 +0100
Subject: [PATCH] Support AGENT_TOOLSDIRECTORY as in setup-python action

---
 dist/setup/index.js | 5 +++++
 src/main.ts         | 8 ++++++++
 2 files changed, 13 insertions(+)

diff --git a/dist/setup/index.js b/dist/setup/index.js
index 1f4334d35..5e7197516 100644
--- a/dist/setup/index.js
+++ b/dist/setup/index.js
@@ -94211,6 +94211,7 @@ const util_1 = __nccwpck_require__(2629);
 const constants_1 = __nccwpck_require__(9042);
 function run() {
     return __awaiter(this, void 0, void 0, function* () {
+        var _a;
         try {
             //
             // Version is optional.  If supplied, install / use from the tool cache
@@ -94227,6 +94228,10 @@ function run() {
             if (!arch) {
                 arch = os_1.default.arch();
             }
+            if ((_a = process.env.AGENT_TOOLSDIRECTORY) === null || _a === void 0 ? void 0 : _a.trim()) {
+                process.env['RUNNER_TOOL_CACHE'] = process.env['AGENT_TOOLSDIRECTORY'];
+            }
+            core.debug(`Node is expected to be installed into ${process.env['RUNNER_TOOL_CACHE']}`);
             if (version) {
                 const token = core.getInput('token');
                 const auth = !token ? undefined : `token ${token}`;
diff --git a/src/main.ts b/src/main.ts
index c55c3b005..3bef94729 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -33,6 +33,14 @@ export async function run() {
       arch = os.arch();
     }
 
+    if (process.env.AGENT_TOOLSDIRECTORY?.trim()) {
+      process.env['RUNNER_TOOL_CACHE'] = process.env['AGENT_TOOLSDIRECTORY'];
+    }
+
+    core.debug(
+      `Node is expected to be installed into ${process.env['RUNNER_TOOL_CACHE']}`
+    );
+
     if (version) {
       const token = core.getInput('token');
       const auth = !token ? undefined : `token ${token}`;