Skip to content

Commit

Permalink
Merge pull request #19 from juanigalan91/development
Browse files Browse the repository at this point in the history
Release 0.2.4
  • Loading branch information
juanigalan91 authored Jan 10, 2021
2 parents a613c0e + 62f5556 commit 93cda22
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/monorepolyser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ jobs:
high-impact-threshold: 50
on-high-impact: 'comment,add-labels'
high-impact-labels: 'high-impact'
verbose: 'comment'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 4 additions & 1 deletion CHANGE_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

## Unreleased

## 0.2.3 (current)
## 0.2.4 (current)
- Allow to print the impact analysis

## 0.2.3
- Impact Analysis

## 0.2.2
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,20 @@ steps:
high-impact-labels: 'high-impact' # Labels to be added (separated by a comma) if the PR has a high impact
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

If you want to have the analysis printed, you can choose to print this on the logs or on the PR as a comment. To do so, you can use the `verbose` parameter


```yaml
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Check impact
uses: juanigalan91/[email protected]
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
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ inputs:
description: 'Labels to be added (separated by a comma) if the PR has a high impact'
required: false
default: ''
verbose:
description: 'Whether this action logs the results of its analysis or not. It can be "comment" or "logs"'
required: false
default: false
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.3",
"version": "0.2.4",
"description": "",
"main": "index.js",
"private": true,
Expand Down
6 changes: 6 additions & 0 deletions packages/dependencies/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ export interface ProjectMetadata {
totalPackages?: number;
}

export enum VERBOSE {
LOGS = 'logs',
COMMENT = 'comment',
}

export interface MainOptions {
onlyWarn?: boolean;
project: ProjectMetadata;
verbose?: VERBOSE;
}
66 changes: 57 additions & 9 deletions packages/ga-impact-analysis/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as github from '@actions/github';
import { MainOptions } from '@monorepolyser/dependencies/types';
import { MainOptions, VERBOSE } from '@monorepolyser/dependencies/types';
import { isFileInAWorkspace } from '@monorepolyser/dependencies/utils';
import { addCommentToCurrentPR, Comment, addLabelsToCurrentPR } from '@monorepolyser/ga-utils';

Expand All @@ -14,7 +14,7 @@ export interface ImpactAnalysisOptions extends MainOptions {
const main = async (options: ImpactAnalysisOptions) => {
const githubToken = process.env.GITHUB_TOKEN;
const client = new github.GitHub(githubToken);
const { project, highImpactThreshold, onHighImpact, highImpactLabels } = options;
const { project, highImpactThreshold, onHighImpact, highImpactLabels, verbose } = options;
const { totalPackages } = project;
const { dependedOnPackages } = calculatePackagesDependencies(project);
const analysis: Record<string, string[]> = {
Expand Down Expand Up @@ -64,10 +64,8 @@ const main = async (options: ImpactAnalysisOptions) => {
if (analysis.high.indexOf(name) < 0) {
analysis.high.push(name);
}
} else {
if (analysis.low.indexOf(name) < 0) {
analysis.low.push(name);
}
} else if (analysis.low.indexOf(name) < 0) {
analysis.low.push(name);
}
}
});
Expand All @@ -84,17 +82,17 @@ const main = async (options: ImpactAnalysisOptions) => {
text:
'One or several core packages have been modified, and this PR has been flagged as high impact. The modified packages are the following:',
});

const rows: string[][] = [];
analysis.high.forEach((highImpactModule) => {
rows.push([highImpactModule]);
});

comment.addTable({
columns: ['Package'],
rows,
});

addCommentToCurrentPR(comment);
}

Expand All @@ -103,6 +101,56 @@ const main = async (options: ImpactAnalysisOptions) => {
}
}
}

if (verbose) {
let verboseComment;
const verboseRows: any[][] = [];

Object
.keys(dependedOnPackages)
.forEach((key: string) => {
const dependedModules = dependedOnPackages[key];

verboseRows.push([key, dependedModules]);
});

verboseRows.sort((a, b) => {
const [, aDeps] = a;
const [, bDeps] = b;

return bDeps - aDeps;
});

switch (verbose) {
case VERBOSE.COMMENT:
verboseComment = new Comment();

verboseComment.addTitle({
title: 'Impact Analysis',
level: 2,
});

verboseComment.addText({
text:
'Here is a report your packages dependencies, showing the packages order from most depended on to least depended on:',
});

verboseComment.addTable({
columns: ['Package', 'Packages that depend on this package'],
rows: verboseRows,
});

addCommentToCurrentPR(verboseComment);

break;
default:
// eslint-disable-next-line no-console
console.log('Here is a report your packages dependencies, showing the packages order from most depended on to least depended on:');
// eslint-disable-next-line no-console
console.log(verboseRows);
break;
}
}
};

export { main };
66 changes: 61 additions & 5 deletions packages/ga-monorepolyser/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28686,6 +28686,22 @@ const getProjectMetadata = (options = GET_PROJECT_METADATA_DEFAULTS) => {
exports.getProjectMetadata = getProjectMetadata;


/***/ }),

/***/ 6522:
/***/ ((__unused_webpack_module, exports) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.VERBOSE = void 0;
var VERBOSE;
(function (VERBOSE) {
VERBOSE["LOGS"] = "logs";
VERBOSE["COMMENT"] = "comment";
})(VERBOSE = exports.VERBOSE || (exports.VERBOSE = {}));


/***/ }),

/***/ 7478:
Expand Down Expand Up @@ -28959,14 +28975,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.main = void 0;
const github = __importStar(__webpack_require__(4312));
const types_1 = __webpack_require__(6522);
const utils_1 = __webpack_require__(7478);
const ga_utils_1 = __webpack_require__(5721);
const utils_2 = __webpack_require__(355);
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 } = options;
const { project, highImpactThreshold, onHighImpact, highImpactLabels, verbose } = options;
const { totalPackages } = project;
const { dependedOnPackages } = utils_2.calculatePackagesDependencies(project);
const analysis = {
Expand Down Expand Up @@ -29009,10 +29026,8 @@ const main = (options) => __awaiter(void 0, void 0, void 0, function* () {
analysis.high.push(name);
}
}
else {
if (analysis.low.indexOf(name) < 0) {
analysis.low.push(name);
}
else if (analysis.low.indexOf(name) < 0) {
analysis.low.push(name);
}
}
});
Expand Down Expand Up @@ -29041,6 +29056,44 @@ const main = (options) => __awaiter(void 0, void 0, void 0, function* () {
}
}
}
if (verbose) {
let verboseComment;
const verboseRows = [];
Object
.keys(dependedOnPackages)
.forEach((key) => {
const dependedModules = dependedOnPackages[key];
verboseRows.push([key, dependedModules]);
});
verboseRows.sort((a, b) => {
const [, aDeps] = a;
const [, bDeps] = b;
return bDeps - aDeps;
});
switch (verbose) {
case types_1.VERBOSE.COMMENT:
verboseComment = new ga_utils_1.Comment();
verboseComment.addTitle({
title: 'Impact Analysis',
level: 2,
});
verboseComment.addText({
text: 'Here is a report your packages dependencies, showing the packages order from most depended on to least depended on:',
});
verboseComment.addTable({
columns: ['Package', 'Packages that depend on this package'],
rows: verboseRows,
});
ga_utils_1.addCommentToCurrentPR(verboseComment);
break;
default:
// eslint-disable-next-line no-console
console.log('Here is a report your packages dependencies, showing the packages order from most depended on to least depended on:');
// eslint-disable-next-line no-console
console.log(verboseRows);
break;
}
}
});
exports.main = main;

Expand Down Expand Up @@ -29125,6 +29178,7 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
const highImpactLabels = core.getInput('high-impact-labels').split(',');
const highImpactThreshold = parseInt(core.getInput('high-impact-threshold'), 10);
const onlyWarn = core.getInput('only-warn') === 'true';
const verbose = core.getInput('verbose');
const projectMetadataOptions = {
workspacesToIgnore: workspacesToIgnore.length > 0 ? workspacesToIgnore.split(',') : [],
includeMainPackageJson,
Expand All @@ -29135,6 +29189,7 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
yield ga_check_dependencies_1.main({
project,
onlyWarn,
verbose,
});
}
if (shouldAnalyseImpact) {
Expand All @@ -29144,6 +29199,7 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
highImpactThreshold,
onHighImpact,
highImpactLabels,
verbose,
});
}
});
Expand Down
4 changes: 4 additions & 0 deletions packages/ga-monorepolyser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as core from '@actions/core';
import { main as checkDependencies } from '@monorepolyser/ga-check-dependencies';
import { main as impactAnalysis } from '@monorepolyser/ga-impact-analysis';
import { getProjectMetadata } from '@monorepolyser/dependencies';
import { VERBOSE } from '@monorepolyser/dependencies/types';

const main = async () => {
const shouldCheckDependencies: boolean = core.getInput('check-dependencies') === 'true';
Expand All @@ -12,6 +13,7 @@ const main = async () => {
const highImpactLabels: string[] = core.getInput('high-impact-labels').split(',');
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 projectMetadataOptions = {
workspacesToIgnore: workspacesToIgnore.length > 0 ? workspacesToIgnore.split(',') : [],
Expand All @@ -25,6 +27,7 @@ const main = async () => {
await checkDependencies({
project,
onlyWarn,
verbose,
});
}

Expand All @@ -35,6 +38,7 @@ const main = async () => {
highImpactThreshold,
onHighImpact,
highImpactLabels,
verbose,
});
}
};
Expand Down

0 comments on commit 93cda22

Please sign in to comment.