From 0acc1c308efedeb1a3a82d4c3812e380cacc86ec Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 7 Aug 2023 00:00:11 -0600 Subject: [PATCH] chore: simplify code (#1439) Co-authored-by: GitHub Action --- dist/index.js | Bin 1690208 -> 1690657 bytes dist/index.js.map | Bin 1695275 -> 1695772 bytes src/__tests__/utils.test.ts | 9 ++++++++- src/changedFilesOutput.ts | 10 +++------- src/main.ts | 28 ++++++++++++++++++++++++---- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/dist/index.js b/dist/index.js index f20fcd5b133f0d8fc302638554bc57e10aa52e78..d62c9d0e459775f3f337b6dd7796a6ce192a188f 100644 GIT binary patch delta 320 zcmXZWu}cC06b5k4&ePH^?M}NCZ=@n(|hmx-s`z_bz$8Ob7-z6FvwNfOZnX!n8p^KjzkpQ z6ux>E SG))Srl%OQd+&iB3`1S)Qm6^!^ delta 222 zcmZ2DBmKdY^bJ2PCi7e7Pk#Q`d$QRRvB|%F^Gr^#k({jeTzoQ{qwwVAPvkh0^Ye;J z6cSTXCSP<}IoUpvb+ew;rj?UVK8c$g@Puc2CJQ6q6Ri11lrv=GiY48Jpj{Y=85T5r~<9m>Gy!fS47C*?^cGh&h0m u6NtHhm>Y-RZXig$1hC++I6{^O#4;noPtu-+SPd$kU z4x)&Vg8@AVfr^V1q0myHe%yL2*jv1)e}LT-tY8oC@nB}&%tX@;{Y^9Y=-D_OW+U z?VU6B==)h*7b%P%j%%L#5^cm)mU?jB>Be~YdLPZeQOS+=pHnx|>#7513*^JVG==cJ zMnRm~)Qr!sH51#qyDAfOSuYvEt4n45YpSDoqI4|Jxa6UaG%QTQny@bH6*h!@!hT^> iI3OGpZWMkZ+$7vA91;!-M}(uoG2s^B_$RiKQ-1(d)u5yR delta 357 zcmZwAEl2}#7zS{>|9j^?ZXf5qlfncA5ieL=8iGX@hC$Y}$Tqhd(_oM(%EEL-MdS&} zSh}KuaA7J6E@&1p32IO+;c1_4gG7MCsUb=xtWJ~nZ|mUkNH`E1zCuN8*L*JUHk<(OpL(* diff --git a/src/__tests__/utils.test.ts b/src/__tests__/utils.test.ts index 3599a29c..d4ec1750 100644 --- a/src/__tests__/utils.test.ts +++ b/src/__tests__/utils.test.ts @@ -315,7 +315,14 @@ describe('utils test', () => { // Tests that the function returns only the files that match the file patterns it('should return only the files that match the file patterns', async () => { const allDiffFiles = { - [ChangeTypeEnum.Added]: ['file1.txt', 'file2.md', 'file3.txt'], + [ChangeTypeEnum.Added]: [ + 'file1.txt', + 'file2.md', + 'file3.txt', + 'test/dir/file4.txt', + '/test/dir/file5.txt', + 'dir/file6.md' + ], [ChangeTypeEnum.Copied]: [], [ChangeTypeEnum.Deleted]: [], [ChangeTypeEnum.Modified]: [], diff --git a/src/changedFilesOutput.ts b/src/changedFilesOutput.ts index 0e6f580a..41c267e2 100644 --- a/src/changedFilesOutput.ts +++ b/src/changedFilesOutput.ts @@ -6,7 +6,7 @@ import { getChangeTypeFiles } from './changedFiles' import {Inputs} from './inputs' -import {getFilteredChangedFiles, setOutput} from './utils' +import {setOutput} from './utils' const getOutputKey = (key: string, outputPrefix: string): string => { return outputPrefix ? `${outputPrefix}_${key}` : key @@ -14,21 +14,17 @@ const getOutputKey = (key: string, outputPrefix: string): string => { export const setChangedFilesOutput = async ({ allDiffFiles, + allFilteredDiffFiles, inputs, filePatterns = [], outputPrefix = '' }: { allDiffFiles: ChangedFiles + allFilteredDiffFiles: ChangedFiles inputs: Inputs filePatterns?: string[] outputPrefix?: string }): Promise => { - const allFilteredDiffFiles = await getFilteredChangedFiles({ - allDiffFiles, - filePatterns - }) - core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`) - const addedFiles = await getChangeTypeFiles({ inputs, changedFiles: allFilteredDiffFiles, diff --git a/src/main.ts b/src/main.ts index e7a97dc5..a8330e53 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,6 +18,7 @@ import {Env, getEnv} from './env' import {getInputs, Inputs} from './inputs' import { getFilePatterns, + getFilteredChangedFiles, getRecoverFilePatterns, getSubmodulePath, getYamlFilePatterns, @@ -43,10 +44,18 @@ const changedFilesOutput = async ({ }): Promise => { if (filePatterns.length > 0) { core.startGroup('changed-files-patterns') + const allFilteredDiffFiles = await getFilteredChangedFiles({ + allDiffFiles, + filePatterns + }) + core.debug( + `All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}` + ) await setChangedFilesOutput({ allDiffFiles, - filePatterns, - inputs + allFilteredDiffFiles, + inputs, + filePatterns }) core.info('All Done!') core.endGroup() @@ -55,11 +64,21 @@ const changedFilesOutput = async ({ if (Object.keys(yamlFilePatterns).length > 0) { for (const key of Object.keys(yamlFilePatterns)) { core.startGroup(`changed-files-yaml-${key}`) + const allFilteredDiffFiles = await getFilteredChangedFiles({ + allDiffFiles, + filePatterns: yamlFilePatterns[key] + }) + core.debug( + `All filtered diff files for ${key}: ${JSON.stringify( + allFilteredDiffFiles + )}` + ) await setChangedFilesOutput({ allDiffFiles, + allFilteredDiffFiles, + inputs, filePatterns: yamlFilePatterns[key], - outputPrefix: key, - inputs + outputPrefix: key }) core.info('All Done!') core.endGroup() @@ -70,6 +89,7 @@ const changedFilesOutput = async ({ core.startGroup('changed-files-all') await setChangedFilesOutput({ allDiffFiles, + allFilteredDiffFiles: allDiffFiles, inputs }) core.info('All Done!')