From 4ede81d01426c3fc3664c97fbdf189df80394b9c Mon Sep 17 00:00:00 2001
From: Nikola Jokic <nikola-jokic@github.com>
Date: Wed, 5 Oct 2022 15:07:47 +0200
Subject: [PATCH 1/4] fixed substring issue with /github/workspace and
 /github/file_commands

---
 packages/k8s/src/k8s/utils.ts        |  4 ++--
 packages/k8s/tests/k8s-utils-test.ts | 29 ++++++++++++++++------------
 2 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/packages/k8s/src/k8s/utils.ts b/packages/k8s/src/k8s/utils.ts
index d3072b49..16899d77 100644
--- a/packages/k8s/src/k8s/utils.ts
+++ b/packages/k8s/src/k8s/utils.ts
@@ -26,12 +26,12 @@ export function containerVolumes(
       {
         name: POD_VOLUME_NAME,
         mountPath: '/github/workspace',
-        subPath: workspacePath.substring(workspacePath.indexOf('work/') + 1)
+        subPath: workspacePath.split('work/')[1]
       },
       {
         name: POD_VOLUME_NAME,
         mountPath: '/github/file_commands',
-        subPath: workspacePath.substring(workspacePath.indexOf('work/') + 1)
+        subPath: workspacePath.split('work/')[1]
       }
     )
     return mounts
