diff --git a/action.yml b/action.yml index 7c1edf563..aaba5c4d3 100644 --- a/action.yml +++ b/action.yml @@ -41,6 +41,10 @@ inputs: description: 'Separator used for the paths output.' required: true default: " " + escape-paths: + description: 'Escape regex special characters used in the `paths` output' + required: true + default: false strip-top-level-dir: description: 'Strip the `$GITHUB_WORKSPACE` from the `paths` output' required: false diff --git a/package.json b/package.json index 0cb5ddee9..5cff6e1fd 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "@actions/github": "5.0.0", "@actions/glob": "0.2.1", "@actions/io": "1.1.2", + "escape-string-regexp": "^5.0.0", "temp-dir": "2.0.0", "uuid": "8.3.2" }, diff --git a/src/main.ts b/src/main.ts index b629f37c1..fb6f1de7b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,6 +2,7 @@ import * as path from 'path' import * as core from '@actions/core' import * as glob from '@actions/glob' import {promises as fs} from 'fs' +import escapeStringRegexp from 'escape-string-regexp' import { getDeletedFiles, @@ -53,6 +54,7 @@ export async function run(): Promise { required: true, trimWhitespace: false }) + const escapePaths = core.getBooleanInput('escape-paths', { required: true }) const stripTopLevelDir = core.getBooleanInput('strip-top-level-dir', { required: true }) @@ -153,7 +155,11 @@ export async function run(): Promise { .filter((p: string) => p !== '') } - const pathsOutput = paths.join(separator) + let pathsOutput = paths.join(separator) + + if (escapePaths) { + pathsOutput = escapeStringRegexp(pathsOutput) + } core.setOutput('paths', pathsOutput) if (pathsOutput) { diff --git a/yarn.lock b/yarn.lock index a4379b0fc..02da6d530 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1527,6 +1527,11 @@ escape-string-regexp@^4.0.0: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== +escape-string-regexp@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz#4683126b500b61762f2dbebace1806e8be31b1c8" + integrity sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw== + escodegen@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-2.0.0.tgz#5e32b12833e8aa8fa35e1bf0befa89380484c7dd"