@@ -16,8 +16,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1616 });
1717};
1818Object.defineProperty(exports, "__esModule", ({ value: true }));
19- exports.execCommand = void 0;
19+ exports.setOutputs = exports.execCommand = void 0;
20+ const core_1 = __nccwpck_require__(5316);
2021const exec_1 = __nccwpck_require__(110);
22+ const serialization_utils_1 = __nccwpck_require__(9091);
2123function execCommand(command) {
2224 return __awaiter(this, void 0, void 0, function* () {
2325 const { stdout, stderr, exitCode } = yield (0, exec_1.getExecOutput)(command);
@@ -28,6 +30,12 @@ function execCommand(command) {
2830 });
2931}
3032exports.execCommand = execCommand;
33+ function setOutputs(values) {
34+ for (const [key, value] of Object.entries(values)) {
35+ (0, core_1.setOutput)(key, (0, serialization_utils_1.stringifyForShell)(value));
36+ }
37+ }
38+ exports.setOutputs = setOutputs;
3139
3240
3341/***/ }),
@@ -126,7 +134,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
126134 return result;
127135};
128136Object.defineProperty(exports, "__esModule", ({ value: true }));
129- exports.filterPaths = void 0;
137+ exports.testPath = exports.normalizePatterns = exports. filterPaths = void 0;
130138const core = __importStar(__nccwpck_require__(5316));
131139const minimatch_1 = __nccwpck_require__(148);
132140const NEGATION = '!';
@@ -144,16 +152,26 @@ function filterPaths(paths, patterns) {
144152}
145153exports.filterPaths = filterPaths;
146154function filterPathsImpl(paths, patterns) {
147- return (patterns === null || patterns === void 0 ? void 0 : patterns.length) === 0
155+ const normalizedPatterns = normalizePatterns(patterns);
156+ return normalizedPatterns === undefined
148157 ? paths
149- : paths.filter(path => {
150- return patterns.reduce((prevResult, pattern) => {
151- return pattern.startsWith(NEGATION)
152- ? prevResult && !match(path, pattern.substring(1) )
153- : prevResult || match(path, pattern) ;
154- }, false );
155- } );
158+ : paths.filter(path => testPath(path, normalizedPatterns));
159+ }
160+ function normalizePatterns(patterns) {
161+ if (!patterns )
162+ return undefined ;
163+ const notEmptyPatterns = patterns.filter(p => p != undefined && p.length > 0 );
164+ return (notEmptyPatterns.length > 0 ? notEmptyPatterns : undefined );
156165}
166+ exports.normalizePatterns = normalizePatterns;
167+ function testPath(path, patterns) {
168+ return patterns.reduce((prevResult, pattern) => {
169+ return pattern.startsWith(NEGATION)
170+ ? prevResult && !match(path, pattern.substring(1))
171+ : prevResult || match(path, pattern);
172+ }, false);
173+ }
174+ exports.testPath = testPath;
157175
158176
159177/***/ }),
@@ -251,12 +269,12 @@ function getChangedFilesImpl(token) {
251269 core.setFailed('Getting changed files only works on pull request events.');
252270 return [];
253271 }
254- const files = yield octokit.paginate(octokit.rest.pulls.listFiles, {
272+ const entries = yield octokit.paginate(octokit.rest.pulls.listFiles, {
255273 owner: github_1.context.repo.owner,
256274 repo: github_1.context.repo.repo,
257275 pull_number: github_1.context.payload.pull_request.number,
258276 });
259- return files .map(file => file. filename);
277+ return entries .map(({ filename, status }) => ({ path: filename, status }) );
260278 }
261279 catch (error) {
262280 core.setFailed(`Getting changed files failed with error: ${error}`);
@@ -266,6 +284,44 @@ function getChangedFilesImpl(token) {
266284}
267285
268286
287+ /***/ }),
288+
289+ /***/ 9091:
290+ /***/ ((__unused_webpack_module, exports) => {
291+
292+ "use strict";
293+
294+ Object.defineProperty(exports, "__esModule", ({ value: true }));
295+ exports.stringifyForShell = void 0;
296+ function stringifyArrayItem(item) {
297+ switch (typeof item) {
298+ case 'number':
299+ return item.toString();
300+ case 'string':
301+ return `'${item}'`;
302+ default:
303+ return JSON.stringify(item);
304+ }
305+ }
306+ function stringifyForShell(value) {
307+ switch (typeof value) {
308+ case 'string':
309+ return value;
310+ case 'object':
311+ if (Array.isArray(value)) {
312+ return value.map(stringifyArrayItem).join(' ');
313+ }
314+ if (value === null) {
315+ return '';
316+ }
317+ return value.toString();
318+ default:
319+ return JSON.stringify(value);
320+ }
321+ }
322+ exports.stringifyForShell = stringifyForShell;
323+
324+
269325/***/ }),
270326
271327/***/ 2013:
@@ -522,14 +578,24 @@ const common_1 = __nccwpck_require__(9145);
522578function run() {
523579 return __awaiter(this, void 0, void 0, function* () {
524580 try {
525- const pathPatterns = core.getInput(common_1.inputs.PATHS).split(';');
581+ const patterns = (0, common_1.normalizePatterns)( core.getInput(common_1.inputs.PATHS).split(';') );
526582 const token = core.getInput(common_1.inputs.GH_TOKEN, { required: true });
527583 const output = core.getInput(common_1.inputs.OUTPUT, { required: true });
528- console.log('patterns: ' + JSON.stringify(pathPatterns , undefined, 2));
584+ console.log('patterns: ' + JSON.stringify(patterns , undefined, 2));
529585 const changedFiles = yield (0, common_1.getChangedFiles)(token);
530- const filteredFiles = (0, common_1.filterPaths)(changedFiles, pathPatterns);
586+ const filteredFiles = patterns === undefined
587+ ? changedFiles
588+ : changedFiles.filter(({ path }) => (0, common_1.testPath)(path, patterns));
531589 (0, common_1.ensureDir)(output);
532- fs.writeFileSync(output, JSON.stringify(filteredFiles.map(filename => ({ filename })), undefined, 2));
590+ fs.writeFileSync(output, JSON.stringify(filteredFiles.map(({ path }) => ({ filename: path })), undefined, 2));
591+ (0, common_1.setOutputs)({
592+ json: JSON.stringify({
593+ files: filteredFiles,
594+ count: filteredFiles.length,
595+ }),
596+ files: filteredFiles.map(e => e.path),
597+ count: filteredFiles.length,
598+ });
533599 }
534600 catch (error) {
535601 if (error instanceof Error) {
0 commit comments