Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add show_total_changes #80

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Please check the above setup example to use this action with `pull_request_targe
| `percent_extra_attention` | `20` | If an out file size has increased more than this percent, display a "‼️" to draw extra attention to the change. |
| `show_details` | `true` | If `true`, a collapsed "details" section is rendered. It explains the details of the numbers provided and icons. |
| `show_no_change` | `true` | If `true`, all bundles are shown in the analysis regardless of size change. If `false`, only bundles with size changes are shown. |
| `show_total_changes` | `false` | If `true`, the cumulative number of changes in bundle sizes is rendered. |
| `top_n_largest_paths` | `20` | The number of largest paths (e.g.) `node_modules/foo`) to be collected. If 0 or lower, skipped. |

## Action outputs
Expand Down
1 change: 1 addition & 0 deletions __tests__/no-base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe("examples w/o base analysis", () => {
showDetails: false,
showNoChange: true,
topNLargestPaths: 10,
showTotalChanges: false,
};

beforeEach(() => {
Expand Down
3 changes: 3 additions & 0 deletions __tests__/with-base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe("examples w/ base analysis", () => {
showDetails: false,
showNoChange: isEven,
topNLargestPaths: 10,
showTotalChanges: isEven,
};

beforeEach(() => {
Expand All @@ -60,8 +61,10 @@ describe("examples w/ base analysis", () => {
expect(comment).toMatch(/✅ {2}No change/i);
if (isEven) {
expect(comment).not.toMatch(/\d bundles with no change are hidden./i);
expect(comment).toMatch(/\(Total\) \| - \|.+⚠️/i);
} else {
expect(comment).toMatch(/\d bundles with no change are hidden./i);
expect(comment).not.toMatch(/\(Total\) \| - \|.+⚠️/i);
}
expect(comment).toMatch(/🆕 Added/i);
expect(comment).toMatch(/🗑️ Deleted/i);
Expand Down
5 changes: 5 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ inputs:
description: |
If an out file size has increased more than this percent, display a "‼️" to draw attention
to the change.
show_total_changes:
required: false
default: "false"
description: |
If `true`, the cumulative number of changes in bundle sizes is rendered.
show_details:
required: false
default: "true"
Expand Down
14 changes: 7 additions & 7 deletions dist/index.mjs

Large diffs are not rendered by default.

28 changes: 26 additions & 2 deletions src/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ This analysis was generated by [esbuild-bundle-analyzer](https://github.com/exoe
output += markdownTable(
comparison,
input.percentExtraAttention,
input.showTotalChanges,
input.showNoChange,
);
output += noChangesTable(comparison, input.showNoChange);
Expand Down Expand Up @@ -228,10 +229,33 @@ const shouldShowBundle = (d: CompareResult, showNoChange: boolean) =>
function markdownTable(
data: Array<CompareResult>,
redThreshold: number,
showTotalChanges: boolean,
showNoChange: boolean,
): string {
const rows = data
.filter((d) => shouldShowBundle(d, showNoChange))
const totalRow = data.reduce(
(acc, d) => {
const { bytes, baseBytes, ...rest } = acc;
return {
...rest,
baseBytes: baseBytes + d.baseBytes,
bytes: bytes + d.bytes,
};
},
{
baseBytes: 0,
bytes: 0,
metafile: "(Total)",
outfile: "-",
remark: "added",
tree: undefined,
},
);
totalRow.remark =
totalRow.bytes > totalRow.baseBytes ? "increased" : "decreased";
const totalRows: Array<CompareResult> = showTotalChanges ? [totalRow] : [];

const individualRows = data.filter((d) => shouldShowBundle(d, showNoChange));
const rows = [...totalRows, ...individualRows]
.map((d) => {
return `${d.metafile} | ${d.outfile} | ${renderSize(d)} | ${renderNote(
d,
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ function getInput(): Input {
showNoChange: ["true", "True", "TRUE"].includes(
getSingleInput("show_no_change") || "true",
),
showTotalChanges: ["true", "True", "TRUE"].includes(
getSingleInput("show_total_changes") || "false",
),
topNLargestPaths: Number.parseInt(
getSingleInput("top_n_largest_paths") || "20",
10,
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface Input {
percentExtraAttention: number;
showDetails: boolean;
showNoChange: boolean;
showTotalChanges: boolean;
}

export interface TreeMapNode {
Expand Down