mirror of
https://gitea.com/actions/checkout.git
synced 2024-11-01 01:20:35 +01:00
change: remove path.sep, add unit tests, dist
Remove path.sep during comparison with repositoryPath (did not take in account root folders) Updated and added more unit tests Updated dist/index.js
This commit is contained in:
parent
faa95350fe
commit
53a4183dea
@ -821,7 +821,6 @@ async function setup(testName: string): Promise<void> {
|
||||
workflowOrganizationId: 123456,
|
||||
setSafeDirectory: true,
|
||||
githubServerUrl: githubServerUrl,
|
||||
workingDirectory: undefined
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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('/'))
|
||||
})
|
||||
})
|
||||
|
6
dist/index.js
vendored
6
dist/index.js
vendored
@ -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() ===
|
||||
|
@ -43,11 +43,11 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
||||
)
|
||||
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}'`
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user