-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaction.yaml
137 lines (125 loc) · 5.12 KB
/
action.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: esbuild-bundle-analyzer
description: Analyzes each PR's impact on esbuild bundle size
inputs:
name:
required: false
default: ${{ github.event.repository.name }}
description: |
The name of your project. This will be used in the comment header.
metafiles:
required: true
description: |
A comma-separated list of paths to [esbuild's meta file]([https://esbuild.github.io/api/#metafile]).
Must be non-empty.
Glob (`dist/**/meta.json`) is supported.
As of esbuild v0.20.0, you need to write the meta file by yourself after build, something like this:
```javascript
import * as esbuild from 'esbuild'
import fs from 'node:fs'
let result = await esbuild.build({
entryPoints: ['src/app1.js', 'src/app2.js'],
bundle: true,
metafile: true,
outdir: 'dist',
})
fs.writeFileSync('dist/meta.json', JSON.stringify(result.metafile))
```
In this case, the `metafiles` config should be `"dist/meta.json"`.
Typically, you only need one meta file since one meta file can contain multiple out files information.
Multiple meta files may be useful for more complex scenarios.
analyze_directory:
required: false
default: ".analyzer"
description: |
A path to working directory where bundle analysis are stored.
include_extensions:
required: false
default: ".js,.cjs,.mjs"
description: |
A comma-separated list of file extension to be included in the analysis table.
percent_extra_attention:
required: false
default: "20"
description: |
If an out file size has increased more than this percent, display a "‼️" to draw attention
to the change.
include_size_comparison:
required: false
default: "added, deleted, increased, decreased, no-change"
description: |
A comma-separated list of size comparison items to be displayed.
Available filter are `total`, `added`, `deleted`, `increased`, `decreased` and `no-change`.
If you are not interested in some of them, you can remove them from the list.
show_details:
required: false
default: "true"
description: |
If `true`, a collapsed "details" section is rendered. It explains the details of the numbers provided and icons.
show_no_change:
required: false
deprecationMessage: |
Use the `include_size_comparison` list to show/hide `no-change`.
description: |
If `true`, all bundles are shown in the analysis regardless of size change. If `false`, only bundles with size changes are shown.
top_n_largest_paths:
required: false
default: "20"
description: |
The number of largest paths (e.g.) `node_modules/foo`) to be collected.
If 0 or lower, skipped.
runs:
using: composite
steps:
- name: Download base branch bundle stats
uses: dawidd6/action-download-artifact@v7
# Ok to continue on error since the base branch has no bundle analysis artifact for the first setup
continue-on-error: true
if: success() && github.event.number
with:
branch: ${{ github.event.pull_request.base.ref }}
path: ${{ inputs.analyze_directory }}/base
- name: Compare with base branch bundle
shell: bash
if: success()
env:
INPUT_METAFILES: ${{ inputs.metafiles }}
INPUT_NAME: ${{ inputs.name }}
INPUT_ANALYZE_DIRECTORY: ${{ inputs.analyze_directory }}
INPUT_INCLUDE_EXTENSIONS: ${{ inputs.include_extensions }}
INPUT_INCLUDE_SIZE_COMPARISON: ${{ inputs.include_size_comparison }}
INPUT_PERCENT_EXTRA_ATTENTION: ${{ inputs.percent_extra_attention }}
INPUT_SHOW_DETAILS: ${{ inputs.show_details }}
INPUT_SHOW_NO_CHANGE: ${{ inputs.show_no_change }}
INPUT_TOP_N_LARGEST_PATHS: ${{ inputs.top_n_largest_paths }}
run: |
node ${{ github.action_path }}/dist/index.mjs
- name: Upload bundle analysis on default branch
uses: actions/upload-artifact@v4
if: success() && github.ref_name == github.event.repository.default_branch
with:
name: bundle
path: ${{ inputs.analyze_directory }}/bundle_analysis.json
- name: Find Comment
uses: peter-evans/find-comment@v3
if: success() && github.event.number
id: fc
with:
issue-number: ${{ github.event.number }}
body-includes: '<!-- __ESBUILD_BUNDLE_${{ inputs.name }} -->'
- name: Create Comment
uses: peter-evans/create-or-update-comment@v4
if: success() && github.event.number && steps.fc.outputs.comment-id == 0
with:
issue-number: ${{ github.event.number }}
body-path: ${{ inputs.analyze_directory }}/bundle_analysis_comment.txt
- name: Update Comment
uses: peter-evans/create-or-update-comment@v4
if: success() && github.event.number && steps.fc.outputs.comment-id != 0
with:
issue-number: ${{ github.event.number }}
body-path: ${{ inputs.analyze_directory }}/bundle_analysis_comment.txt
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
branding:
icon: 'package'
color: 'yellow'