@@ -53,16 +53,53 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
53
53
return (mod && mod.__esModule) ? mod : { "default": mod };
54
54
};
55
55
Object.defineProperty(exports, "__esModule", ({ value: true }));
56
- exports.Filter = void 0;
56
+ exports.Filter = exports.isPredicateQuantifier = exports.SUPPORTED_PREDICATE_QUANTIFIERS = exports.PredicateQuantifier = void 0;
57
57
const jsyaml = __importStar(__nccwpck_require__(1917));
58
58
const picomatch_1 = __importDefault(__nccwpck_require__(8569));
59
59
// Minimatch options used in all matchers
60
60
const MatchOptions = {
61
61
dot: true
62
62
};
63
+ /**
64
+ * Enumerates the possible logic quantifiers that can be used when determining
65
+ * if a file is a match or not with multiple patterns.
66
+ *
67
+ * The YAML configuration property that is parsed into one of these values is
68
+ * 'predicate-quantifier' on the top level of the configuration object of the
69
+ * action.
70
+ *
71
+ * The default is to use 'some' which used to be the hardcoded behavior prior to
72
+ * the introduction of the new mechanism.
73
+ *
74
+ * @see https://en.wikipedia.org/wiki/Quantifier_(logic)
75
+ */
76
+ var PredicateQuantifier;
77
+ (function (PredicateQuantifier) {
78
+ /**
79
+ * When choosing 'every' in the config it means that files will only get matched
80
+ * if all the patterns are satisfied by the path of the file, not just at least one of them.
81
+ */
82
+ PredicateQuantifier["EVERY"] = "every";
83
+ /**
84
+ * When choosing 'some' in the config it means that files will get matched as long as there is
85
+ * at least one pattern that matches them. This is the default behavior if you don't
86
+ * specify anything as a predicate quantifier.
87
+ */
88
+ PredicateQuantifier["SOME"] = "some";
89
+ })(PredicateQuantifier || (exports.PredicateQuantifier = PredicateQuantifier = {}));
90
+ /**
91
+ * An array of strings (at runtime) that contains the valid/accepted values for
92
+ * the configuration parameter 'predicate-quantifier'.
93
+ */
94
+ exports.SUPPORTED_PREDICATE_QUANTIFIERS = Object.values(PredicateQuantifier);
95
+ function isPredicateQuantifier(x) {
96
+ return exports.SUPPORTED_PREDICATE_QUANTIFIERS.includes(x);
97
+ }
98
+ exports.isPredicateQuantifier = isPredicateQuantifier;
63
99
class Filter {
64
100
// Creates instance of Filter and load rules from YAML if it's provided
65
- constructor(yaml) {
101
+ constructor(yaml, filterConfig) {
102
+ this.filterConfig = filterConfig;
66
103
this.rules = {};
67
104
if (yaml) {
68
105
this.load(yaml);
@@ -89,7 +126,16 @@ class Filter {
89
126
return result;
90
127
}
91
128
isMatch(file, patterns) {
92
- return patterns.some(rule => (rule.status === undefined || rule.status.includes(file.status)) && rule.isMatch(file.filename));
129
+ var _a;
130
+ const aPredicate = (rule) => {
131
+ return (rule.status === undefined || rule.status.includes(file.status)) && rule.isMatch(file.filename);
132
+ };
133
+ if (((_a = this.filterConfig) === null || _a === void 0 ? void 0 : _a.predicateQuantifier) === 'every') {
134
+ return patterns.every(aPredicate);
135
+ }
136
+ else {
137
+ return patterns.some(aPredicate);
138
+ }
93
139
}
94
140
parseFilterItemYaml(item) {
95
141
if (Array.isArray(item)) {
@@ -528,11 +574,18 @@ async function run() {
528
574
const filtersYaml = isPathInput(filtersInput) ? getConfigFileContent(filtersInput) : filtersInput;
529
575
const listFiles = core.getInput('list-files', { required: false }).toLowerCase() || 'none';
530
576
const initialFetchDepth = parseInt(core.getInput('initial-fetch-depth', { required: false })) || 10;
577
+ const predicateQuantifier = core.getInput('predicate-quantifier', { required: false }) || filter_1.PredicateQuantifier.SOME;
531
578
if (!isExportFormat(listFiles)) {
532
579
core.setFailed(`Input parameter 'list-files' is set to invalid value '${listFiles}'`);
533
580
return;
534
581
}
535
- const filter = new filter_1.Filter(filtersYaml);
582
+ if (!(0, filter_1.isPredicateQuantifier)(predicateQuantifier)) {
583
+ const predicateQuantifierInvalidErrorMsg = `Input parameter 'predicate-quantifier' is set to invalid value ` +
584
+ `'${predicateQuantifier}'. Valid values: ${filter_1.SUPPORTED_PREDICATE_QUANTIFIERS.join(', ')}`;
585
+ throw new Error(predicateQuantifierInvalidErrorMsg);
586
+ }
587
+ const filterConfig = { predicateQuantifier };
588
+ const filter = new filter_1.Filter(filtersYaml, filterConfig);
536
589
const files = await getChangedFiles(token, base, ref, initialFetchDepth);
537
590
core.info(`Detected ${files.length} changed files`);
538
591
const results = filter.match(files);
0 commit comments