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 collapse_changes option #79

Closed
wants to merge 3 commits into from
Closed
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. |
| `collapse_changes` | `false` | If `true`, hide the analysis table inside an accordion. If `false`, display the analysis table directly. |
| `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 @@ -22,6 +22,7 @@ describe("examples w/o base analysis", () => {
name: "test",
showDetails: false,
showNoChange: true,
collapseChanges: false,
topNLargestPaths: 10,
};

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 @@ -34,6 +34,7 @@ describe("examples w/ base analysis", () => {
name: "test",
showDetails: false,
showNoChange: isEven,
collapseChanges: !isEven,
topNLargestPaths: 10,
};

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).not.toMatch("View analysis table");
} else {
expect(comment).toMatch(/\d bundles with no change are hidden./i);
expect(comment).toMatch("View analysis table");
}
expect(comment).toMatch(/🆕 Added/i);
expect(comment).toMatch(/🗑️ Deleted/i);
Expand Down
6 changes: 6 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ inputs:
default: "true"
description: |
If `true`, all bundles are shown in the analysis regardless of size change. If `false`, only bundles with size changes are shown.
collapse_changes:
required: false
default: "false"
description: |
If `true`, hide the analysis table inside an accordion. If `false`, display the analysis table directly.
top_n_largest_paths:
required: false
default: "20"
Expand Down Expand Up @@ -89,6 +94,7 @@ runs:
INPUT_PERCENT_EXTRA_ATTENTION: ${{ inputs.percent_extra_attention }}
INPUT_SHOW_DETAILS: ${{ inputs.show_details }}
INPUT_SHOW_NO_CHANGE: ${{ inputs.show_no_change }}
INPUT_COLLAPSE_CHANGES: ${{ inputs.collapse_changes }}
INPUT_TOP_N_LARGEST_PATHS: ${{ inputs.top_n_largest_paths }}
run: |
node ${{ github.action_path }}/dist/index.mjs
Expand Down
21 changes: 14 additions & 7 deletions dist/index.mjs

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion src/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ This analysis was generated by [esbuild-bundle-analyzer](https://github.com/exoe
comparison,
input.percentExtraAttention,
input.showNoChange,
input.collapseChanges,
);
output += noChangesTable(comparison, input.showNoChange);
output += fileSizeTable(comparison, input.topNLargestPaths);
Expand Down Expand Up @@ -229,6 +230,7 @@ function markdownTable(
data: Array<CompareResult>,
redThreshold: number,
showNoChange: boolean,
collapseChanges: boolean,
): string {
const rows = data
.filter((d) => shouldShowBundle(d, showNoChange))
Expand All @@ -240,10 +242,22 @@ function markdownTable(
})
.join("");

return `
const table = `
Meta File | Out File | Size (raw) | Note
----------|----------|-----------:|------
${rows}`;

if (collapseChanges) {
return `
<details>
<summary>View analysis table</summary>

${table}

</details>
`;
}
return table;
}

function noChangesTable(
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",
),
collapseChanges: ["true", "True", "TRUE"].includes(
getSingleInput("collapse_changes"),
),
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;
collapseChanges: boolean;
}

export interface TreeMapNode {
Expand Down