mirror of
https://code.forgejo.org/actions/checkout.git
synced 2025-04-24 04:15:33 +00:00
Add workingDirectory option
Let user override $GITHUB_WORKSPACE as default working directory Defaults to undefined, the original behaviour is maintained
This commit is contained in:
parent
8459bc0c7e
commit
0fd0fa4fd4
4 changed files with 27 additions and 21 deletions
|
@ -118,4 +118,9 @@ export interface IGitSourceSettings {
|
|||
* User override on the GitHub Server/Host URL that hosts the repository to be cloned
|
||||
*/
|
||||
githubServerUrl: string | undefined
|
||||
|
||||
/**
|
||||
* User override of the working directory (default is $GITHUB_WORKSPACE)
|
||||
*/
|
||||
workingDirectory: string | undefined
|
||||
}
|
||||
|
|
|
@ -8,14 +8,14 @@ import {IGitSourceSettings} from './git-source-settings'
|
|||
export async function getInputs(): Promise<IGitSourceSettings> {
|
||||
const result = {} as unknown as IGitSourceSettings
|
||||
|
||||
// GitHub workspace
|
||||
let githubWorkspacePath = process.env['GITHUB_WORKSPACE']
|
||||
if (!githubWorkspacePath) {
|
||||
throw new Error('GITHUB_WORKSPACE not defined')
|
||||
// Working directory
|
||||
let workingDirectory = core.getInput('workingDirectory') || process.env['GITHUB_WORKSPACE']
|
||||
if (!workingDirectory) {
|
||||
throw new Error('working dir not defined')
|
||||
}
|
||||
githubWorkspacePath = path.resolve(githubWorkspacePath)
|
||||
core.debug(`GITHUB_WORKSPACE = '${githubWorkspacePath}'`)
|
||||
fsHelper.directoryExistsSync(githubWorkspacePath, true)
|
||||
workingDirectory = path.resolve(workingDirectory)
|
||||
core.debug(`working directory = '${workingDirectory}'`)
|
||||
fsHelper.directoryExistsSync(workingDirectory, true)
|
||||
|
||||
// Qualified repository
|
||||
const qualifiedRepository =
|
||||
|
@ -38,16 +38,16 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
|||
// Repository path
|
||||
result.repositoryPath = core.getInput('path') || '.'
|
||||
result.repositoryPath = path.resolve(
|
||||
githubWorkspacePath,
|
||||
workingDirectory,
|
||||
result.repositoryPath
|
||||
)
|
||||
if (
|
||||
!(result.repositoryPath + path.sep).startsWith(
|
||||
githubWorkspacePath + path.sep
|
||||
workingDirectory + path.sep
|
||||
)
|
||||
) {
|
||||
throw new Error(
|
||||
`Repository path '${result.repositoryPath}' is not under '${githubWorkspacePath}'`
|
||||
`Repository path '${result.repositoryPath}' is not under '${workingDirectory}'`
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue