feat: add support for controlling the pattern order (#1693)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
50a9cc9b7b
commit
892553a457
@ -200,6 +200,10 @@ inputs:
|
|||||||
description: "Fail when the submodule diff fails."
|
description: "Fail when the submodule diff fails."
|
||||||
required: false
|
required: false
|
||||||
default: "false"
|
default: "false"
|
||||||
|
negation_patterns_first:
|
||||||
|
description: "Apply the negation patterns first. **NOTE:** This affects how changed files are matched."
|
||||||
|
required: false
|
||||||
|
default: "false"
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
added_files:
|
added_files:
|
||||||
|
80
dist/index.js
generated
vendored
80
dist/index.js
generated
vendored
@ -1528,6 +1528,9 @@ const getInputs = () => {
|
|||||||
const dirNamesDeletedFilesIncludeOnlyDeletedDirs = core.getBooleanInput('dir_names_deleted_files_include_only_deleted_dirs', {
|
const dirNamesDeletedFilesIncludeOnlyDeletedDirs = core.getBooleanInput('dir_names_deleted_files_include_only_deleted_dirs', {
|
||||||
required: false
|
required: false
|
||||||
});
|
});
|
||||||
|
const negationPatternsFirst = core.getBooleanInput('negation_patterns_first', {
|
||||||
|
required: false
|
||||||
|
});
|
||||||
const inputs = {
|
const inputs = {
|
||||||
files,
|
files,
|
||||||
filesSeparator,
|
filesSeparator,
|
||||||
@ -1578,7 +1581,8 @@ const getInputs = () => {
|
|||||||
outputDir,
|
outputDir,
|
||||||
outputRenamedFilesAsDeletedAndAdded,
|
outputRenamedFilesAsDeletedAndAdded,
|
||||||
token,
|
token,
|
||||||
apiUrl
|
apiUrl,
|
||||||
|
negationPatternsFirst
|
||||||
};
|
};
|
||||||
if (fetchDepth) {
|
if (fetchDepth) {
|
||||||
inputs.fetchDepth = Math.max(parseInt(fetchDepth, 10), 2);
|
inputs.fetchDepth = Math.max(parseInt(fetchDepth, 10), 2);
|
||||||
@ -2542,60 +2546,68 @@ const getDirNamesIncludeFilesPattern = ({ inputs }) => {
|
|||||||
};
|
};
|
||||||
exports.getDirNamesIncludeFilesPattern = getDirNamesIncludeFilesPattern;
|
exports.getDirNamesIncludeFilesPattern = getDirNamesIncludeFilesPattern;
|
||||||
const getFilePatterns = ({ inputs, workingDirectory }) => __awaiter(void 0, void 0, void 0, function* () {
|
const getFilePatterns = ({ inputs, workingDirectory }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
let filePatterns = '';
|
let cleanedFilePatterns = [];
|
||||||
|
if (inputs.files) {
|
||||||
|
const filesPatterns = inputs.files
|
||||||
|
.split(inputs.filesSeparator)
|
||||||
|
.filter(Boolean);
|
||||||
|
cleanedFilePatterns.push(...filesPatterns);
|
||||||
|
core.debug(`files patterns: ${filesPatterns.join('\n')}`);
|
||||||
|
}
|
||||||
|
if (inputs.filesFromSourceFile !== '') {
|
||||||
|
const inputFilesFromSourceFile = inputs.filesFromSourceFile
|
||||||
|
.split(inputs.filesFromSourceFileSeparator)
|
||||||
|
.filter(Boolean)
|
||||||
|
.map(p => path.join(workingDirectory, p));
|
||||||
|
core.debug(`files from source file: ${inputFilesFromSourceFile}`);
|
||||||
|
const filesFromSourceFiles = yield getFilesFromSourceFile({
|
||||||
|
filePaths: inputFilesFromSourceFile
|
||||||
|
});
|
||||||
|
core.debug(`files from source files patterns: ${filesFromSourceFiles.join('\n')}`);
|
||||||
|
cleanedFilePatterns.push(...filesFromSourceFiles);
|
||||||
|
}
|
||||||
if (inputs.filesIgnore) {
|
if (inputs.filesIgnore) {
|
||||||
const filesIgnorePatterns = inputs.filesIgnore
|
const filesIgnorePatterns = inputs.filesIgnore
|
||||||
.split(inputs.filesIgnoreSeparator)
|
.split(inputs.filesIgnoreSeparator)
|
||||||
.filter(p => p !== '')
|
.filter(Boolean)
|
||||||
.map(p => {
|
.map(p => {
|
||||||
if (!p.startsWith('!')) {
|
if (!p.startsWith('!')) {
|
||||||
p = `!${p}`;
|
p = `!${p}`;
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
})
|
});
|
||||||
.join('\n');
|
core.debug(`files ignore patterns: ${filesIgnorePatterns.join('\n')}`);
|
||||||
core.debug(`files ignore patterns: ${filesIgnorePatterns}`);
|
cleanedFilePatterns.push(...filesIgnorePatterns);
|
||||||
filePatterns = filePatterns.concat('\n', filesIgnorePatterns);
|
|
||||||
}
|
}
|
||||||
if (inputs.filesIgnoreFromSourceFile) {
|
if (inputs.filesIgnoreFromSourceFile) {
|
||||||
const inputFilesIgnoreFromSourceFile = inputs.filesIgnoreFromSourceFile
|
const inputFilesIgnoreFromSourceFile = inputs.filesIgnoreFromSourceFile
|
||||||
.split(inputs.filesIgnoreFromSourceFileSeparator)
|
.split(inputs.filesIgnoreFromSourceFileSeparator)
|
||||||
.filter(p => p !== '')
|
.filter(Boolean)
|
||||||
.map(p => path.join(workingDirectory, p));
|
.map(p => path.join(workingDirectory, p));
|
||||||
core.debug(`files ignore from source file: ${inputFilesIgnoreFromSourceFile}`);
|
core.debug(`files ignore from source file: ${inputFilesIgnoreFromSourceFile}`);
|
||||||
const filesIgnoreFromSourceFiles = (yield getFilesFromSourceFile({
|
const filesIgnoreFromSourceFiles = yield getFilesFromSourceFile({
|
||||||
filePaths: inputFilesIgnoreFromSourceFile,
|
filePaths: inputFilesIgnoreFromSourceFile,
|
||||||
excludedFiles: true
|
excludedFiles: true
|
||||||
})).join('\n');
|
});
|
||||||
core.debug(`files ignore from source files patterns: ${filesIgnoreFromSourceFiles}`);
|
core.debug(`files ignore from source files patterns: ${filesIgnoreFromSourceFiles.join('\n')}`);
|
||||||
filePatterns = filePatterns.concat('\n', filesIgnoreFromSourceFiles);
|
cleanedFilePatterns.push(...filesIgnoreFromSourceFiles);
|
||||||
}
|
}
|
||||||
if (inputs.files) {
|
if (inputs.negationPatternsFirst) {
|
||||||
filePatterns = filePatterns.concat('\n', inputs.files.split(inputs.filesSeparator).filter(Boolean).join('\n'));
|
cleanedFilePatterns.sort((a, b) => {
|
||||||
|
return a.startsWith('!') ? -1 : b.startsWith('!') ? 1 : 0;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (inputs.filesFromSourceFile !== '') {
|
// Reorder file patterns '**' should come first
|
||||||
const inputFilesFromSourceFile = inputs.filesFromSourceFile
|
if (cleanedFilePatterns.includes('**')) {
|
||||||
.split(inputs.filesFromSourceFileSeparator)
|
cleanedFilePatterns.sort((a, b) => {
|
||||||
.filter(p => p !== '')
|
|
||||||
.map(p => path.join(workingDirectory, p));
|
|
||||||
core.debug(`files from source file: ${inputFilesFromSourceFile}`);
|
|
||||||
const filesFromSourceFiles = (yield getFilesFromSourceFile({ filePaths: inputFilesFromSourceFile })).join('\n');
|
|
||||||
core.debug(`files from source files patterns: ${filesFromSourceFiles}`);
|
|
||||||
filePatterns = filePatterns.concat('\n', filesFromSourceFiles);
|
|
||||||
}
|
|
||||||
if ((0, exports.isWindows)()) {
|
|
||||||
filePatterns = filePatterns.replace(/\r\n/g, '\n');
|
|
||||||
filePatterns = filePatterns.replace(/\r/g, '\n');
|
|
||||||
}
|
|
||||||
const filePatternsArray = filePatterns.trim().split('\n').filter(Boolean);
|
|
||||||
// Reorder file patterns '**' should come before '!**/*.txt' and then the rest 'dir/**/*.txt'
|
|
||||||
if (filePatternsArray.includes('**')) {
|
|
||||||
filePatternsArray.sort((a, b) => {
|
|
||||||
return a === '**' ? -1 : b === '**' ? 1 : 0;
|
return a === '**' ? -1 : b === '**' ? 1 : 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
core.debug(`Input file patterns: \n${filePatternsArray.join('\n')}`);
|
if ((0, exports.isWindows)()) {
|
||||||
return filePatternsArray;
|
cleanedFilePatterns = cleanedFilePatterns.map(pattern => pattern.replace(/\r\n/g, '\n').replace(/\r/g, '\n'));
|
||||||
|
}
|
||||||
|
core.debug(`Input file patterns: \n${cleanedFilePatterns.join('\n')}`);
|
||||||
|
return cleanedFilePatterns;
|
||||||
});
|
});
|
||||||
exports.getFilePatterns = getFilePatterns;
|
exports.getFilePatterns = getFilePatterns;
|
||||||
const getYamlFilePatternsFromContents = ({ content = '', filePath = '', excludedFiles = false }) => __awaiter(void 0, void 0, void 0, function* () {
|
const getYamlFilePatternsFromContents = ({ content = '', filePath = '', excludedFiles = false }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@ -51,6 +51,7 @@ export type Inputs = {
|
|||||||
skipInitialFetch: boolean
|
skipInitialFetch: boolean
|
||||||
failOnInitialDiffError: boolean
|
failOnInitialDiffError: boolean
|
||||||
failOnSubmoduleDiffError: boolean
|
failOnSubmoduleDiffError: boolean
|
||||||
|
negationPatternsFirst: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getInputs = (): Inputs => {
|
export const getInputs = (): Inputs => {
|
||||||
@ -218,6 +219,13 @@ export const getInputs = (): Inputs => {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const negationPatternsFirst = core.getBooleanInput(
|
||||||
|
'negation_patterns_first',
|
||||||
|
{
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const inputs: Inputs = {
|
const inputs: Inputs = {
|
||||||
files,
|
files,
|
||||||
filesSeparator,
|
filesSeparator,
|
||||||
@ -268,7 +276,8 @@ export const getInputs = (): Inputs => {
|
|||||||
outputDir,
|
outputDir,
|
||||||
outputRenamedFilesAsDeletedAndAdded,
|
outputRenamedFilesAsDeletedAndAdded,
|
||||||
token,
|
token,
|
||||||
apiUrl
|
apiUrl,
|
||||||
|
negationPatternsFirst
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fetchDepth) {
|
if (fetchDepth) {
|
||||||
|
99
src/utils.ts
99
src/utils.ts
@ -938,90 +938,99 @@ export const getFilePatterns = async ({
|
|||||||
inputs: Inputs
|
inputs: Inputs
|
||||||
workingDirectory: string
|
workingDirectory: string
|
||||||
}): Promise<string[]> => {
|
}): Promise<string[]> => {
|
||||||
let filePatterns = ''
|
let cleanedFilePatterns: string[] = []
|
||||||
|
|
||||||
|
if (inputs.files) {
|
||||||
|
const filesPatterns = inputs.files
|
||||||
|
.split(inputs.filesSeparator)
|
||||||
|
.filter(Boolean)
|
||||||
|
|
||||||
|
cleanedFilePatterns.push(...filesPatterns)
|
||||||
|
|
||||||
|
core.debug(`files patterns: ${filesPatterns.join('\n')}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputs.filesFromSourceFile !== '') {
|
||||||
|
const inputFilesFromSourceFile = inputs.filesFromSourceFile
|
||||||
|
.split(inputs.filesFromSourceFileSeparator)
|
||||||
|
.filter(Boolean)
|
||||||
|
.map(p => path.join(workingDirectory, p))
|
||||||
|
|
||||||
|
core.debug(`files from source file: ${inputFilesFromSourceFile}`)
|
||||||
|
|
||||||
|
const filesFromSourceFiles = await getFilesFromSourceFile({
|
||||||
|
filePaths: inputFilesFromSourceFile
|
||||||
|
})
|
||||||
|
|
||||||
|
core.debug(
|
||||||
|
`files from source files patterns: ${filesFromSourceFiles.join('\n')}`
|
||||||
|
)
|
||||||
|
|
||||||
|
cleanedFilePatterns.push(...filesFromSourceFiles)
|
||||||
|
}
|
||||||
|
|
||||||
if (inputs.filesIgnore) {
|
if (inputs.filesIgnore) {
|
||||||
const filesIgnorePatterns = inputs.filesIgnore
|
const filesIgnorePatterns = inputs.filesIgnore
|
||||||
.split(inputs.filesIgnoreSeparator)
|
.split(inputs.filesIgnoreSeparator)
|
||||||
.filter(p => p !== '')
|
.filter(Boolean)
|
||||||
.map(p => {
|
.map(p => {
|
||||||
if (!p.startsWith('!')) {
|
if (!p.startsWith('!')) {
|
||||||
p = `!${p}`
|
p = `!${p}`
|
||||||
}
|
}
|
||||||
return p
|
return p
|
||||||
})
|
})
|
||||||
.join('\n')
|
|
||||||
|
|
||||||
core.debug(`files ignore patterns: ${filesIgnorePatterns}`)
|
core.debug(`files ignore patterns: ${filesIgnorePatterns.join('\n')}`)
|
||||||
|
|
||||||
filePatterns = filePatterns.concat('\n', filesIgnorePatterns)
|
cleanedFilePatterns.push(...filesIgnorePatterns)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputs.filesIgnoreFromSourceFile) {
|
if (inputs.filesIgnoreFromSourceFile) {
|
||||||
const inputFilesIgnoreFromSourceFile = inputs.filesIgnoreFromSourceFile
|
const inputFilesIgnoreFromSourceFile = inputs.filesIgnoreFromSourceFile
|
||||||
.split(inputs.filesIgnoreFromSourceFileSeparator)
|
.split(inputs.filesIgnoreFromSourceFileSeparator)
|
||||||
.filter(p => p !== '')
|
.filter(Boolean)
|
||||||
.map(p => path.join(workingDirectory, p))
|
.map(p => path.join(workingDirectory, p))
|
||||||
|
|
||||||
core.debug(
|
core.debug(
|
||||||
`files ignore from source file: ${inputFilesIgnoreFromSourceFile}`
|
`files ignore from source file: ${inputFilesIgnoreFromSourceFile}`
|
||||||
)
|
)
|
||||||
|
|
||||||
const filesIgnoreFromSourceFiles = (
|
const filesIgnoreFromSourceFiles = await getFilesFromSourceFile({
|
||||||
await getFilesFromSourceFile({
|
|
||||||
filePaths: inputFilesIgnoreFromSourceFile,
|
filePaths: inputFilesIgnoreFromSourceFile,
|
||||||
excludedFiles: true
|
excludedFiles: true
|
||||||
})
|
})
|
||||||
).join('\n')
|
|
||||||
|
|
||||||
core.debug(
|
core.debug(
|
||||||
`files ignore from source files patterns: ${filesIgnoreFromSourceFiles}`
|
`files ignore from source files patterns: ${filesIgnoreFromSourceFiles.join(
|
||||||
|
'\n'
|
||||||
|
)}`
|
||||||
)
|
)
|
||||||
|
|
||||||
filePatterns = filePatterns.concat('\n', filesIgnoreFromSourceFiles)
|
cleanedFilePatterns.push(...filesIgnoreFromSourceFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputs.files) {
|
if (inputs.negationPatternsFirst) {
|
||||||
filePatterns = filePatterns.concat(
|
cleanedFilePatterns.sort((a, b) => {
|
||||||
'\n',
|
return a.startsWith('!') ? -1 : b.startsWith('!') ? 1 : 0
|
||||||
inputs.files.split(inputs.filesSeparator).filter(Boolean).join('\n')
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputs.filesFromSourceFile !== '') {
|
// Reorder file patterns '**' should come first
|
||||||
const inputFilesFromSourceFile = inputs.filesFromSourceFile
|
if (cleanedFilePatterns.includes('**')) {
|
||||||
.split(inputs.filesFromSourceFileSeparator)
|
cleanedFilePatterns.sort((a, b) => {
|
||||||
.filter(p => p !== '')
|
|
||||||
.map(p => path.join(workingDirectory, p))
|
|
||||||
|
|
||||||
core.debug(`files from source file: ${inputFilesFromSourceFile}`)
|
|
||||||
|
|
||||||
const filesFromSourceFiles = (
|
|
||||||
await getFilesFromSourceFile({filePaths: inputFilesFromSourceFile})
|
|
||||||
).join('\n')
|
|
||||||
|
|
||||||
core.debug(`files from source files patterns: ${filesFromSourceFiles}`)
|
|
||||||
|
|
||||||
filePatterns = filePatterns.concat('\n', filesFromSourceFiles)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isWindows()) {
|
|
||||||
filePatterns = filePatterns.replace(/\r\n/g, '\n')
|
|
||||||
filePatterns = filePatterns.replace(/\r/g, '\n')
|
|
||||||
}
|
|
||||||
|
|
||||||
const filePatternsArray = filePatterns.trim().split('\n').filter(Boolean)
|
|
||||||
|
|
||||||
// Reorder file patterns '**' should come before '!**/*.txt' and then the rest 'dir/**/*.txt'
|
|
||||||
if (filePatternsArray.includes('**')) {
|
|
||||||
filePatternsArray.sort((a, b) => {
|
|
||||||
return a === '**' ? -1 : b === '**' ? 1 : 0
|
return a === '**' ? -1 : b === '**' ? 1 : 0
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(`Input file patterns: \n${filePatternsArray.join('\n')}`)
|
if (isWindows()) {
|
||||||
|
cleanedFilePatterns = cleanedFilePatterns.map(pattern =>
|
||||||
|
pattern.replace(/\r\n/g, '\n').replace(/\r/g, '\n')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return filePatternsArray
|
core.debug(`Input file patterns: \n${cleanedFilePatterns.join('\n')}`)
|
||||||
|
|
||||||
|
return cleanedFilePatterns
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example YAML input:
|
// Example YAML input:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user