Skip to content

Commit

Permalink
Merge pull request #22 from juanigalan91/development
Browse files Browse the repository at this point in the history
Release 0.2.6
  • Loading branch information
juanigalan91 authored Feb 7, 2021
2 parents caf6217 + b8f4408 commit a1e73cb
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 23 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ steps:
- name: Checkout
uses: actions/checkout@v2
- name: Check dependencies
uses: juanigalan91/[email protected].5
uses: juanigalan91/[email protected].6
with:
# Whether you want to execute the check dependencies action or not
check-dependencies: true
Expand All @@ -60,7 +60,7 @@ steps:
- name: Checkout
uses: actions/checkout@v2
- name: Check dependencies
uses: juanigalan91/[email protected].5
uses: juanigalan91/[email protected].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
Expand All @@ -75,7 +75,7 @@ steps:
- name: Checkout
uses: actions/checkout@v2
- name: Check dependencies
uses: juanigalan91/[email protected].5
uses: juanigalan91/[email protected].6
with:
check-dependencies: true
include-main-package-json: true
Expand All @@ -90,7 +90,7 @@ steps:
- name: Checkout
uses: actions/checkout@v2
- name: Check dependencies
uses: juanigalan91/[email protected].5
uses: juanigalan91/[email protected].6
with:
check-dependencies: true
only-warn: true
Expand All @@ -105,7 +105,7 @@ steps:
- name: Checkout
uses: actions/checkout@v2
- name: Check impact
uses: juanigalan91/[email protected].5
uses: juanigalan91/[email protected].6
with:
impact-analysis: true
env:
Expand All @@ -119,12 +119,13 @@ steps:
- name: Checkout
uses: actions/checkout@v2
- name: Check impact
uses: juanigalan91/[email protected].5
uses: juanigalan91/[email protected].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 }}
```
Expand All @@ -137,7 +138,7 @@ steps:
- name: Checkout
uses: actions/checkout@v2
- name: Check impact
uses: juanigalan91/[email protected].5
uses: juanigalan91/[email protected].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
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monorepolyser",
"version": "0.2.4",
"version": "0.2.6",
"description": "",
"main": "index.js",
"private": true,
Expand Down
24 changes: 15 additions & 9 deletions packages/ga-impact-analysis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@ 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 manuallyFlaggedPackages = getPackagesFlaggedManuallyAsHighImpact(project, highImpactPackagesRegexp);

const analysis: Record<string, string[]> = {
high: [],
low: [],
};

const { context } = github;

const { eventName } = context;

let base: string | undefined;
Expand Down Expand Up @@ -69,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);
}
}
}
}
});
Expand Down Expand Up @@ -109,13 +117,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;
Expand Down
24 changes: 23 additions & 1 deletion packages/ga-impact-analysis/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,26 @@ 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);
}
});

// eslint-disable-next-line no-console
console.log('The following packages will be manually flagged as high impact', flaggedPackages);
}

return flaggedPackages;
};

export { calculatePackagesDependencies, getPackagesFlaggedManuallyAsHighImpact };
33 changes: 28 additions & 5 deletions packages/ga-monorepolyser/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28983,9 +28983,10 @@ 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 manuallyFlaggedPackages = utils_2.getPackagesFlaggedManuallyAsHighImpact(project, highImpactPackagesRegexp);
const analysis = {
high: [],
low: [],
Expand Down Expand Up @@ -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);
}
}
}
}
});
Expand Down Expand Up @@ -29061,9 +29067,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]);
});
Expand Down Expand Up @@ -29108,7 +29112,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;
Expand All @@ -29129,6 +29133,23 @@ 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);
}
});
// eslint-disable-next-line no-console
console.log('The following packages will be manually flagged as high impact', flaggedPackages);
}
return flaggedPackages;
};
exports.getPackagesFlaggedManuallyAsHighImpact = getPackagesFlaggedManuallyAsHighImpact;


/***/ }),
Expand Down Expand Up @@ -29181,6 +29202,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,
Expand All @@ -29202,6 +29224,7 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
onHighImpact,
highImpactLabels,
verbose,
highImpactPackagesRegexp,
});
}
});
Expand Down
2 changes: 2 additions & 0 deletions packages/ga-monorepolyser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(',') : [],
Expand All @@ -39,6 +40,7 @@ const main = async () => {
onHighImpact,
highImpactLabels,
verbose,
highImpactPackagesRegexp,
});
}
};
Expand Down

0 comments on commit a1e73cb

Please sign in to comment.