mirror of
https://github.com/tj-actions/changed-files
synced 2025-03-05 11:06:22 +00:00
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
5 changed files with 118 additions and 84 deletions
|
@ -200,6 +200,10 @@ inputs:
|
|||
description: "Fail when the submodule diff fails."
|
||||
required: 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:
|
||||
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', {
|
||||
required: false
|
||||
});
|
||||
const negationPatternsFirst = core.getBooleanInput('negation_patterns_first', {
|
||||
required: false
|
||||
});
|
||||
const inputs = {
|
||||
files,
|
||||
filesSeparator,
|
||||
|
@ -1578,7 +1581,8 @@ const getInputs = () => {
|
|||
outputDir,
|
||||
outputRenamedFilesAsDeletedAndAdded,
|
||||
token,
|
||||
apiUrl
|
||||
apiUrl,
|
||||
negationPatternsFirst
|
||||
};
|
||||
if (fetchDepth) {
|
||||
inputs.fetchDepth = Math.max(parseInt(fetchDepth, 10), 2);
|
||||
|
@ -2542,60 +2546,68 @@ const getDirNamesIncludeFilesPattern = ({ inputs }) => {
|
|||
};
|
||||
exports.getDirNamesIncludeFilesPattern = getDirNamesIncludeFilesPattern;
|
||||
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) {
|
||||
const filesIgnorePatterns = inputs.filesIgnore
|
||||
.split(inputs.filesIgnoreSeparator)
|
||||
.filter(p => p !== '')
|
||||
.filter(Boolean)
|
||||
.map(p => {
|
||||
if (!p.startsWith('!')) {
|
||||
p = `!${p}`;
|
||||
}
|
||||
return p;
|
||||
})
|
||||
.join('\n');
|
||||
core.debug(`files ignore patterns: ${filesIgnorePatterns}`);
|
||||
filePatterns = filePatterns.concat('\n', filesIgnorePatterns);
|
||||
});
|
||||
core.debug(`files ignore patterns: ${filesIgnorePatterns.join('\n')}`);
|
||||
cleanedFilePatterns.push(...filesIgnorePatterns);
|
||||
}
|
||||
if (inputs.filesIgnoreFromSourceFile) {
|
||||
const inputFilesIgnoreFromSourceFile = inputs.filesIgnoreFromSourceFile
|
||||
.split(inputs.filesIgnoreFromSourceFileSeparator)
|
||||
.filter(p => p !== '')
|
||||
.filter(Boolean)
|
||||
.map(p => path.join(workingDirectory, p));
|
||||
core.debug(`files ignore from source file: ${inputFilesIgnoreFromSourceFile}`);
|
||||
const filesIgnoreFromSourceFiles = (yield getFilesFromSourceFile({
|
||||
const filesIgnoreFromSourceFiles = yield getFilesFromSourceFile({
|
||||
filePaths: inputFilesIgnoreFromSourceFile,
|
||||
excludedFiles: true
|
||||
})).join('\n');
|
||||
core.debug(`files ignore from source files patterns: ${filesIgnoreFromSourceFiles}`);
|
||||
filePatterns = filePatterns.concat('\n', filesIgnoreFromSourceFiles);
|
||||
});
|
||||
core.debug(`files ignore from source files patterns: ${filesIgnoreFromSourceFiles.join('\n')}`);
|
||||
cleanedFilePatterns.push(...filesIgnoreFromSourceFiles);
|
||||
}
|
||||
if (inputs.files) {
|
||||
filePatterns = filePatterns.concat('\n', inputs.files.split(inputs.filesSeparator).filter(Boolean).join('\n'));
|
||||
if (inputs.negationPatternsFirst) {
|
||||
cleanedFilePatterns.sort((a, b) => {
|
||||
return a.startsWith('!') ? -1 : b.startsWith('!') ? 1 : 0;
|
||||
});
|
||||
}
|
||||
if (inputs.filesFromSourceFile !== '') {
|
||||
const inputFilesFromSourceFile = inputs.filesFromSourceFile
|
||||
.split(inputs.filesFromSourceFileSeparator)
|
||||
.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) => {
|
||||
// Reorder file patterns '**' should come first
|
||||
if (cleanedFilePatterns.includes('**')) {
|
||||
cleanedFilePatterns.sort((a, b) => {
|
||||
return a === '**' ? -1 : b === '**' ? 1 : 0;
|
||||
});
|
||||
}
|
||||
core.debug(`Input file patterns: \n${filePatternsArray.join('\n')}`);
|
||||
return filePatternsArray;
|
||||
if ((0, exports.isWindows)()) {
|
||||
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;
|
||||
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
|
||||
failOnInitialDiffError: boolean
|
||||
failOnSubmoduleDiffError: boolean
|
||||
negationPatternsFirst: boolean
|
||||
}
|
||||
|
||||
export const getInputs = (): Inputs => {
|
||||
|
@ -218,6 +219,13 @@ export const getInputs = (): Inputs => {
|
|||
}
|
||||
)
|
||||
|
||||
const negationPatternsFirst = core.getBooleanInput(
|
||||
'negation_patterns_first',
|
||||
{
|
||||
required: false
|
||||
}
|
||||
)
|
||||
|
||||
const inputs: Inputs = {
|
||||
files,
|
||||
filesSeparator,
|
||||
|
@ -268,7 +276,8 @@ export const getInputs = (): Inputs => {
|
|||
outputDir,
|
||||
outputRenamedFilesAsDeletedAndAdded,
|
||||
token,
|
||||
apiUrl
|
||||
apiUrl,
|
||||
negationPatternsFirst
|
||||
}
|
||||
|
||||
if (fetchDepth) {
|
||||
|
|
105
src/utils.ts
105
src/utils.ts
|
@ -938,90 +938,99 @@ export const getFilePatterns = async ({
|
|||
inputs: Inputs
|
||||
workingDirectory: 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) {
|
||||
const filesIgnorePatterns = inputs.filesIgnore
|
||||
.split(inputs.filesIgnoreSeparator)
|
||||
.filter(p => p !== '')
|
||||
.filter(Boolean)
|
||||
.map(p => {
|
||||
if (!p.startsWith('!')) {
|
||||
p = `!${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) {
|
||||
const inputFilesIgnoreFromSourceFile = inputs.filesIgnoreFromSourceFile
|
||||
.split(inputs.filesIgnoreFromSourceFileSeparator)
|
||||
.filter(p => p !== '')
|
||||
.filter(Boolean)
|
||||
.map(p => path.join(workingDirectory, p))
|
||||
|
||||
core.debug(
|
||||
`files ignore from source file: ${inputFilesIgnoreFromSourceFile}`
|
||||
)
|
||||
|
||||
const filesIgnoreFromSourceFiles = (
|
||||
await getFilesFromSourceFile({
|
||||
filePaths: inputFilesIgnoreFromSourceFile,
|
||||
excludedFiles: true
|
||||
})
|
||||
).join('\n')
|
||||
const filesIgnoreFromSourceFiles = await getFilesFromSourceFile({
|
||||
filePaths: inputFilesIgnoreFromSourceFile,
|
||||
excludedFiles: true
|
||||
})
|
||||
|
||||
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) {
|
||||
filePatterns = filePatterns.concat(
|
||||
'\n',
|
||||
inputs.files.split(inputs.filesSeparator).filter(Boolean).join('\n')
|
||||
)
|
||||
if (inputs.negationPatternsFirst) {
|
||||
cleanedFilePatterns.sort((a, b) => {
|
||||
return a.startsWith('!') ? -1 : b.startsWith('!') ? 1 : 0
|
||||
})
|
||||
}
|
||||
|
||||
if (inputs.filesFromSourceFile !== '') {
|
||||
const inputFilesFromSourceFile = inputs.filesFromSourceFile
|
||||
.split(inputs.filesFromSourceFileSeparator)
|
||||
.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) => {
|
||||
// Reorder file patterns '**' should come first
|
||||
if (cleanedFilePatterns.includes('**')) {
|
||||
cleanedFilePatterns.sort((a, b) => {
|
||||
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:
|
||||
|
|
Loading…
Add table
Reference in a new issue