diff --git a/__test__/git-auth-helper.test.ts b/__test__/git-auth-helper.test.ts index 603376e..f28bff0 100644 --- a/__test__/git-auth-helper.test.ts +++ b/__test__/git-auth-helper.test.ts @@ -821,7 +821,6 @@ async function setup(testName: string): Promise { workflowOrganizationId: 123456, setSafeDirectory: true, githubServerUrl: githubServerUrl, - workingDirectory: undefined } } diff --git a/__test__/input-helper.test.ts b/__test__/input-helper.test.ts index 21932ca..f90eda9 100644 --- a/__test__/input-helper.test.ts +++ b/__test__/input-helper.test.ts @@ -143,4 +143,25 @@ describe('input-helper tests', () => { const settings: IGitSourceSettings = await inputHelper.getInputs() expect(settings.workflowOrganizationId).toBe(123456) }) + + it('sets a different working directory', async() => { + inputs['working-directory'] = '/home/user/test' + inputs['path'] = 'path/to/repo' + const settings: IGitSourceSettings = await inputHelper.getInputs() + expect(settings.repositoryPath).toBe(path.resolve('/home/user/test/path/to/repo')) + }) + + it('sets a working directory on root', async() => { + inputs['working-directory'] = '/' + inputs['path'] = 'path/to/repo' + const settings: IGitSourceSettings = await inputHelper.getInputs() + expect(settings.repositoryPath).toBe(path.resolve('/path/to/repo')) + }) + + it('sets a working directory on root and repository path is set to empty', async() => { + inputs['working-directory'] = '/' + inputs['path'] = '' + const settings: IGitSourceSettings = await inputHelper.getInputs() + expect(settings.repositoryPath).toBe(path.resolve('/')) + }) }) diff --git a/dist/index.js b/dist/index.js index 76c1143..cef2aea 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1672,7 +1672,7 @@ function getInputs() { return __awaiter(this, void 0, void 0, function* () { const result = {}; // Working directory - let workingDirectory = core.getInput('workingDirectory') || process.env['GITHUB_WORKSPACE']; + let workingDirectory = core.getInput('working-directory') || process.env['GITHUB_WORKSPACE']; if (!workingDirectory) { throw new Error('working dir not defined'); } @@ -1694,8 +1694,8 @@ function getInputs() { // Repository path result.repositoryPath = core.getInput('path') || '.'; result.repositoryPath = path.resolve(workingDirectory, result.repositoryPath); - if (!(result.repositoryPath + path.sep).startsWith(workingDirectory + path.sep)) { - throw new Error(`Repository path '${result.repositoryPath}' is not under '${workingDirectory}'`); + if (!(result.repositoryPath + path.sep).startsWith(workingDirectory)) { + throw new Error(`Repository path '${result.repositoryPath + path.sep}' is not under '${workingDirectory}'`); } // Workflow repository? const isWorkflowRepository = qualifiedRepository.toUpperCase() === diff --git a/src/input-helper.ts b/src/input-helper.ts index 4697f65..48e1fae 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -43,11 +43,11 @@ export async function getInputs(): Promise { ) if ( !(result.repositoryPath + path.sep).startsWith( - workingDirectory + path.sep + workingDirectory ) ) { throw new Error( - `Repository path '${result.repositoryPath}' is not under '${workingDirectory}'` + `Repository path '${result.repositoryPath + path.sep}' is not under '${workingDirectory}'` ) }