feat: add support for returning posix path separator on windows (#2056)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
@@ -55,6 +55,7 @@ exports[`getInputs should correctly parse boolean inputs 1`] = `
|
||||
"skipInitialFetch": "true",
|
||||
"token": "",
|
||||
"until": "",
|
||||
"usePosixPathSeparator": "false",
|
||||
"useRestApi": "false",
|
||||
"writeOutputFiles": "false",
|
||||
}
|
||||
@@ -114,6 +115,7 @@ exports[`getInputs should correctly parse numeric inputs 1`] = `
|
||||
"skipInitialFetch": false,
|
||||
"token": "",
|
||||
"until": "",
|
||||
"usePosixPathSeparator": false,
|
||||
"useRestApi": false,
|
||||
"writeOutputFiles": false,
|
||||
}
|
||||
@@ -171,6 +173,7 @@ exports[`getInputs should correctly parse string inputs 1`] = `
|
||||
"skipInitialFetch": false,
|
||||
"token": "token",
|
||||
"until": "",
|
||||
"usePosixPathSeparator": false,
|
||||
"useRestApi": false,
|
||||
"writeOutputFiles": false,
|
||||
}
|
||||
@@ -230,6 +233,7 @@ exports[`getInputs should handle invalid numeric inputs correctly 1`] = `
|
||||
"skipInitialFetch": false,
|
||||
"token": "",
|
||||
"until": "",
|
||||
"usePosixPathSeparator": false,
|
||||
"useRestApi": false,
|
||||
"writeOutputFiles": false,
|
||||
}
|
||||
@@ -289,6 +293,7 @@ exports[`getInputs should handle negative numeric inputs correctly 1`] = `
|
||||
"skipInitialFetch": false,
|
||||
"token": "",
|
||||
"until": "",
|
||||
"usePosixPathSeparator": false,
|
||||
"useRestApi": false,
|
||||
"writeOutputFiles": false,
|
||||
}
|
||||
@@ -349,6 +354,7 @@ exports[`getInputs should return default values when no inputs are provided 1`]
|
||||
"skipInitialFetch": false,
|
||||
"token": "",
|
||||
"until": "",
|
||||
"usePosixPathSeparator": false,
|
||||
"useRestApi": false,
|
||||
"writeOutputFiles": false,
|
||||
}
|
||||
|
||||
@@ -637,7 +637,8 @@ describe('utils test', () => {
|
||||
negationPatternsFirst: false,
|
||||
useRestApi: false,
|
||||
excludeSubmodules: false,
|
||||
fetchMissingHistoryMaxRetries: 10
|
||||
fetchMissingHistoryMaxRetries: 10,
|
||||
usePosixPathSeparator: false
|
||||
}
|
||||
|
||||
const coreWarningSpy = jest.spyOn(core, 'warning')
|
||||
|
||||
@@ -2,6 +2,7 @@ import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import type {RestEndpointMethodTypes} from '@octokit/rest'
|
||||
import flatten from 'lodash/flatten'
|
||||
import convertPath from '@stdlib/utils-convert-path'
|
||||
import mm from 'micromatch'
|
||||
import * as path from 'path'
|
||||
import {setOutputsAndGetModifiedAndChangedFilesStatus} from './changedFilesOutput'
|
||||
@@ -355,7 +356,11 @@ function* getChangeTypeFilesGenerator({
|
||||
filePaths,
|
||||
dirNamesIncludeFilePatterns
|
||||
})) {
|
||||
yield filePath
|
||||
if (isWindows() && inputs.usePosixPathSeparator) {
|
||||
yield convertPath(filePath, 'mixed')
|
||||
} else {
|
||||
yield filePath
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -402,7 +407,11 @@ function* getAllChangeTypeFilesGenerator({
|
||||
filePaths,
|
||||
dirNamesIncludeFilePatterns
|
||||
})) {
|
||||
yield filePath
|
||||
if (isWindows() && inputs.usePosixPathSeparator) {
|
||||
yield convertPath(filePath, 'mixed')
|
||||
} else {
|
||||
yield filePath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,5 +22,6 @@ export const DEFAULT_VALUES_OF_UNSUPPORTED_API_INPUTS: Partial<Inputs> = {
|
||||
fetchAdditionalSubmoduleHistory: false,
|
||||
dirNamesDeletedFilesIncludeOnlyDeletedDirs: false,
|
||||
excludeSubmodules: false,
|
||||
fetchMissingHistoryMaxRetries: 10
|
||||
fetchMissingHistoryMaxRetries: 10,
|
||||
usePosixPathSeparator: false
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ export type Inputs = {
|
||||
useRestApi: boolean
|
||||
excludeSubmodules: boolean
|
||||
fetchMissingHistoryMaxRetries?: number
|
||||
usePosixPathSeparator: boolean
|
||||
}
|
||||
|
||||
export const getInputs = (): Inputs => {
|
||||
@@ -251,6 +252,13 @@ export const getInputs = (): Inputs => {
|
||||
{required: false}
|
||||
)
|
||||
|
||||
const usePosixPathSeparator = core.getBooleanInput(
|
||||
'use_posix_path_separator',
|
||||
{
|
||||
required: false
|
||||
}
|
||||
)
|
||||
|
||||
const inputs: Inputs = {
|
||||
files,
|
||||
filesSeparator,
|
||||
@@ -291,6 +299,7 @@ export const getInputs = (): Inputs => {
|
||||
fetchAdditionalSubmoduleHistory,
|
||||
dirNamesDeletedFilesIncludeOnlyDeletedDirs,
|
||||
excludeSubmodules,
|
||||
usePosixPathSeparator,
|
||||
// End Not Supported via REST API
|
||||
dirNames,
|
||||
dirNamesExcludeCurrentDir,
|
||||
|
||||
@@ -32,11 +32,13 @@ export const normalizeSeparators = (p: string): string => {
|
||||
|
||||
// Remove redundant slashes
|
||||
const isUnc = /^\\\\+[^\\]/.test(p) // e.g. \\hello
|
||||
return (isUnc ? '\\' : '') + p.replace(/\\\\+/g, '\\') // preserve leading \\ for UNC
|
||||
p = (isUnc ? '\\' : '') + p.replace(/\\\\+/g, '\\') // preserve leading \\ for UNC
|
||||
} else {
|
||||
// Remove redundant slashes on Linux/macOS
|
||||
p = p.replace(/\/\/+/g, '/')
|
||||
}
|
||||
|
||||
// Remove redundant slashes
|
||||
return p.replace(/\/\/+/g, '/')
|
||||
return p
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user