Add option to convert backslashes in path pattern to forward slashes

The fast-glob library that is internally used interprets backslashes as escape characters. If enabled, all backslashes in provided path will be replaced by forward slashes and act as directory separators. It might be useful when path input variable is composed dynamically from existing directory paths on Windows.

Closes #127
This commit is contained in:
Michal Dorner 2021-06-22 22:33:11 +02:00
parent ad831af420
commit de0b4b9ece
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
6 changed files with 43 additions and 22 deletions

View file

@ -119,6 +119,11 @@ jobs:
# All matched result files must be of the same format
path: ''
# The fast-glob library that is internally used interprets backslashes as escape characters.
# If enabled, all backslashes in provided path will be replaced to forward slashes and act as directory separators.
# It might be useful when path input variable is composed dynamically from existing directory paths on Windows.
path-replace-backslashes: 'false'
# Format of test results. Supported options:
# dart-json
# dotnet-trx

View file

@ -15,6 +15,13 @@ inputs:
Supports wildcards via [fast-glob](https://github.com/mrmlnc/fast-glob)
All matched result files must be of same format
required: true
path-replace-backslashes:
description: |
The fast-glob library that is internally used interprets backslashes as escape characters.
If enabled, all backslashes in provided path will be replaced by forward slashes and act as directory separators.
It might be useful when path input variable is composed dynamically from existing directory paths on Windows.
default: 'false'
required: false
reporter:
description: |
Format of test results. Supported options:

6
dist/index.js generated vendored
View file

@ -239,6 +239,7 @@ class TestReporter {
this.artifact = core.getInput('artifact', { required: false });
this.name = core.getInput('name', { required: true });
this.path = core.getInput('path', { required: true });
this.pathReplaceBackslashes = core.getInput('path-replace-backslashes', { required: false }) === 'true';
this.reporter = core.getInput('reporter', { required: true });
this.listSuites = core.getInput('list-suites', { required: true });
this.listTests = core.getInput('list-tests', { required: true });
@ -268,7 +269,10 @@ class TestReporter {
process.chdir(this.workDirInput);
}
core.info(`Check runs will be created with SHA=${this.context.sha}`);
const pattern = this.path.split(',');
// Split path pattern by ',' and optionally convert all backslashes to forward slashes
// fast-glob (micromatch) always interprets backslashes as escape characters instead of directory separators
const pathsList = this.path.split(',');
const pattern = this.pathReplaceBackslashes ? pathsList.map(path_utils_1.normalizeFilePath) : pathsList;
const inputProvider = this.artifact
? new artifact_provider_1.ArtifactProvider(this.octokit, this.artifact, this.name, pattern, this.context.sha, this.context.runId, this.token)
: new local_file_provider_1.LocalFileProvider(this.name, pattern);

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

36
dist/licenses.txt generated vendored
View file

@ -341,27 +341,27 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
adm-zip
MIT
Copyright (c) 2012 Another-D-Mention Software and other contributors,
http://www.another-d-mention.ro/
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
Copyright (c) 2012 Another-D-Mention Software and other contributors
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
before-after-hook

View file

@ -16,7 +16,7 @@ import {JavaJunitParser} from './parsers/java-junit/java-junit-parser'
import {JestJunitParser} from './parsers/jest-junit/jest-junit-parser'
import {MochaJsonParser} from './parsers/mocha-json/mocha-json-parser'
import {normalizeDirPath} from './utils/path-utils'
import {normalizeDirPath, normalizeFilePath} from './utils/path-utils'
import {getCheckRunContext} from './utils/github-utils'
import {Icon} from './utils/markdown-utils'
@ -33,6 +33,7 @@ class TestReporter {
readonly artifact = core.getInput('artifact', {required: false})
readonly name = core.getInput('name', {required: true})
readonly path = core.getInput('path', {required: true})
readonly pathReplaceBackslashes = core.getInput('path-replace-backslashes', {required: false}) === 'true'
readonly reporter = core.getInput('reporter', {required: true})
readonly listSuites = core.getInput('list-suites', {required: true}) as 'all' | 'failed'
readonly listTests = core.getInput('list-tests', {required: true}) as 'all' | 'failed' | 'none'
@ -71,7 +72,11 @@ class TestReporter {
core.info(`Check runs will be created with SHA=${this.context.sha}`)
const pattern = this.path.split(',')
// Split path pattern by ',' and optionally convert all backslashes to forward slashes
// fast-glob (micromatch) always interprets backslashes as escape characters instead of directory separators
const pathsList = this.path.split(',')
const pattern = this.pathReplaceBackslashes ? pathsList.map(normalizeFilePath) : pathsList
const inputProvider = this.artifact
? new ArtifactProvider(
this.octokit,