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
72f2cec99f
commit
a66a86e636
|
@ -820,7 +820,8 @@ async function setup(testName: string): Promise<void> {
|
||||||
sshStrict: true,
|
sshStrict: true,
|
||||||
workflowOrganizationId: 123456,
|
workflowOrganizationId: 123456,
|
||||||
setSafeDirectory: true,
|
setSafeDirectory: true,
|
||||||
githubServerUrl: githubServerUrl
|
githubServerUrl: githubServerUrl,
|
||||||
|
workingDirectory: undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1671,14 +1671,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('workingDirectory') || 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}`;
|
||||||
|
@ -1693,9 +1693,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 + path.sep)) {
|
||||||
throw new Error(`Repository path '${result.repositoryPath}' is not under '${githubWorkspacePath}'`);
|
throw new Error(`Repository path '${result.repositoryPath}' is not under '${workingDirectory}'`);
|
||||||
}
|
}
|
||||||
// Workflow repository?
|
// Workflow repository?
|
||||||
const isWorkflowRepository = qualifiedRepository.toUpperCase() ===
|
const isWorkflowRepository = qualifiedRepository.toUpperCase() ===
|
||||||
|
|
|
@ -108,4 +108,9 @@ export interface IGitSourceSettings {
|
||||||
* User override on the GitHub Server/Host URL that hosts the repository to be cloned
|
* User override on the GitHub Server/Host URL that hosts the repository to be cloned
|
||||||
*/
|
*/
|
||||||
githubServerUrl: string | undefined
|
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> {
|
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('workingDirectory') || 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 + path.sep
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Repository path '${result.repositoryPath}' is not under '${githubWorkspacePath}'`
|
`Repository path '${result.repositoryPath}' is not under '${workingDirectory}'`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue