Skip to content

Commit de90cc6

Browse files
committed
Update dist and CHANGELOG for v3.0.2
1 parent cf89abd commit de90cc6

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v3.0.2
4+
- [Add config parameter for predicate quantifier](https://github.com/dorny/paths-filter/pull/224)
5+
36
## v3.0.1
47
- [Compare base and ref when token is empty](https://github.com/dorny/paths-filter/pull/133)
58

dist/index.js

+57-4
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,53 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5353
return (mod && mod.__esModule) ? mod : { "default": mod };
5454
};
5555
Object.defineProperty(exports, "__esModule", ({ value: true }));
56-
exports.Filter = void 0;
56+
exports.Filter = exports.isPredicateQuantifier = exports.SUPPORTED_PREDICATE_QUANTIFIERS = exports.PredicateQuantifier = void 0;
5757
const jsyaml = __importStar(__nccwpck_require__(1917));
5858
const picomatch_1 = __importDefault(__nccwpck_require__(8569));
5959
// Minimatch options used in all matchers
6060
const MatchOptions = {
6161
dot: true
6262
};
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;
6399
class Filter {
64100
// Creates instance of Filter and load rules from YAML if it's provided
65-
constructor(yaml) {
101+
constructor(yaml, filterConfig) {
102+
this.filterConfig = filterConfig;
66103
this.rules = {};
67104
if (yaml) {
68105
this.load(yaml);
@@ -89,7 +126,16 @@ class Filter {
89126
return result;
90127
}
91128
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+
}
93139
}
94140
parseFilterItemYaml(item) {
95141
if (Array.isArray(item)) {
@@ -528,11 +574,18 @@ async function run() {
528574
const filtersYaml = isPathInput(filtersInput) ? getConfigFileContent(filtersInput) : filtersInput;
529575
const listFiles = core.getInput('list-files', { required: false }).toLowerCase() || 'none';
530576
const initialFetchDepth = parseInt(core.getInput('initial-fetch-depth', { required: false })) || 10;
577+
const predicateQuantifier = core.getInput('predicate-quantifier', { required: false }) || filter_1.PredicateQuantifier.SOME;
531578
if (!isExportFormat(listFiles)) {
532579
core.setFailed(`Input parameter 'list-files' is set to invalid value '${listFiles}'`);
533580
return;
534581
}
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);
536589
const files = await getChangedFiles(token, base, ref, initialFetchDepth);
537590
core.info(`Detected ${files.length} changed files`);
538591
const results = filter.match(files);

src/filter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class Filter {
7373
rules: {[key: string]: FilterRuleItem[]} = {}
7474

7575
// Creates instance of Filter and load rules from YAML if it's provided
76-
constructor(yaml?: string, public readonly filterConfig?: FilterConfig) {
76+
constructor(yaml?: string, readonly filterConfig?: FilterConfig) {
7777
if (yaml) {
7878
this.load(yaml)
7979
}
@@ -104,7 +104,7 @@ export class Filter {
104104
}
105105

106106
private isMatch(file: File, patterns: FilterRuleItem[]): boolean {
107-
const aPredicate = (rule: Readonly<FilterRuleItem>) => {
107+
const aPredicate = (rule: Readonly<FilterRuleItem>): boolean => {
108108
return (rule.status === undefined || rule.status.includes(file.status)) && rule.isMatch(file.filename)
109109
}
110110
if (this.filterConfig?.predicateQuantifier === 'every') {

0 commit comments

Comments
 (0)