From 58b1cb2d52d4165792285f0e37f0139f96487a74 Mon Sep 17 00:00:00 2001 From: ilyakhd <14272298+IlyaKhD@users.noreply.github.com> Date: Mon, 17 Mar 2025 19:26:40 +0200 Subject: [PATCH 1/9] Fix paths filtering in the case of empty filter --- common/src/path-utils.test.ts | 5 +++++ common/src/path-utils.ts | 16 +++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/common/src/path-utils.test.ts b/common/src/path-utils.test.ts index 1a0a07d..69eb911 100644 --- a/common/src/path-utils.test.ts +++ b/common/src/path-utils.test.ts @@ -9,6 +9,11 @@ describe('path utils', () => { patterns: [], expected: [] }, + { + paths: ['a.ts', 'a.js', 'b.md'], + patterns: [], + expected: ['a.ts', 'a.js', 'b.md'] + }, { paths: ['a.ts', 'a.js', 'b.md'], patterns: ['b*.*'], diff --git a/common/src/path-utils.ts b/common/src/path-utils.ts index 4ee432a..2d98c87 100644 --- a/common/src/path-utils.ts +++ b/common/src/path-utils.ts @@ -24,11 +24,13 @@ function filterPathsImpl( paths: string[], patterns: string[], ): string[] { - return paths.filter(path => { - return patterns.reduce((prevResult, pattern) => { - return pattern.startsWith(NEGATION) - ? prevResult && !match(path, pattern.substring(1)) - : prevResult || match(path, pattern); - }, false); - }); + return patterns?.length === 0 + ? paths + : paths.filter(path => { + return patterns.reduce((prevResult, pattern) => { + return pattern.startsWith(NEGATION) + ? prevResult && !match(path, pattern.substring(1)) + : prevResult || match(path, pattern); + }, false); + }); } From cc81aa18577c9efc51e0eb5c61a7b94ed4e5a9e2 Mon Sep 17 00:00:00 2001 From: ilyakhd <14272298+IlyaKhD@users.noreply.github.com> Date: Tue, 18 Mar 2025 15:47:50 +0200 Subject: [PATCH 2/9] Update dists --- get-changed-files/dist/index.js | 16 +++++++++------- pr-filter/dist/index.js | 16 +++++++++------- verify-version-change/dist/index.js | 16 +++++++++------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/get-changed-files/dist/index.js b/get-changed-files/dist/index.js index 35296ac..3fe4c9e 100644 --- a/get-changed-files/dist/index.js +++ b/get-changed-files/dist/index.js @@ -144,13 +144,15 @@ function filterPaths(paths, patterns) { } exports.filterPaths = filterPaths; function filterPathsImpl(paths, patterns) { - return paths.filter(path => { - return patterns.reduce((prevResult, pattern) => { - return pattern.startsWith(NEGATION) - ? prevResult && !match(path, pattern.substring(1)) - : prevResult || match(path, pattern); - }, false); - }); + return (patterns === null || patterns === void 0 ? void 0 : patterns.length) === 0 + ? paths + : paths.filter(path => { + return patterns.reduce((prevResult, pattern) => { + return pattern.startsWith(NEGATION) + ? prevResult && !match(path, pattern.substring(1)) + : prevResult || match(path, pattern); + }, false); + }); } diff --git a/pr-filter/dist/index.js b/pr-filter/dist/index.js index 1791f1f..296ab56 100644 --- a/pr-filter/dist/index.js +++ b/pr-filter/dist/index.js @@ -144,13 +144,15 @@ function filterPaths(paths, patterns) { } exports.filterPaths = filterPaths; function filterPathsImpl(paths, patterns) { - return paths.filter(path => { - return patterns.reduce((prevResult, pattern) => { - return pattern.startsWith(NEGATION) - ? prevResult && !match(path, pattern.substring(1)) - : prevResult || match(path, pattern); - }, false); - }); + return (patterns === null || patterns === void 0 ? void 0 : patterns.length) === 0 + ? paths + : paths.filter(path => { + return patterns.reduce((prevResult, pattern) => { + return pattern.startsWith(NEGATION) + ? prevResult && !match(path, pattern.substring(1)) + : prevResult || match(path, pattern); + }, false); + }); } diff --git a/verify-version-change/dist/index.js b/verify-version-change/dist/index.js index 0da1e5a..050ceb4 100644 --- a/verify-version-change/dist/index.js +++ b/verify-version-change/dist/index.js @@ -144,13 +144,15 @@ function filterPaths(paths, patterns) { } exports.filterPaths = filterPaths; function filterPathsImpl(paths, patterns) { - return paths.filter(path => { - return patterns.reduce((prevResult, pattern) => { - return pattern.startsWith(NEGATION) - ? prevResult && !match(path, pattern.substring(1)) - : prevResult || match(path, pattern); - }, false); - }); + return (patterns === null || patterns === void 0 ? void 0 : patterns.length) === 0 + ? paths + : paths.filter(path => { + return patterns.reduce((prevResult, pattern) => { + return pattern.startsWith(NEGATION) + ? prevResult && !match(path, pattern.substring(1)) + : prevResult || match(path, pattern); + }, false); + }); } From 2e39fe03b6407f821cda19e846b82532ce7f4ba5 Mon Sep 17 00:00:00 2001 From: ilyakhd <14272298+IlyaKhD@users.noreply.github.com> Date: Tue, 18 Mar 2025 15:53:06 +0200 Subject: [PATCH 3/9] Add outputs --- get-changed-files/dist/index.js | 2 ++ get-changed-files/src/main.ts | 3 +++ 2 files changed, 5 insertions(+) diff --git a/get-changed-files/dist/index.js b/get-changed-files/dist/index.js index 3fe4c9e..5361158 100644 --- a/get-changed-files/dist/index.js +++ b/get-changed-files/dist/index.js @@ -530,6 +530,8 @@ function run() { const filteredFiles = (0, common_1.filterPaths)(changedFiles, pathPatterns); (0, common_1.ensureDir)(output); fs.writeFileSync(output, JSON.stringify(filteredFiles.map(filename => ({ filename })), undefined, 2)); + core.setOutput('files', filteredFiles.toString().trim()); + core.setOutput('count', filteredFiles.length.toString().trim()); } catch (error) { if (error instanceof Error) { diff --git a/get-changed-files/src/main.ts b/get-changed-files/src/main.ts index d832f2a..0684edd 100644 --- a/get-changed-files/src/main.ts +++ b/get-changed-files/src/main.ts @@ -17,6 +17,9 @@ async function run(): Promise { ensureDir(output); fs.writeFileSync(output, JSON.stringify(filteredFiles.map(filename => ({ filename })), undefined, 2)); + + core.setOutput('files', filteredFiles.toString().trim()); + core.setOutput('count', filteredFiles.length.toString().trim()); } catch (error) { if (error instanceof Error) { core.setFailed(error.message) From 516c06597407176e0d17e4b8a3fd1c0ea0ee0e3a Mon Sep 17 00:00:00 2001 From: ilyakhd <14272298+IlyaKhD@users.noreply.github.com> Date: Tue, 18 Mar 2025 18:17:32 +0200 Subject: [PATCH 4/9] Use JSON for outputs --- get-changed-files/dist/index.js | 6 +++++- get-changed-files/src/main.ts | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/get-changed-files/dist/index.js b/get-changed-files/dist/index.js index 5361158..e744847 100644 --- a/get-changed-files/dist/index.js +++ b/get-changed-files/dist/index.js @@ -530,7 +530,11 @@ function run() { const filteredFiles = (0, common_1.filterPaths)(changedFiles, pathPatterns); (0, common_1.ensureDir)(output); fs.writeFileSync(output, JSON.stringify(filteredFiles.map(filename => ({ filename })), undefined, 2)); - core.setOutput('files', filteredFiles.toString().trim()); + core.setOutput('files', JSON.stringify(filteredFiles)); + core.setOutput('json', JSON.stringify({ + files: filteredFiles, + count: filteredFiles.length, + })); core.setOutput('count', filteredFiles.length.toString().trim()); } catch (error) { diff --git a/get-changed-files/src/main.ts b/get-changed-files/src/main.ts index 0684edd..3499be5 100644 --- a/get-changed-files/src/main.ts +++ b/get-changed-files/src/main.ts @@ -18,7 +18,11 @@ async function run(): Promise { ensureDir(output); fs.writeFileSync(output, JSON.stringify(filteredFiles.map(filename => ({ filename })), undefined, 2)); - core.setOutput('files', filteredFiles.toString().trim()); + core.setOutput('files', JSON.stringify(filteredFiles)); + core.setOutput('json', JSON.stringify({ + files: filteredFiles, + count: filteredFiles.length, + })); core.setOutput('count', filteredFiles.length.toString().trim()); } catch (error) { if (error instanceof Error) { From 614d8b835e92f802b2f032b1844e31319300c892 Mon Sep 17 00:00:00 2001 From: ilyakhd <14272298+IlyaKhD@users.noreply.github.com> Date: Tue, 18 Mar 2025 20:02:26 +0200 Subject: [PATCH 5/9] Add unified outputs --- common/src/common-utils.ts | 11 ++++++ common/src/serialization-utils.test.ts | 23 +++++++++++ common/src/serialization-utils.ts | 36 +++++++++++++++++ get-changed-files/dist/index.js | 55 +++++++++++++++++++++++--- get-changed-files/src/main.ts | 14 ++++--- pr-filter/dist/index.js | 49 ++++++++++++++++++++++- verify-version-change/dist/index.js | 49 ++++++++++++++++++++++- 7 files changed, 225 insertions(+), 12 deletions(-) create mode 100644 common/src/serialization-utils.test.ts create mode 100644 common/src/serialization-utils.ts diff --git a/common/src/common-utils.ts b/common/src/common-utils.ts index 666e289..0911a11 100644 --- a/common/src/common-utils.ts +++ b/common/src/common-utils.ts @@ -1,4 +1,6 @@ +import { setOutput } from '@actions/core'; import { getExecOutput } from '@actions/exec' +import { stringifyForShell } from './serialization-utils'; export async function execCommand(command: string): Promise { const { stdout, stderr, exitCode } = await getExecOutput(command) @@ -9,3 +11,12 @@ export async function execCommand(command: string): Promise { return stdout.trim() } + +export function setOutputs(values: Record): void { + + setOutput('json', JSON.stringify(values)); + + for (const [key, value] of Object.entries(values)) { + setOutput(key, stringifyForShell(value)); + } +} diff --git a/common/src/serialization-utils.test.ts b/common/src/serialization-utils.test.ts new file mode 100644 index 0000000..8baa218 --- /dev/null +++ b/common/src/serialization-utils.test.ts @@ -0,0 +1,23 @@ +import { stringifyForShell } from "./serialization-utils"; + +describe('action utils', () => { + + describe(stringifyForShell.name, () => { + test.each([ + { value: 123, expected: '123' }, + { value: 'abc', expected: 'abc' }, + ])('scalar cases [%#]', ({ value, expected }) => { + expect(stringifyForShell(value)).toEqual(expected); + }); + }); + + describe(stringifyForShell.name, () => { + test.each([ + { value: [123, 456], expected: '123 456' }, + { value: ['abc', 'def'], expected: '\'abc\' \'def\'' }, + ])('array values [%#]', ({ value, expected }) => { + expect(stringifyForShell(value)).toEqual(expected); + }); + }); + +}); diff --git a/common/src/serialization-utils.ts b/common/src/serialization-utils.ts new file mode 100644 index 0000000..069c9d7 --- /dev/null +++ b/common/src/serialization-utils.ts @@ -0,0 +1,36 @@ +function stringifyArrayItem(item: unknown): string { + switch (typeof item) { + case 'number': + return item.toString(); + + case 'string': + return `'${item}'`; + + default: + return JSON.stringify(item); + } +} + +export function stringifyForShell(value: unknown): string { + + switch (typeof value) { + + case 'string': + return value; + + + case 'object': + if (Array.isArray(value)) { + return value.map(stringifyArrayItem).join(' '); + } + + if (value === null) { + return ''; + } + + return value.toString(); + + default: + return JSON.stringify(value); + } +} \ No newline at end of file diff --git a/get-changed-files/dist/index.js b/get-changed-files/dist/index.js index e744847..14265d0 100644 --- a/get-changed-files/dist/index.js +++ b/get-changed-files/dist/index.js @@ -16,8 +16,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.execCommand = void 0; +exports.setOutputs = exports.execCommand = void 0; +const core_1 = __nccwpck_require__(5316); const exec_1 = __nccwpck_require__(110); +const serialization_utils_1 = __nccwpck_require__(9091); function execCommand(command) { return __awaiter(this, void 0, void 0, function* () { const { stdout, stderr, exitCode } = yield (0, exec_1.getExecOutput)(command); @@ -28,6 +30,13 @@ function execCommand(command) { }); } exports.execCommand = execCommand; +function setOutputs(values) { + (0, core_1.setOutput)('json', JSON.stringify(values)); + for (const [key, value] of Object.entries(values)) { + (0, core_1.setOutput)(key, (0, serialization_utils_1.stringifyForShell)(value)); + } +} +exports.setOutputs = setOutputs; /***/ }), @@ -266,6 +275,44 @@ function getChangedFilesImpl(token) { } +/***/ }), + +/***/ 9091: +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.stringifyForShell = void 0; +function stringifyArrayItem(item) { + switch (typeof item) { + case 'number': + return item.toString(); + case 'string': + return `'${item}'`; + default: + return JSON.stringify(item); + } +} +function stringifyForShell(value) { + switch (typeof value) { + case 'string': + return value; + case 'object': + if (Array.isArray(value)) { + return value.map(stringifyArrayItem).join(' '); + } + if (value === null) { + return ''; + } + return value.toString(); + default: + return JSON.stringify(value); + } +} +exports.stringifyForShell = stringifyForShell; + + /***/ }), /***/ 2013: @@ -530,12 +577,10 @@ function run() { const filteredFiles = (0, common_1.filterPaths)(changedFiles, pathPatterns); (0, common_1.ensureDir)(output); fs.writeFileSync(output, JSON.stringify(filteredFiles.map(filename => ({ filename })), undefined, 2)); - core.setOutput('files', JSON.stringify(filteredFiles)); - core.setOutput('json', JSON.stringify({ + (0, common_1.setOutputs)({ files: filteredFiles, count: filteredFiles.length, - })); - core.setOutput('count', filteredFiles.length.toString().trim()); + }); } catch (error) { if (error instanceof Error) { diff --git a/get-changed-files/src/main.ts b/get-changed-files/src/main.ts index 3499be5..7078349 100644 --- a/get-changed-files/src/main.ts +++ b/get-changed-files/src/main.ts @@ -1,7 +1,13 @@ import * as fs from 'fs'; import * as core from '@actions/core'; -import { inputs, filterPaths, getChangedFiles, ensureDir } from 'common'; +import { + inputs, + filterPaths, + getChangedFiles, + ensureDir, + setOutputs, +} from 'common'; async function run(): Promise { @@ -18,12 +24,10 @@ async function run(): Promise { ensureDir(output); fs.writeFileSync(output, JSON.stringify(filteredFiles.map(filename => ({ filename })), undefined, 2)); - core.setOutput('files', JSON.stringify(filteredFiles)); - core.setOutput('json', JSON.stringify({ + setOutputs({ files: filteredFiles, count: filteredFiles.length, - })); - core.setOutput('count', filteredFiles.length.toString().trim()); + }); } catch (error) { if (error instanceof Error) { core.setFailed(error.message) diff --git a/pr-filter/dist/index.js b/pr-filter/dist/index.js index 296ab56..8eb1cbb 100644 --- a/pr-filter/dist/index.js +++ b/pr-filter/dist/index.js @@ -16,8 +16,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.execCommand = void 0; +exports.setOutputs = exports.execCommand = void 0; +const core_1 = __nccwpck_require__(5316); const exec_1 = __nccwpck_require__(110); +const serialization_utils_1 = __nccwpck_require__(9091); function execCommand(command) { return __awaiter(this, void 0, void 0, function* () { const { stdout, stderr, exitCode } = yield (0, exec_1.getExecOutput)(command); @@ -28,6 +30,13 @@ function execCommand(command) { }); } exports.execCommand = execCommand; +function setOutputs(values) { + (0, core_1.setOutput)('json', JSON.stringify(values)); + for (const [key, value] of Object.entries(values)) { + (0, core_1.setOutput)(key, (0, serialization_utils_1.stringifyForShell)(value)); + } +} +exports.setOutputs = setOutputs; /***/ }), @@ -266,6 +275,44 @@ function getChangedFilesImpl(token) { } +/***/ }), + +/***/ 9091: +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.stringifyForShell = void 0; +function stringifyArrayItem(item) { + switch (typeof item) { + case 'number': + return item.toString(); + case 'string': + return `'${item}'`; + default: + return JSON.stringify(item); + } +} +function stringifyForShell(value) { + switch (typeof value) { + case 'string': + return value; + case 'object': + if (Array.isArray(value)) { + return value.map(stringifyArrayItem).join(' '); + } + if (value === null) { + return ''; + } + return value.toString(); + default: + return JSON.stringify(value); + } +} +exports.stringifyForShell = stringifyForShell; + + /***/ }), /***/ 2013: diff --git a/verify-version-change/dist/index.js b/verify-version-change/dist/index.js index 050ceb4..69d3c14 100644 --- a/verify-version-change/dist/index.js +++ b/verify-version-change/dist/index.js @@ -16,8 +16,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.execCommand = void 0; +exports.setOutputs = exports.execCommand = void 0; +const core_1 = __nccwpck_require__(5316); const exec_1 = __nccwpck_require__(110); +const serialization_utils_1 = __nccwpck_require__(9091); function execCommand(command) { return __awaiter(this, void 0, void 0, function* () { const { stdout, stderr, exitCode } = yield (0, exec_1.getExecOutput)(command); @@ -28,6 +30,13 @@ function execCommand(command) { }); } exports.execCommand = execCommand; +function setOutputs(values) { + (0, core_1.setOutput)('json', JSON.stringify(values)); + for (const [key, value] of Object.entries(values)) { + (0, core_1.setOutput)(key, (0, serialization_utils_1.stringifyForShell)(value)); + } +} +exports.setOutputs = setOutputs; /***/ }), @@ -266,6 +275,44 @@ function getChangedFilesImpl(token) { } +/***/ }), + +/***/ 9091: +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.stringifyForShell = void 0; +function stringifyArrayItem(item) { + switch (typeof item) { + case 'number': + return item.toString(); + case 'string': + return `'${item}'`; + default: + return JSON.stringify(item); + } +} +function stringifyForShell(value) { + switch (typeof value) { + case 'string': + return value; + case 'object': + if (Array.isArray(value)) { + return value.map(stringifyArrayItem).join(' '); + } + if (value === null) { + return ''; + } + return value.toString(); + default: + return JSON.stringify(value); + } +} +exports.stringifyForShell = stringifyForShell; + + /***/ }), /***/ 2013: From 8cbf39aae6db03a3f0becca93a89f65fdd0b93c8 Mon Sep 17 00:00:00 2001 From: ilyakhd <14272298+IlyaKhD@users.noreply.github.com> Date: Thu, 20 Mar 2025 21:43:38 +0200 Subject: [PATCH 6/9] Add changed file status --- common/src/common-utils.ts | 3 --- common/src/path-utils.ts | 16 ++++++++------- common/src/pr-utils.ts | 18 ++++++++++------ common/src/serialization-utils.ts | 1 - get-changed-files/dist/index.js | 32 ++++++++++++++++------------- get-changed-files/src/main.ts | 11 ++++++---- pr-filter/dist/index.js | 25 +++++++++++----------- pr-filter/src/main.ts | 2 +- verify-version-change/dist/index.js | 23 +++++++++++---------- 9 files changed, 72 insertions(+), 59 deletions(-) diff --git a/common/src/common-utils.ts b/common/src/common-utils.ts index 0911a11..4de9d53 100644 --- a/common/src/common-utils.ts +++ b/common/src/common-utils.ts @@ -13,9 +13,6 @@ export async function execCommand(command: string): Promise { } export function setOutputs(values: Record): void { - - setOutput('json', JSON.stringify(values)); - for (const [key, value] of Object.entries(values)) { setOutput(key, stringifyForShell(value)); } diff --git a/common/src/path-utils.ts b/common/src/path-utils.ts index 2d98c87..91dca31 100644 --- a/common/src/path-utils.ts +++ b/common/src/path-utils.ts @@ -26,11 +26,13 @@ function filterPathsImpl( ): string[] { return patterns?.length === 0 ? paths - : paths.filter(path => { - return patterns.reduce((prevResult, pattern) => { - return pattern.startsWith(NEGATION) - ? prevResult && !match(path, pattern.substring(1)) - : prevResult || match(path, pattern); - }, false); - }); + : paths.filter(path => testPath(path, patterns)); +} + +export function testPath(path: string, patterns: string[]): boolean { + return patterns.reduce((prevResult, pattern) => { + return pattern.startsWith(NEGATION) + ? prevResult && !match(path, pattern.substring(1)) + : prevResult || match(path, pattern); + }, false); } diff --git a/common/src/pr-utils.ts b/common/src/pr-utils.ts index 968a0fc..8983b9d 100644 --- a/common/src/pr-utils.ts +++ b/common/src/pr-utils.ts @@ -1,6 +1,7 @@ -import * as core from '@actions/core' -import { context, getOctokit } from '@actions/github' +import * as core from '@actions/core'; +import { context, getOctokit } from '@actions/github'; +import { components } from '@octokit/openapi-types'; import { execCommand } from './common-utils'; export async function getPrRevisionRange(): Promise<{ @@ -42,14 +43,19 @@ function normalizeCommit(commit: string) { return commit === '0000000000000000000000000000000000000000' ? 'HEAD^' : commit; } -export async function getChangedFiles(token: string): Promise { +interface ChangedFile { + filename: string; + status: components['schemas']['diff-entry']['status']; +} + +export async function getChangedFiles(token: string): Promise { return getChangedFilesImpl(token).then((files) => { core.info(`${files.length} changed files: ${JSON.stringify(files, undefined, 2)}`) return files; }); } -async function getChangedFilesImpl(token: string): Promise { +async function getChangedFilesImpl(token: string): Promise { try { const octokit = getOctokit(token); @@ -58,13 +64,13 @@ async function getChangedFilesImpl(token: string): Promise { return []; } - const files = await octokit.paginate(octokit.rest.pulls.listFiles, { + const entries = await octokit.paginate(octokit.rest.pulls.listFiles, { owner: context.repo.owner, repo: context.repo.repo, pull_number: context.payload.pull_request.number, }); - return files.map(file => file.filename); + return entries.map(({ filename, status }) => ({ filename, status })); } catch (error) { core.setFailed(`Getting changed files failed with error: ${error}`); return []; diff --git a/common/src/serialization-utils.ts b/common/src/serialization-utils.ts index 069c9d7..3903c65 100644 --- a/common/src/serialization-utils.ts +++ b/common/src/serialization-utils.ts @@ -18,7 +18,6 @@ export function stringifyForShell(value: unknown): string { case 'string': return value; - case 'object': if (Array.isArray(value)) { return value.map(stringifyArrayItem).join(' '); diff --git a/get-changed-files/dist/index.js b/get-changed-files/dist/index.js index 14265d0..0cbf99c 100644 --- a/get-changed-files/dist/index.js +++ b/get-changed-files/dist/index.js @@ -31,7 +31,6 @@ function execCommand(command) { } exports.execCommand = execCommand; function setOutputs(values) { - (0, core_1.setOutput)('json', JSON.stringify(values)); for (const [key, value] of Object.entries(values)) { (0, core_1.setOutput)(key, (0, serialization_utils_1.stringifyForShell)(value)); } @@ -135,7 +134,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.filterPaths = void 0; +exports.testPath = exports.filterPaths = void 0; const core = __importStar(__nccwpck_require__(5316)); const minimatch_1 = __nccwpck_require__(148); const NEGATION = '!'; @@ -155,14 +154,16 @@ exports.filterPaths = filterPaths; function filterPathsImpl(paths, patterns) { return (patterns === null || patterns === void 0 ? void 0 : patterns.length) === 0 ? paths - : paths.filter(path => { - return patterns.reduce((prevResult, pattern) => { - return pattern.startsWith(NEGATION) - ? prevResult && !match(path, pattern.substring(1)) - : prevResult || match(path, pattern); - }, false); - }); + : paths.filter(path => testPath(path, patterns)); +} +function testPath(path, patterns) { + return patterns.reduce((prevResult, pattern) => { + return pattern.startsWith(NEGATION) + ? prevResult && !match(path, pattern.substring(1)) + : prevResult || match(path, pattern); + }, false); } +exports.testPath = testPath; /***/ }), @@ -260,12 +261,12 @@ function getChangedFilesImpl(token) { core.setFailed('Getting changed files only works on pull request events.'); return []; } - const files = yield octokit.paginate(octokit.rest.pulls.listFiles, { + const entries = yield octokit.paginate(octokit.rest.pulls.listFiles, { owner: github_1.context.repo.owner, repo: github_1.context.repo.repo, pull_number: github_1.context.payload.pull_request.number, }); - return files.map(file => file.filename); + return entries.map(({ filename, status }) => ({ filename, status })); } catch (error) { core.setFailed(`Getting changed files failed with error: ${error}`); @@ -574,11 +575,14 @@ function run() { const output = core.getInput(common_1.inputs.OUTPUT, { required: true }); console.log('patterns: ' + JSON.stringify(pathPatterns, undefined, 2)); const changedFiles = yield (0, common_1.getChangedFiles)(token); - const filteredFiles = (0, common_1.filterPaths)(changedFiles, pathPatterns); + const filteredFiles = pathPatterns.length > 0 + ? changedFiles.filter(({ filename }) => (0, common_1.testPath)(filename, pathPatterns)) + : changedFiles; (0, common_1.ensureDir)(output); - fs.writeFileSync(output, JSON.stringify(filteredFiles.map(filename => ({ filename })), undefined, 2)); + fs.writeFileSync(output, JSON.stringify(filteredFiles.map(({ filename }) => ({ filename })), undefined, 2)); (0, common_1.setOutputs)({ - files: filteredFiles, + json: JSON.stringify(filteredFiles, undefined, 2), + files: filteredFiles.map(e => e.filename), count: filteredFiles.length, }); } diff --git a/get-changed-files/src/main.ts b/get-changed-files/src/main.ts index 7078349..e9972fb 100644 --- a/get-changed-files/src/main.ts +++ b/get-changed-files/src/main.ts @@ -3,10 +3,10 @@ import * as core from '@actions/core'; import { inputs, - filterPaths, getChangedFiles, ensureDir, setOutputs, + testPath, } from 'common'; @@ -19,13 +19,16 @@ async function run(): Promise { console.log('patterns: ' + JSON.stringify(pathPatterns, undefined, 2)); const changedFiles = await getChangedFiles(token); - const filteredFiles = filterPaths(changedFiles, pathPatterns); + const filteredFiles = pathPatterns.length > 0 + ? changedFiles.filter(({ filename }) => testPath(filename, pathPatterns)) + : changedFiles; ensureDir(output); - fs.writeFileSync(output, JSON.stringify(filteredFiles.map(filename => ({ filename })), undefined, 2)); + fs.writeFileSync(output, JSON.stringify(filteredFiles.map(({ filename }) => ({ filename })), undefined, 2)); setOutputs({ - files: filteredFiles, + json: JSON.stringify(filteredFiles, undefined, 2), + files: filteredFiles.map(e => e.filename), count: filteredFiles.length, }); } catch (error) { diff --git a/pr-filter/dist/index.js b/pr-filter/dist/index.js index 8eb1cbb..e68a666 100644 --- a/pr-filter/dist/index.js +++ b/pr-filter/dist/index.js @@ -31,7 +31,6 @@ function execCommand(command) { } exports.execCommand = execCommand; function setOutputs(values) { - (0, core_1.setOutput)('json', JSON.stringify(values)); for (const [key, value] of Object.entries(values)) { (0, core_1.setOutput)(key, (0, serialization_utils_1.stringifyForShell)(value)); } @@ -135,7 +134,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.filterPaths = void 0; +exports.testPath = exports.filterPaths = void 0; const core = __importStar(__nccwpck_require__(5316)); const minimatch_1 = __nccwpck_require__(148); const NEGATION = '!'; @@ -155,14 +154,16 @@ exports.filterPaths = filterPaths; function filterPathsImpl(paths, patterns) { return (patterns === null || patterns === void 0 ? void 0 : patterns.length) === 0 ? paths - : paths.filter(path => { - return patterns.reduce((prevResult, pattern) => { - return pattern.startsWith(NEGATION) - ? prevResult && !match(path, pattern.substring(1)) - : prevResult || match(path, pattern); - }, false); - }); + : paths.filter(path => testPath(path, patterns)); +} +function testPath(path, patterns) { + return patterns.reduce((prevResult, pattern) => { + return pattern.startsWith(NEGATION) + ? prevResult && !match(path, pattern.substring(1)) + : prevResult || match(path, pattern); + }, false); } +exports.testPath = testPath; /***/ }), @@ -260,12 +261,12 @@ function getChangedFilesImpl(token) { core.setFailed('Getting changed files only works on pull request events.'); return []; } - const files = yield octokit.paginate(octokit.rest.pulls.listFiles, { + const entries = yield octokit.paginate(octokit.rest.pulls.listFiles, { owner: github_1.context.repo.owner, repo: github_1.context.repo.repo, pull_number: github_1.context.payload.pull_request.number, }); - return files.map(file => file.filename); + return entries.map(({ filename, status }) => ({ filename, status })); } catch (error) { core.setFailed(`Getting changed files failed with error: ${error}`); @@ -33708,7 +33709,7 @@ function run() { try { const pathPatterns = core.getInput(common_1.inputs.PATHS).split(';'); const token = core.getInput(common_1.inputs.GH_TOKEN, { required: true }); - const changedFiles = yield (0, common_1.getChangedFiles)(token); + const changedFiles = (yield (0, common_1.getChangedFiles)(token)).map(e => e.filename); const filteredFiles = (0, common_1.filterPaths)(changedFiles, pathPatterns); core.setOutput(common_1.outputs.RESULT, filteredFiles.length > 0); } diff --git a/pr-filter/src/main.ts b/pr-filter/src/main.ts index ed82a12..f6c3c8a 100644 --- a/pr-filter/src/main.ts +++ b/pr-filter/src/main.ts @@ -7,7 +7,7 @@ async function run(): Promise { const pathPatterns = core.getInput(inputs.PATHS).split(';'); const token = core.getInput(inputs.GH_TOKEN, { required: true }); - const changedFiles = await getChangedFiles(token); + const changedFiles = (await getChangedFiles(token)).map(e => e.filename); const filteredFiles = filterPaths(changedFiles, pathPatterns); core.setOutput(outputs.RESULT, filteredFiles.length > 0); diff --git a/verify-version-change/dist/index.js b/verify-version-change/dist/index.js index 69d3c14..2658c79 100644 --- a/verify-version-change/dist/index.js +++ b/verify-version-change/dist/index.js @@ -31,7 +31,6 @@ function execCommand(command) { } exports.execCommand = execCommand; function setOutputs(values) { - (0, core_1.setOutput)('json', JSON.stringify(values)); for (const [key, value] of Object.entries(values)) { (0, core_1.setOutput)(key, (0, serialization_utils_1.stringifyForShell)(value)); } @@ -135,7 +134,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.filterPaths = void 0; +exports.testPath = exports.filterPaths = void 0; const core = __importStar(__nccwpck_require__(5316)); const minimatch_1 = __nccwpck_require__(148); const NEGATION = '!'; @@ -155,14 +154,16 @@ exports.filterPaths = filterPaths; function filterPathsImpl(paths, patterns) { return (patterns === null || patterns === void 0 ? void 0 : patterns.length) === 0 ? paths - : paths.filter(path => { - return patterns.reduce((prevResult, pattern) => { - return pattern.startsWith(NEGATION) - ? prevResult && !match(path, pattern.substring(1)) - : prevResult || match(path, pattern); - }, false); - }); + : paths.filter(path => testPath(path, patterns)); +} +function testPath(path, patterns) { + return patterns.reduce((prevResult, pattern) => { + return pattern.startsWith(NEGATION) + ? prevResult && !match(path, pattern.substring(1)) + : prevResult || match(path, pattern); + }, false); } +exports.testPath = testPath; /***/ }), @@ -260,12 +261,12 @@ function getChangedFilesImpl(token) { core.setFailed('Getting changed files only works on pull request events.'); return []; } - const files = yield octokit.paginate(octokit.rest.pulls.listFiles, { + const entries = yield octokit.paginate(octokit.rest.pulls.listFiles, { owner: github_1.context.repo.owner, repo: github_1.context.repo.repo, pull_number: github_1.context.payload.pull_request.number, }); - return files.map(file => file.filename); + return entries.map(({ filename, status }) => ({ filename, status })); } catch (error) { core.setFailed(`Getting changed files failed with error: ${error}`); From 23cc0d285a3fbb16a03416563ead9df2ee06beb4 Mon Sep 17 00:00:00 2001 From: ilyakhd <14272298+IlyaKhD@users.noreply.github.com> Date: Thu, 20 Mar 2025 21:55:02 +0200 Subject: [PATCH 7/9] Fix output json format --- common/src/pr-utils.ts | 4 ++-- get-changed-files/dist/index.js | 13 ++++++++----- get-changed-files/src/main.ts | 11 +++++++---- pr-filter/dist/index.js | 4 ++-- pr-filter/src/main.ts | 2 +- verify-version-change/dist/index.js | 2 +- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/common/src/pr-utils.ts b/common/src/pr-utils.ts index 8983b9d..9231545 100644 --- a/common/src/pr-utils.ts +++ b/common/src/pr-utils.ts @@ -44,7 +44,7 @@ function normalizeCommit(commit: string) { } interface ChangedFile { - filename: string; + path: string; status: components['schemas']['diff-entry']['status']; } @@ -70,7 +70,7 @@ async function getChangedFilesImpl(token: string): Promise { pull_number: context.payload.pull_request.number, }); - return entries.map(({ filename, status }) => ({ filename, status })); + return entries.map(({ filename, status }) => ({ path: filename, status })); } catch (error) { core.setFailed(`Getting changed files failed with error: ${error}`); return []; diff --git a/get-changed-files/dist/index.js b/get-changed-files/dist/index.js index 0cbf99c..621b013 100644 --- a/get-changed-files/dist/index.js +++ b/get-changed-files/dist/index.js @@ -266,7 +266,7 @@ function getChangedFilesImpl(token) { repo: github_1.context.repo.repo, pull_number: github_1.context.payload.pull_request.number, }); - return entries.map(({ filename, status }) => ({ filename, status })); + return entries.map(({ filename, status }) => ({ path: filename, status })); } catch (error) { core.setFailed(`Getting changed files failed with error: ${error}`); @@ -576,13 +576,16 @@ function run() { console.log('patterns: ' + JSON.stringify(pathPatterns, undefined, 2)); const changedFiles = yield (0, common_1.getChangedFiles)(token); const filteredFiles = pathPatterns.length > 0 - ? changedFiles.filter(({ filename }) => (0, common_1.testPath)(filename, pathPatterns)) + ? changedFiles.filter(({ path }) => (0, common_1.testPath)(path, pathPatterns)) : changedFiles; (0, common_1.ensureDir)(output); - fs.writeFileSync(output, JSON.stringify(filteredFiles.map(({ filename }) => ({ filename })), undefined, 2)); + fs.writeFileSync(output, JSON.stringify(filteredFiles.map(({ path }) => ({ filename: path })), undefined, 2)); (0, common_1.setOutputs)({ - json: JSON.stringify(filteredFiles, undefined, 2), - files: filteredFiles.map(e => e.filename), + json: { + files: JSON.stringify(filteredFiles, undefined, 2), + count: filteredFiles.length, + }, + files: filteredFiles.map(e => e.path), count: filteredFiles.length, }); } diff --git a/get-changed-files/src/main.ts b/get-changed-files/src/main.ts index e9972fb..2cbea0a 100644 --- a/get-changed-files/src/main.ts +++ b/get-changed-files/src/main.ts @@ -20,15 +20,18 @@ async function run(): Promise { const changedFiles = await getChangedFiles(token); const filteredFiles = pathPatterns.length > 0 - ? changedFiles.filter(({ filename }) => testPath(filename, pathPatterns)) + ? changedFiles.filter(({ path }) => testPath(path, pathPatterns)) : changedFiles; ensureDir(output); - fs.writeFileSync(output, JSON.stringify(filteredFiles.map(({ filename }) => ({ filename })), undefined, 2)); + fs.writeFileSync(output, JSON.stringify(filteredFiles.map(({ path }) => ({ filename: path })), undefined, 2)); setOutputs({ - json: JSON.stringify(filteredFiles, undefined, 2), - files: filteredFiles.map(e => e.filename), + json: { + files: JSON.stringify(filteredFiles, undefined, 2), + count: filteredFiles.length, + }, + files: filteredFiles.map(e => e.path), count: filteredFiles.length, }); } catch (error) { diff --git a/pr-filter/dist/index.js b/pr-filter/dist/index.js index e68a666..e1c1c05 100644 --- a/pr-filter/dist/index.js +++ b/pr-filter/dist/index.js @@ -266,7 +266,7 @@ function getChangedFilesImpl(token) { repo: github_1.context.repo.repo, pull_number: github_1.context.payload.pull_request.number, }); - return entries.map(({ filename, status }) => ({ filename, status })); + return entries.map(({ filename, status }) => ({ path: filename, status })); } catch (error) { core.setFailed(`Getting changed files failed with error: ${error}`); @@ -33709,7 +33709,7 @@ function run() { try { const pathPatterns = core.getInput(common_1.inputs.PATHS).split(';'); const token = core.getInput(common_1.inputs.GH_TOKEN, { required: true }); - const changedFiles = (yield (0, common_1.getChangedFiles)(token)).map(e => e.filename); + const changedFiles = (yield (0, common_1.getChangedFiles)(token)).map(e => e.path); const filteredFiles = (0, common_1.filterPaths)(changedFiles, pathPatterns); core.setOutput(common_1.outputs.RESULT, filteredFiles.length > 0); } diff --git a/pr-filter/src/main.ts b/pr-filter/src/main.ts index f6c3c8a..1b68463 100644 --- a/pr-filter/src/main.ts +++ b/pr-filter/src/main.ts @@ -7,7 +7,7 @@ async function run(): Promise { const pathPatterns = core.getInput(inputs.PATHS).split(';'); const token = core.getInput(inputs.GH_TOKEN, { required: true }); - const changedFiles = (await getChangedFiles(token)).map(e => e.filename); + const changedFiles = (await getChangedFiles(token)).map(e => e.path); const filteredFiles = filterPaths(changedFiles, pathPatterns); core.setOutput(outputs.RESULT, filteredFiles.length > 0); diff --git a/verify-version-change/dist/index.js b/verify-version-change/dist/index.js index 2658c79..20f7fa2 100644 --- a/verify-version-change/dist/index.js +++ b/verify-version-change/dist/index.js @@ -266,7 +266,7 @@ function getChangedFilesImpl(token) { repo: github_1.context.repo.repo, pull_number: github_1.context.payload.pull_request.number, }); - return entries.map(({ filename, status }) => ({ filename, status })); + return entries.map(({ filename, status }) => ({ path: filename, status })); } catch (error) { core.setFailed(`Getting changed files failed with error: ${error}`); From bf151e29d9e38fa089f70428db9ba295775c74fe Mon Sep 17 00:00:00 2001 From: ilyakhd <14272298+IlyaKhD@users.noreply.github.com> Date: Thu, 20 Mar 2025 21:57:39 +0200 Subject: [PATCH 8/9] Fix stringify --- get-changed-files/dist/index.js | 6 +++--- get-changed-files/src/main.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/get-changed-files/dist/index.js b/get-changed-files/dist/index.js index 621b013..b4ac202 100644 --- a/get-changed-files/dist/index.js +++ b/get-changed-files/dist/index.js @@ -581,10 +581,10 @@ function run() { (0, common_1.ensureDir)(output); fs.writeFileSync(output, JSON.stringify(filteredFiles.map(({ path }) => ({ filename: path })), undefined, 2)); (0, common_1.setOutputs)({ - json: { - files: JSON.stringify(filteredFiles, undefined, 2), + json: JSON.stringify({ + files: filteredFiles, count: filteredFiles.length, - }, + }), files: filteredFiles.map(e => e.path), count: filteredFiles.length, }); diff --git a/get-changed-files/src/main.ts b/get-changed-files/src/main.ts index 2cbea0a..d01ca02 100644 --- a/get-changed-files/src/main.ts +++ b/get-changed-files/src/main.ts @@ -27,10 +27,10 @@ async function run(): Promise { fs.writeFileSync(output, JSON.stringify(filteredFiles.map(({ path }) => ({ filename: path })), undefined, 2)); setOutputs({ - json: { - files: JSON.stringify(filteredFiles, undefined, 2), + json: JSON.stringify({ + files: filteredFiles, count: filteredFiles.length, - }, + }), files: filteredFiles.map(e => e.path), count: filteredFiles.length, }); From d6c2a6fa774c00d1a440891db9b2ff0863bdd77a Mon Sep 17 00:00:00 2001 From: ilyakhd <14272298+IlyaKhD@users.noreply.github.com> Date: Fri, 21 Mar 2025 18:47:51 +0200 Subject: [PATCH 9/9] Remove file output --- common/src/constants.ts | 1 - get-changed-files/action.yml | 5 ----- get-changed-files/dist/index.js | 5 ----- get-changed-files/src/main.ts | 4 ---- pr-filter/dist/index.js | 1 - verify-version-change/dist/index.js | 1 - 6 files changed, 17 deletions(-) diff --git a/common/src/constants.ts b/common/src/constants.ts index 6ac0bc3..4f591af 100644 --- a/common/src/constants.ts +++ b/common/src/constants.ts @@ -1,7 +1,6 @@ export const inputs = { GH_TOKEN: 'gh-token', - OUTPUT: 'output', PATHS: 'paths', } as const; diff --git a/get-changed-files/action.yml b/get-changed-files/action.yml index 0eb1700..4e0486a 100644 --- a/get-changed-files/action.yml +++ b/get-changed-files/action.yml @@ -11,11 +11,6 @@ inputs: description: Semicolon separated globs required: false - output: - description: Output file path - required: true - - runs: using: node16 main: dist/index.js diff --git a/get-changed-files/dist/index.js b/get-changed-files/dist/index.js index b4ac202..a5a9a32 100644 --- a/get-changed-files/dist/index.js +++ b/get-changed-files/dist/index.js @@ -49,7 +49,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.outputs = exports.inputs = void 0; exports.inputs = { GH_TOKEN: 'gh-token', - OUTPUT: 'output', PATHS: 'paths', }; exports.outputs = { @@ -564,7 +563,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -const fs = __importStar(__nccwpck_require__(7147)); const core = __importStar(__nccwpck_require__(5316)); const common_1 = __nccwpck_require__(9145); function run() { @@ -572,14 +570,11 @@ function run() { try { const pathPatterns = core.getInput(common_1.inputs.PATHS).split(';'); const token = core.getInput(common_1.inputs.GH_TOKEN, { required: true }); - const output = core.getInput(common_1.inputs.OUTPUT, { required: true }); console.log('patterns: ' + JSON.stringify(pathPatterns, undefined, 2)); const changedFiles = yield (0, common_1.getChangedFiles)(token); const filteredFiles = pathPatterns.length > 0 ? changedFiles.filter(({ path }) => (0, common_1.testPath)(path, pathPatterns)) : changedFiles; - (0, common_1.ensureDir)(output); - fs.writeFileSync(output, JSON.stringify(filteredFiles.map(({ path }) => ({ filename: path })), undefined, 2)); (0, common_1.setOutputs)({ json: JSON.stringify({ files: filteredFiles, diff --git a/get-changed-files/src/main.ts b/get-changed-files/src/main.ts index d01ca02..4692e2c 100644 --- a/get-changed-files/src/main.ts +++ b/get-changed-files/src/main.ts @@ -14,7 +14,6 @@ async function run(): Promise { try { const pathPatterns = core.getInput(inputs.PATHS).split(';'); const token = core.getInput(inputs.GH_TOKEN, { required: true }); - const output = core.getInput(inputs.OUTPUT, { required: true }); console.log('patterns: ' + JSON.stringify(pathPatterns, undefined, 2)); @@ -23,9 +22,6 @@ async function run(): Promise { ? changedFiles.filter(({ path }) => testPath(path, pathPatterns)) : changedFiles; - ensureDir(output); - fs.writeFileSync(output, JSON.stringify(filteredFiles.map(({ path }) => ({ filename: path })), undefined, 2)); - setOutputs({ json: JSON.stringify({ files: filteredFiles, diff --git a/pr-filter/dist/index.js b/pr-filter/dist/index.js index e1c1c05..6d8f9b7 100644 --- a/pr-filter/dist/index.js +++ b/pr-filter/dist/index.js @@ -49,7 +49,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.outputs = exports.inputs = void 0; exports.inputs = { GH_TOKEN: 'gh-token', - OUTPUT: 'output', PATHS: 'paths', }; exports.outputs = { diff --git a/verify-version-change/dist/index.js b/verify-version-change/dist/index.js index 20f7fa2..221a00c 100644 --- a/verify-version-change/dist/index.js +++ b/verify-version-change/dist/index.js @@ -49,7 +49,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.outputs = exports.inputs = void 0; exports.inputs = { GH_TOKEN: 'gh-token', - OUTPUT: 'output', PATHS: 'paths', }; exports.outputs = {