From 23cc6dda6fc44782d713f5ce9888d66a5a02b15f Mon Sep 17 00:00:00 2001 From: Nikola Jokic <97525037+nikola-jokic@users.noreply.github.com> Date: Thu, 3 Nov 2022 14:55:07 +0100 Subject: [PATCH] fixed substring issue with /github/workspace and /github/file_commands (#35) * fixed substring issue with /github/workspace and /github/file_commands * npm run format * last 3 parts of the path are mounted to /github/workspace and /github/file_commands * file commands now point to _temp/_runner_file_commands --- packages/k8s/src/k8s/utils.ts | 6 ++++-- packages/k8s/tests/k8s-utils-test.ts | 27 +++++++++++++++------------ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/k8s/src/k8s/utils.ts b/packages/k8s/src/k8s/utils.ts index d3072b4..e2a23aa 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 i = workspacePath.lastIndexOf('_work/') + const workspaceRelativePath = workspacePath.slice(i + '_work/'.length) mounts.push( { name: POD_VOLUME_NAME, mountPath: '/github/workspace', - subPath: workspacePath.substring(workspacePath.indexOf('work/') + 1) + subPath: workspaceRelativePath }, { name: POD_VOLUME_NAME, mountPath: '/github/file_commands', - subPath: workspacePath.substring(workspacePath.indexOf('work/') + 1) + 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 cf30fda..3d79256 100644 --- a/packages/k8s/tests/k8s-utils-test.ts +++ b/packages/k8s/tests/k8s-utils-test.ts @@ -103,19 +103,22 @@ 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('_temp/_runner_file_commands') + 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('_temp/_runner_file_commands') }) it('should have externals, github home and github workflow mounts if job container', () => {