Skip to content

Commit

Permalink
Add support for escaping paths output
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 authored Mar 29, 2022
1 parent d2999e3 commit b746fe6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
8 changes: 7 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -53,6 +54,7 @@ export async function run(): Promise<void> {
required: true,
trimWhitespace: false
})
const escapePaths = core.getBooleanInput('escape-paths', { required: true })
const stripTopLevelDir = core.getBooleanInput('strip-top-level-dir', {
required: true
})
Expand Down Expand Up @@ -153,7 +155,11 @@ export async function run(): Promise<void> {
.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) {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b746fe6

Please sign in to comment.