Merge 9335342b9e9b8c4a6d8250fb6b44f0eb7c794ec5 into b4ffde65f46336ab88eb53be808477a3936bae11
This commit is contained in:
commit
5ccbd52098
@ -66,7 +66,7 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
|
|||||||
# Default: true
|
# Default: true
|
||||||
persist-credentials: ''
|
persist-credentials: ''
|
||||||
|
|
||||||
# Relative path under $GITHUB_WORKSPACE to place the repository
|
# Relative path under $GITHUB_WORKSPACE/working-directory to place the repository
|
||||||
path: ''
|
path: ''
|
||||||
|
|
||||||
# Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching
|
# Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching
|
||||||
@ -121,6 +121,10 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
|
|||||||
# running from unless specified. Example URLs are https://github.com or
|
# running from unless specified. Example URLs are https://github.com or
|
||||||
# https://my-ghes-server.example.com
|
# https://my-ghes-server.example.com
|
||||||
github-server-url: ''
|
github-server-url: ''
|
||||||
|
|
||||||
|
# Provide the working directory for the git commands to execute into, defaults to
|
||||||
|
# $GITHUB_WORKSPACE
|
||||||
|
working-directory: ''
|
||||||
```
|
```
|
||||||
<!-- end usage -->
|
<!-- end usage -->
|
||||||
|
|
||||||
|
@ -821,7 +821,7 @@ async function setup(testName: string): Promise<void> {
|
|||||||
sshStrict: true,
|
sshStrict: true,
|
||||||
workflowOrganizationId: 123456,
|
workflowOrganizationId: 123456,
|
||||||
setSafeDirectory: true,
|
setSafeDirectory: true,
|
||||||
githubServerUrl: githubServerUrl
|
githubServerUrl: githubServerUrl,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,4 +144,25 @@ describe('input-helper tests', () => {
|
|||||||
const settings: IGitSourceSettings = await inputHelper.getInputs()
|
const settings: IGitSourceSettings = await inputHelper.getInputs()
|
||||||
expect(settings.workflowOrganizationId).toBe(123456)
|
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('/'))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -49,7 +49,7 @@ inputs:
|
|||||||
description: 'Whether to configure the token or SSH key with the local git config'
|
description: 'Whether to configure the token or SSH key with the local git config'
|
||||||
default: true
|
default: true
|
||||||
path:
|
path:
|
||||||
description: 'Relative path under $GITHUB_WORKSPACE to place the repository'
|
description: 'Relative path under $GITHUB_WORKSPACE/working-directory to place the repository'
|
||||||
clean:
|
clean:
|
||||||
description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching'
|
description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching'
|
||||||
default: true
|
default: true
|
||||||
@ -94,6 +94,9 @@ inputs:
|
|||||||
github-server-url:
|
github-server-url:
|
||||||
description: The base URL for the GitHub instance that you are trying to clone from, will use environment defaults to fetch from the same instance that the workflow is running from unless specified. Example URLs are https://github.com or https://my-ghes-server.example.com
|
description: The base URL for the GitHub instance that you are trying to clone from, will use environment defaults to fetch from the same instance that the workflow is running from unless specified. Example URLs are https://github.com or https://my-ghes-server.example.com
|
||||||
required: false
|
required: false
|
||||||
|
working-directory:
|
||||||
|
description: Provide the working directory for the git commands to execute into, defaults to $GITHUB_WORKSPACE
|
||||||
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: node20
|
using: node20
|
||||||
main: dist/index.js
|
main: dist/index.js
|
||||||
|
20
dist/index.js
vendored
20
dist/index.js
vendored
@ -1675,14 +1675,14 @@ const workflowContextHelper = __importStar(__nccwpck_require__(9568));
|
|||||||
function getInputs() {
|
function getInputs() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const result = {};
|
const result = {};
|
||||||
// GitHub workspace
|
// Working directory
|
||||||
let githubWorkspacePath = process.env['GITHUB_WORKSPACE'];
|
let workingDirectory = core.getInput('working-directory') || process.env['GITHUB_WORKSPACE'];
|
||||||
if (!githubWorkspacePath) {
|
if (!workingDirectory) {
|
||||||
throw new Error('GITHUB_WORKSPACE not defined');
|
throw new Error('working dir not defined');
|
||||||
}
|
}
|
||||||
githubWorkspacePath = path.resolve(githubWorkspacePath);
|
workingDirectory = path.resolve(workingDirectory);
|
||||||
core.debug(`GITHUB_WORKSPACE = '${githubWorkspacePath}'`);
|
core.debug(`working directory = '${workingDirectory}'`);
|
||||||
fsHelper.directoryExistsSync(githubWorkspacePath, true);
|
fsHelper.directoryExistsSync(workingDirectory, true);
|
||||||
// Qualified repository
|
// Qualified repository
|
||||||
const qualifiedRepository = core.getInput('repository') ||
|
const qualifiedRepository = core.getInput('repository') ||
|
||||||
`${github.context.repo.owner}/${github.context.repo.repo}`;
|
`${github.context.repo.owner}/${github.context.repo.repo}`;
|
||||||
@ -1697,9 +1697,9 @@ function getInputs() {
|
|||||||
result.repositoryName = splitRepository[1];
|
result.repositoryName = splitRepository[1];
|
||||||
// Repository path
|
// Repository path
|
||||||
result.repositoryPath = core.getInput('path') || '.';
|
result.repositoryPath = core.getInput('path') || '.';
|
||||||
result.repositoryPath = path.resolve(githubWorkspacePath, result.repositoryPath);
|
result.repositoryPath = path.resolve(workingDirectory, result.repositoryPath);
|
||||||
if (!(result.repositoryPath + path.sep).startsWith(githubWorkspacePath + path.sep)) {
|
if (!(result.repositoryPath + path.sep).startsWith(workingDirectory)) {
|
||||||
throw new Error(`Repository path '${result.repositoryPath}' is not under '${githubWorkspacePath}'`);
|
throw new Error(`Repository path '${result.repositoryPath + path.sep}' is not under '${workingDirectory}'`);
|
||||||
}
|
}
|
||||||
// Workflow repository?
|
// Workflow repository?
|
||||||
const isWorkflowRepository = qualifiedRepository.toUpperCase() ===
|
const isWorkflowRepository = qualifiedRepository.toUpperCase() ===
|
||||||
|
@ -8,14 +8,14 @@ import {IGitSourceSettings} from './git-source-settings'
|
|||||||
export async function getInputs(): Promise<IGitSourceSettings> {
|
export async function getInputs(): Promise<IGitSourceSettings> {
|
||||||
const result = ({} as unknown) as IGitSourceSettings
|
const result = ({} as unknown) as IGitSourceSettings
|
||||||
|
|
||||||
// GitHub workspace
|
// Working directory
|
||||||
let githubWorkspacePath = process.env['GITHUB_WORKSPACE']
|
let workingDirectory = core.getInput('working-directory') || process.env['GITHUB_WORKSPACE']
|
||||||
if (!githubWorkspacePath) {
|
if (!workingDirectory) {
|
||||||
throw new Error('GITHUB_WORKSPACE not defined')
|
throw new Error('working dir not defined')
|
||||||
}
|
}
|
||||||
githubWorkspacePath = path.resolve(githubWorkspacePath)
|
workingDirectory = path.resolve(workingDirectory)
|
||||||
core.debug(`GITHUB_WORKSPACE = '${githubWorkspacePath}'`)
|
core.debug(`working directory = '${workingDirectory}'`)
|
||||||
fsHelper.directoryExistsSync(githubWorkspacePath, true)
|
fsHelper.directoryExistsSync(workingDirectory, true)
|
||||||
|
|
||||||
// Qualified repository
|
// Qualified repository
|
||||||
const qualifiedRepository =
|
const qualifiedRepository =
|
||||||
@ -38,16 +38,16 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
|||||||
// Repository path
|
// Repository path
|
||||||
result.repositoryPath = core.getInput('path') || '.'
|
result.repositoryPath = core.getInput('path') || '.'
|
||||||
result.repositoryPath = path.resolve(
|
result.repositoryPath = path.resolve(
|
||||||
githubWorkspacePath,
|
workingDirectory,
|
||||||
result.repositoryPath
|
result.repositoryPath
|
||||||
)
|
)
|
||||||
if (
|
if (
|
||||||
!(result.repositoryPath + path.sep).startsWith(
|
!(result.repositoryPath + path.sep).startsWith(
|
||||||
githubWorkspacePath + path.sep
|
workingDirectory
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Repository path '${result.repositoryPath}' is not under '${githubWorkspacePath}'`
|
`Repository path '${result.repositoryPath + path.sep}' is not under '${workingDirectory}'`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user