diff --git a/packages/k8s/tests/k8s-utils-test.ts b/packages/k8s/tests/k8s-utils-test.ts
index cf30fda1..006b0b18 100644
--- a/packages/k8s/tests/k8s-utils-test.ts
+++ b/packages/k8s/tests/k8s-utils-test.ts
@@ -103,19 +103,24 @@ describe('k8s utils', () => {
 
     it('should have container action volumes', () => {
       let volumes = containerVolumes([], true, true)
-      expect(
-        volumes.find(e => e.mountPath === '/github/workspace')
-      ).toBeTruthy()
-      expect(
-        volumes.find(e => e.mountPath === '/github/file_commands')
-      ).toBeTruthy()
+      let workspace = volumes.find(e => e.mountPath === '/github/workspace')
+      let fileCommands = volumes.find(
+        e => e.mountPath === '/github/file_commands'
+      )
+      expect(workspace).toBeTruthy()
+      expect(workspace?.subPath).toBe("repo/repo")
+      expect(fileCommands).toBeTruthy()
+      expect(fileCommands?.subPath).toBe("repo/repo")
+
       volumes = containerVolumes([], false, true)
-      expect(
-        volumes.find(e => e.mountPath === '/github/workspace')
-      ).toBeTruthy()
-      expect(
-        volumes.find(e => e.mountPath === '/github/file_commands')
-      ).toBeTruthy()
+      workspace = volumes.find(e => e.mountPath === '/github/workspace')
+      fileCommands = volumes.find(
+        e => e.mountPath === '/github/file_commands'
+      )
+      expect(workspace).toBeTruthy()
+      expect(workspace?.subPath).toBe("repo/repo")
+      expect(fileCommands).toBeTruthy()
+      expect(fileCommands?.subPath).toBe("repo/repo")
     })
 
     it('should have externals, github home and github workflow mounts if job container', () => {

From d573da44b3072839beaab5d67eabc82c2b3021cb Mon Sep 17 00:00:00 2001
From: Nikola Jokic <nikola-jokic@github.com>
Date: Fri, 7 Oct 2022 09:59:16 +0200
Subject: [PATCH 2/4] npm run format

---
 packages/k8s/tests/k8s-utils-test.ts | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/packages/k8s/tests/k8s-utils-test.ts b/packages/k8s/tests/k8s-utils-test.ts
index 006b0b18..23645260 100644
--- a/packages/k8s/tests/k8s-utils-test.ts
+++ b/packages/k8s/tests/k8s-utils-test.ts
@@ -108,19 +108,17 @@ describe('k8s utils', () => {
         e => e.mountPath === '/github/file_commands'
       )
       expect(workspace).toBeTruthy()
-      expect(workspace?.subPath).toBe("repo/repo")
+      expect(workspace?.subPath).toBe('repo/repo')
       expect(fileCommands).toBeTruthy()
-      expect(fileCommands?.subPath).toBe("repo/repo")
+      expect(fileCommands?.subPath).toBe('repo/repo')
 
       volumes = containerVolumes([], false, true)
       workspace = volumes.find(e => e.mountPath === '/github/workspace')
-      fileCommands = volumes.find(
-        e => e.mountPath === '/github/file_commands'
-      )
+      fileCommands = volumes.find(e => e.mountPath === '/github/file_commands')
       expect(workspace).toBeTruthy()
-      expect(workspace?.subPath).toBe("repo/repo")
+      expect(workspace?.subPath).toBe('repo/repo')
       expect(fileCommands).toBeTruthy()
-      expect(fileCommands?.subPath).toBe("repo/repo")
+      expect(fileCommands?.subPath).toBe('repo/repo')
     })
 
     it('should have externals, github home and github workflow mounts if job container', () => {

From ed3e381a4a069e17900d5851e54fe580211b7b3f Mon Sep 17 00:00:00 2001
From: Nikola Jokic <nikola-jokic@github.com>
Date: Fri, 7 Oct 2022 11:56:49 +0200
Subject: [PATCH 3/4] last 3 parts of the path are mounted to /github/workspace
 and /github/file_commands

---
 packages/k8s/src/k8s/utils.ts        | 6 ++++--
 packages/k8s/tests/k8s-utils-test.ts | 8 ++++----
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/packages/k8s/src/k8s/utils.ts b/packages/k8s/src/k8s/utils.ts
index 16899d77..91a9c42f 100644
--- a/packages/k8s/src/k8s/utils.ts
+++ b/packages/k8s/src/k8s/utils.ts
@@ -22,16 +22,18 @@ export function containerVolumes(
 
   const workspacePath = process.env.GITHUB_WORKSPACE as string
   if (containerAction) {
+    const splitLength = workspacePath.split('/').length
+    const pathSplit = workspacePath.split('/').slice(splitLength - 3)
     mounts.push(
       {
         name: POD_VOLUME_NAME,
         mountPath: '/github/workspace',
-        subPath: workspacePath.split('work/')[1]
+        subPath: path.join(...pathSplit)
       },
       {
         name: POD_VOLUME_NAME,
         mountPath: '/github/file_commands',
-        subPath: workspacePath.split('work/')[1]
+        subPath: path.join(...pathSplit)
       }
     )
     return mounts
diff --git a/packages/k8s/tests/k8s-utils-test.ts b/packages/k8s/tests/k8s-utils-test.ts
index 23645260..749e2c02 100644
--- a/packages/k8s/tests/k8s-utils-test.ts
+++ b/packages/k8s/tests/k8s-utils-test.ts
@@ -108,17 +108,17 @@ describe('k8s utils', () => {
         e => e.mountPath === '/github/file_commands'
       )
       expect(workspace).toBeTruthy()
-      expect(workspace?.subPath).toBe('repo/repo')
+      expect(workspace?.subPath).toBe('_work/repo/repo')
       expect(fileCommands).toBeTruthy()
-      expect(fileCommands?.subPath).toBe('repo/repo')
+      expect(fileCommands?.subPath).toBe('_work/repo/repo')
 
       volumes = containerVolumes([], false, true)
       workspace = volumes.find(e => e.mountPath === '/github/workspace')
       fileCommands = volumes.find(e => e.mountPath === '/github/file_commands')
       expect(workspace).toBeTruthy()
-      expect(workspace?.subPath).toBe('repo/repo')
+      expect(workspace?.subPath).toBe('_work/repo/repo')
       expect(fileCommands).toBeTruthy()
-      expect(fileCommands?.subPath).toBe('repo/repo')
+      expect(fileCommands?.subPath).toBe('_work/repo/repo')
     })
 
     it('should have externals, github home and github workflow mounts if job container', () => {

From 6f117d20b0433e6e68d11e482632dfa05fb83d39 Mon Sep 17 00:00:00 2001
From: Nikola Jokic <nikola-jokic@github.com>
Date: Mon, 31 Oct 2022 16:02:14 +0100
Subject: [PATCH 4/4] file commands now point to _temp/_runner_file_commands

---
 packages/k8s/src/k8s/utils.ts        | 8 ++++----
 packages/k8s/tests/k8s-utils-test.ts | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/packages/k8s/src/k8s/utils.ts b/packages/k8s/src/k8s/utils.ts
index 91a9c42f..e2a23aa3 100644
--- a/packages/k8s/src/k8s/utils.ts
+++ b/packages/k8s/src/k8s/utils.ts
@@ -22,18 +22,18 @@ export function containerVolumes(
 
   const workspacePath = process.env.GITHUB_WORKSPACE as string
   if (containerAction) {
-    const splitLength = workspacePath.split('/').length
-    const pathSplit = workspacePath.split('/').slice(splitLength - 3)
+    const i = workspacePath.lastIndexOf('_work/')
+    const workspaceRelativePath = workspacePath.slice(i + '_work/'.length)
     mounts.push(
       {
         name: POD_VOLUME_NAME,
         mountPath: '/github/workspace',
-        subPath: path.join(...pathSplit)
+        subPath: workspaceRelativePath
       },
       {
         name: POD_VOLUME_NAME,
         mountPath: '/github/file_commands',
-        subPath: path.join(...pathSplit)
+        subPath: '_temp/_runner_file_commands'
       }
     )
     return mounts
diff --git a/packages/k8s/tests/k8s-utils-test.ts b/packages/k8s/tests/k8s-utils-test.ts
index 749e2c02..3d792567 100644
--- a/packages/k8s/tests/k8s-utils-test.ts
+++ b/packages/k8s/tests/k8s-utils-test.ts
@@ -108,17 +108,17 @@ describe('k8s utils', () => {
         e => e.mountPath === '/github/file_commands'
       )
       expect(workspace).toBeTruthy()
-      expect(workspace?.subPath).toBe('_work/repo/repo')
+      expect(workspace?.subPath).toBe('repo/repo')
       expect(fileCommands).toBeTruthy()
-      expect(fileCommands?.subPath).toBe('_work/repo/repo')
+      expect(fileCommands?.subPath).toBe('_temp/_runner_file_commands')
 
       volumes = containerVolumes([], false, true)
       workspace = volumes.find(e => e.mountPath === '/github/workspace')
       fileCommands = volumes.find(e => e.mountPath === '/github/file_commands')
       expect(workspace).toBeTruthy()
-      expect(workspace?.subPath).toBe('_work/repo/repo')
+      expect(workspace?.subPath).toBe('repo/repo')
       expect(fileCommands).toBeTruthy()
-      expect(fileCommands?.subPath).toBe('_work/repo/repo')
+      expect(fileCommands?.subPath).toBe('_temp/_runner_file_commands')
     })
 
     it('should have externals, github home and github workflow mounts if job container', () => {