From b661785bbb55d9c9829dcbba435be4b8d22728f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juani=20Gal=C3=A1n?= Date: Sun, 7 Feb 2021 11:07:37 +0100 Subject: [PATCH 1/6] feat(high-impact-packages): regexp for manually flagging packages --- action.yml | 4 ++++ packages/ga-impact-analysis/index.ts | 19 +++++++++-------- packages/ga-impact-analysis/utils.ts | 21 ++++++++++++++++++- packages/ga-monorepolyser/dist/index.js | 27 +++++++++++++++++++------ packages/ga-monorepolyser/index.ts | 2 ++ 5 files changed, 56 insertions(+), 17 deletions(-) diff --git a/action.yml b/action.yml index 556b53e..f8e47b0 100644 --- a/action.yml +++ b/action.yml @@ -38,6 +38,10 @@ inputs: description: 'Whether this action logs the results of its analysis or not. It can be "comment" or "logs"' required: false default: false + high-impact-packages-regexp: + description: 'Regexp that determines which packages should be consider as high impact, no matter the impact analysis' + required: false + default: null runs: using: 'node12' main: 'packages/ga-monorepolyser/dist/index.js' diff --git a/packages/ga-impact-analysis/index.ts b/packages/ga-impact-analysis/index.ts index ecdd237..9f48a19 100644 --- a/packages/ga-impact-analysis/index.ts +++ b/packages/ga-impact-analysis/index.ts @@ -3,27 +3,28 @@ import { MainOptions, VERBOSE } from '@monorepolyser/dependencies/types'; import { isFileInAWorkspace } from '@monorepolyser/dependencies/utils'; import { addCommentToCurrentPR, Comment, addLabelsToCurrentPR } from '@monorepolyser/ga-utils'; -import { calculatePackagesDependencies } from './utils'; +import { calculatePackagesDependencies, getPackagesFlaggedManuallyAsHighImpact } from './utils'; export interface ImpactAnalysisOptions extends MainOptions { highImpactThreshold: number; highImpactLabels: string[]; onHighImpact: string[]; + highImpactPackagesRegexp: string | null; } const main = async (options: ImpactAnalysisOptions) => { const githubToken = process.env.GITHUB_TOKEN; const client = new github.GitHub(githubToken); - const { project, highImpactThreshold, onHighImpact, highImpactLabels, verbose } = options; + const { project, highImpactThreshold, onHighImpact, highImpactLabels, verbose, highImpactPackagesRegexp } = options; const { totalPackages } = project; const { dependedOnPackages } = calculatePackagesDependencies(project); + const analysis: Record = { - high: [], + high: getPackagesFlaggedManuallyAsHighImpact(project, highImpactPackagesRegexp), low: [], }; const { context } = github; - const { eventName } = context; let base: string | undefined; @@ -109,13 +110,11 @@ const main = async (options: ImpactAnalysisOptions) => { let verboseComment; const verboseRows: any[][] = []; - Object - .keys(dependedOnPackages) - .forEach((key: string) => { - const dependedModules = dependedOnPackages[key]; + Object.keys(dependedOnPackages).forEach((key: string) => { + const dependedModules = dependedOnPackages[key]; - verboseRows.push([key, dependedModules]); - }); + verboseRows.push([key, dependedModules]); + }); verboseRows.sort((a, b) => { const [, aDeps] = a; diff --git a/packages/ga-impact-analysis/utils.ts b/packages/ga-impact-analysis/utils.ts index df25eaa..55247b3 100644 --- a/packages/ga-impact-analysis/utils.ts +++ b/packages/ga-impact-analysis/utils.ts @@ -22,4 +22,23 @@ const calculatePackagesDependencies = (project: ProjectMetadata) => { return { dependedOnPackages }; }; -export { calculatePackagesDependencies }; +const getPackagesFlaggedManuallyAsHighImpact = (project: ProjectMetadata, highImpactPackagesRegexp: string | null) => { + const { packages } = project; + const flaggedPackages: string[] = []; + + if (highImpactPackagesRegexp) { + const regexp = new RegExp(highImpactPackagesRegexp); + + Object.keys(packages).forEach((pkgName) => { + const { name } = packages[pkgName]; + + if (regexp.test(name)) { + flaggedPackages.push(name); + } + }); + } + + return flaggedPackages; +}; + +export { calculatePackagesDependencies, getPackagesFlaggedManuallyAsHighImpact }; diff --git a/packages/ga-monorepolyser/dist/index.js b/packages/ga-monorepolyser/dist/index.js index 01e841e..48876c9 100644 --- a/packages/ga-monorepolyser/dist/index.js +++ b/packages/ga-monorepolyser/dist/index.js @@ -28983,11 +28983,11 @@ const main = (options) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d; const githubToken = process.env.GITHUB_TOKEN; const client = new github.GitHub(githubToken); - const { project, highImpactThreshold, onHighImpact, highImpactLabels, verbose } = options; + const { project, highImpactThreshold, onHighImpact, highImpactLabels, verbose, highImpactPackagesRegexp } = options; const { totalPackages } = project; const { dependedOnPackages } = utils_2.calculatePackagesDependencies(project); const analysis = { - high: [], + high: utils_2.getPackagesFlaggedManuallyAsHighImpact(project, highImpactPackagesRegexp), low: [], }; const { context } = github; @@ -29061,9 +29061,7 @@ const main = (options) => __awaiter(void 0, void 0, void 0, function* () { if (verbose) { let verboseComment; const verboseRows = []; - Object - .keys(dependedOnPackages) - .forEach((key) => { + Object.keys(dependedOnPackages).forEach((key) => { const dependedModules = dependedOnPackages[key]; verboseRows.push([key, dependedModules]); }); @@ -29108,7 +29106,7 @@ exports.main = main; "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.calculatePackagesDependencies = void 0; +exports.getPackagesFlaggedManuallyAsHighImpact = exports.calculatePackagesDependencies = void 0; const calculatePackagesDependencies = (project) => { const dependedOnPackages = {}; const { packages } = project; @@ -29129,6 +29127,21 @@ const calculatePackagesDependencies = (project) => { return { dependedOnPackages }; }; exports.calculatePackagesDependencies = calculatePackagesDependencies; +const getPackagesFlaggedManuallyAsHighImpact = (project, highImpactPackagesRegexp) => { + const { packages } = project; + const flaggedPackages = []; + if (highImpactPackagesRegexp) { + const regexp = new RegExp(highImpactPackagesRegexp); + Object.keys(packages).forEach((pkgName) => { + const { name } = packages[pkgName]; + if (regexp.test(name)) { + flaggedPackages.push(name); + } + }); + } + return flaggedPackages; +}; +exports.getPackagesFlaggedManuallyAsHighImpact = getPackagesFlaggedManuallyAsHighImpact; /***/ }), @@ -29181,6 +29194,7 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () { const highImpactThreshold = parseInt(core.getInput('high-impact-threshold'), 10); const onlyWarn = core.getInput('only-warn') === 'true'; const verbose = core.getInput('verbose'); + const highImpactPackagesRegexp = core.getInput('high-impact-packages-regexp'); const projectMetadataOptions = { workspacesToIgnore: workspacesToIgnore.length > 0 ? workspacesToIgnore.split(',') : [], includeMainPackageJson, @@ -29202,6 +29216,7 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () { onHighImpact, highImpactLabels, verbose, + highImpactPackagesRegexp, }); } }); diff --git a/packages/ga-monorepolyser/index.ts b/packages/ga-monorepolyser/index.ts index 3714949..d140dbf 100644 --- a/packages/ga-monorepolyser/index.ts +++ b/packages/ga-monorepolyser/index.ts @@ -14,6 +14,7 @@ const main = async () => { const highImpactThreshold: number = parseInt(core.getInput('high-impact-threshold'), 10); const onlyWarn: boolean = core.getInput('only-warn') === 'true'; const verbose: VERBOSE = core.getInput('verbose') as VERBOSE; + const highImpactPackagesRegexp: string | null = core.getInput('high-impact-packages-regexp'); const projectMetadataOptions = { workspacesToIgnore: workspacesToIgnore.length > 0 ? workspacesToIgnore.split(',') : [], @@ -39,6 +40,7 @@ const main = async () => { onHighImpact, highImpactLabels, verbose, + highImpactPackagesRegexp, }); } }; From 1f2ef3ec017af204c2772ddeb955eb8105762a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juani=20Gal=C3=A1n?= Date: Sun, 7 Feb 2021 11:10:37 +0100 Subject: [PATCH 2/6] feat(high-impact): test regexp --- .github/workflows/monorepolyser.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/monorepolyser.yml b/.github/workflows/monorepolyser.yml index 7d88770..3a1d564 100644 --- a/.github/workflows/monorepolyser.yml +++ b/.github/workflows/monorepolyser.yml @@ -31,5 +31,6 @@ jobs: on-high-impact: 'comment,add-labels' high-impact-labels: 'high-impact' verbose: 'comment' + high-impact-packages-regexp: '@monorepolyser\/(ga-utils|ga-impact-analysis)' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 3b02786a05f0053e9b05582eeeb2dc292c259b16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juani=20Gal=C3=A1n?= Date: Sun, 7 Feb 2021 11:15:40 +0100 Subject: [PATCH 3/6] feat(high-impact): only add package if it was modified --- packages/ga-impact-analysis/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/ga-impact-analysis/index.ts b/packages/ga-impact-analysis/index.ts index 9f48a19..2b2ae27 100644 --- a/packages/ga-impact-analysis/index.ts +++ b/packages/ga-impact-analysis/index.ts @@ -18,9 +18,10 @@ const main = async (options: ImpactAnalysisOptions) => { const { project, highImpactThreshold, onHighImpact, highImpactLabels, verbose, highImpactPackagesRegexp } = options; const { totalPackages } = project; const { dependedOnPackages } = calculatePackagesDependencies(project); + const manuallyFlaggedPackages = getPackagesFlaggedManuallyAsHighImpact(project, highImpactPackagesRegexp); const analysis: Record = { - high: getPackagesFlaggedManuallyAsHighImpact(project, highImpactPackagesRegexp), + high: [], low: [], }; @@ -70,6 +71,12 @@ const main = async (options: ImpactAnalysisOptions) => { } else if (analysis.low.indexOf(name) < 0) { analysis.low.push(name); } + + if (manuallyFlaggedPackages.indexOf(name) >= 0) { + if (analysis.high.indexOf(name) < 0) { + analysis.high.push(name); + } + } } } }); From 7b502efc782bcb212ceb9810b67f417e9ba04c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juani=20Gal=C3=A1n?= Date: Sun, 7 Feb 2021 11:29:13 +0100 Subject: [PATCH 4/6] feat(high-impact): build --- packages/ga-impact-analysis/utils.ts | 3 +++ packages/ga-monorepolyser/dist/index.js | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/ga-impact-analysis/utils.ts b/packages/ga-impact-analysis/utils.ts index 55247b3..cecfaae 100644 --- a/packages/ga-impact-analysis/utils.ts +++ b/packages/ga-impact-analysis/utils.ts @@ -36,6 +36,9 @@ const getPackagesFlaggedManuallyAsHighImpact = (project: ProjectMetadata, highIm flaggedPackages.push(name); } }); + + // eslint-disable-next-line no-console + console.log('The following packages will be manually flagged as high impact', flaggedPackages); } return flaggedPackages; diff --git a/packages/ga-monorepolyser/dist/index.js b/packages/ga-monorepolyser/dist/index.js index 48876c9..f0aca02 100644 --- a/packages/ga-monorepolyser/dist/index.js +++ b/packages/ga-monorepolyser/dist/index.js @@ -28986,8 +28986,9 @@ const main = (options) => __awaiter(void 0, void 0, void 0, function* () { const { project, highImpactThreshold, onHighImpact, highImpactLabels, verbose, highImpactPackagesRegexp } = options; const { totalPackages } = project; const { dependedOnPackages } = utils_2.calculatePackagesDependencies(project); + const manuallyFlaggedPackages = utils_2.getPackagesFlaggedManuallyAsHighImpact(project, highImpactPackagesRegexp); const analysis = { - high: utils_2.getPackagesFlaggedManuallyAsHighImpact(project, highImpactPackagesRegexp), + high: [], low: [], }; const { context } = github; @@ -29030,6 +29031,11 @@ const main = (options) => __awaiter(void 0, void 0, void 0, function* () { else if (analysis.low.indexOf(name) < 0) { analysis.low.push(name); } + if (manuallyFlaggedPackages.indexOf(name) >= 0) { + if (analysis.high.indexOf(name) < 0) { + analysis.high.push(name); + } + } } } }); @@ -29138,6 +29144,8 @@ const getPackagesFlaggedManuallyAsHighImpact = (project, highImpactPackagesRegex flaggedPackages.push(name); } }); + // eslint-disable-next-line no-console + console.log('The following packages will be manually flagged as high impact', flaggedPackages); } return flaggedPackages; }; From 983df12557e56ae44f092d13f02fe4f47ee5eb91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juani=20Gal=C3=A1n?= Date: Sun, 7 Feb 2021 11:37:54 +0100 Subject: [PATCH 5/6] chore(release): 0.2.6 --- README.md | 15 ++++++++------- package.json | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 740b4e7..505df20 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ steps: - name: Checkout uses: actions/checkout@v2 - name: Check dependencies - uses: juanigalan91/monorepolyser@0.2.5 + uses: juanigalan91/monorepolyser@0.2.6 with: # Whether you want to execute the check dependencies action or not check-dependencies: true @@ -60,7 +60,7 @@ steps: - name: Checkout uses: actions/checkout@v2 - name: Check dependencies - uses: juanigalan91/monorepolyser@0.2.5 + uses: juanigalan91/monorepolyser@0.2.6 with: check-dependencies: true ignore-workspaces: 'dev-packages,third-parties' # lists of workspaces to ignore from the check, list of strings separated by a comma @@ -75,7 +75,7 @@ steps: - name: Checkout uses: actions/checkout@v2 - name: Check dependencies - uses: juanigalan91/monorepolyser@0.2.5 + uses: juanigalan91/monorepolyser@0.2.6 with: check-dependencies: true include-main-package-json: true @@ -90,7 +90,7 @@ steps: - name: Checkout uses: actions/checkout@v2 - name: Check dependencies - uses: juanigalan91/monorepolyser@0.2.5 + uses: juanigalan91/monorepolyser@0.2.6 with: check-dependencies: true only-warn: true @@ -105,7 +105,7 @@ steps: - name: Checkout uses: actions/checkout@v2 - name: Check impact - uses: juanigalan91/monorepolyser@0.2.5 + uses: juanigalan91/monorepolyser@0.2.6 with: impact-analysis: true env: @@ -119,12 +119,13 @@ steps: - name: Checkout uses: actions/checkout@v2 - name: Check impact - uses: juanigalan91/monorepolyser@0.2.5 + uses: juanigalan91/monorepolyser@0.2.6 with: impact-analysis: true high-impact-threshold: 50 # percentage (0-100) of the packages that will be impacted by this PR in order for it to be of high impact on-high-impact: 'comment,add-labels' # action to be executed on high impact PR. it can be 'comment', 'add-labels' or multiple, separated by a comma high-impact-labels: 'high-impact' # Labels to be added (separated by a comma) if the PR has a high impact + high-impact-packages-regexp: '@monorepolyser\/(ga-utils|ga-impact-analysis)' # Regular expression to manually flag packages as high impact env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` @@ -137,7 +138,7 @@ steps: - name: Checkout uses: actions/checkout@v2 - name: Check impact - uses: juanigalan91/monorepolyser@0.2.5 + uses: juanigalan91/monorepolyser@0.2.6 with: impact-analysis: true verbose: 'logs' # where to print the analysis. This can be 'logs' and you would need to search this actions logs to see it, or 'comment' and this will add a comment to the PR diff --git a/package.json b/package.json index c86354d..b21aa3a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "monorepolyser", - "version": "0.2.4", + "version": "0.2.6", "description": "", "main": "index.js", "private": true, From da6f004211decc9e09e02269b14337c2d67080ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juani=20Gal=C3=A1n?= Date: Sun, 7 Feb 2021 11:39:55 +0100 Subject: [PATCH 6/6] chore(release): remove test regexp --- .github/workflows/monorepolyser.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/monorepolyser.yml b/.github/workflows/monorepolyser.yml index 3a1d564..7d88770 100644 --- a/.github/workflows/monorepolyser.yml +++ b/.github/workflows/monorepolyser.yml @@ -31,6 +31,5 @@ jobs: on-high-impact: 'comment,add-labels' high-impact-labels: 'high-impact' verbose: 'comment' - high-impact-packages-regexp: '@monorepolyser\/(ga-utils|ga-impact-analysis)' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file