From d1d381abe720cf316aa45d143cebc9dadf38440d Mon Sep 17 00:00:00 2001 From: xavisolesoft Date: Wed, 18 Dec 2024 10:08:23 +0100 Subject: [PATCH] Implement allow-path-outside-workspace --- README.md | 4 ++++ action.yml | 4 ++++ dist/index.js | 3 ++- src/input-helper.ts | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b0f6224..b6aeb7b 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,10 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/ # Relative path under $GITHUB_WORKSPACE to place the repository path: '' + # Allow the checked-out repository to be placed outside of the workspace + # Default: false + allow-path-outside-workspace: '' + # Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching # Default: true clean: '' diff --git a/action.yml b/action.yml index 6842eb8..5e70363 100644 --- a/action.yml +++ b/action.yml @@ -54,6 +54,10 @@ inputs: default: true path: description: 'Relative path under $GITHUB_WORKSPACE to place the repository' + allow-path-outside-workspace: + description: Allow the checked-out repository to be placed outside of the workspace. + default: false + required: false clean: description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching' default: true diff --git a/dist/index.js b/dist/index.js index b0db713..18497fe 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1737,7 +1737,8 @@ function getInputs() { // Repository path result.repositoryPath = core.getInput('path') || '.'; result.repositoryPath = path.resolve(githubWorkspacePath, result.repositoryPath); - if (!(result.repositoryPath + path.sep).startsWith(githubWorkspacePath + path.sep)) { + if (!core.getInput('allow-path-outside-workspace') && + !(result.repositoryPath + path.sep).startsWith(githubWorkspacePath + path.sep)) { throw new Error(`Repository path '${result.repositoryPath}' is not under '${githubWorkspacePath}'`); } // Workflow repository? diff --git a/src/input-helper.ts b/src/input-helper.ts index 059232f..02a01e1 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -42,6 +42,7 @@ export async function getInputs(): Promise { result.repositoryPath ) if ( + !core.getInput('allow-path-outside-workspace') && !(result.repositoryPath + path.sep).startsWith( githubWorkspacePath + path.sep )