Skip to content

Commit 246e419

Browse files
[ops] Remove limits.yml codeownership, add bundle-size PR comment workflow (elastic#270233)
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
1 parent 9d57f7e commit 246e419

3 files changed

Lines changed: 131 additions & 0 deletions

File tree

.github/CODEOWNERS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,11 @@ x-pack/solutions/workplaceai/test @elastic/workchat-eng
13851385
## https://help.github.com/articles/about-codeowners/
13861386
####
13871387

1388+
# limits.yml changes frequently as bundle sizes shift; no owner means the ops
1389+
# team isn't auto-requested as reviewer on every bump. A GitHub Actions workflow
1390+
# (bundle-size-limits-comment.yml) flags increases ≥15% instead.
1391+
packages/kbn-optimizer/limits.yml
1392+
13881393
# The #CC# prefix delineates Code Coverage,
13891394
# used for the 'team' designator within Kibana Stats
13901395

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
const THRESHOLD = 0.15;
2+
const MARKER = '<!-- bundle-size-limits-comment -->';
3+
4+
const getContent = async ({ github, context }, ref) => {
5+
const { data } = await github.rest.repos.getContent({
6+
owner: context.repo.owner,
7+
repo: context.repo.repo,
8+
path: 'packages/kbn-optimizer/limits.yml',
9+
ref,
10+
});
11+
return Buffer.from(data.content, 'base64').toString('utf8');
12+
};
13+
14+
const parseYaml = (content) => {
15+
const result = {};
16+
for (const line of content.split('\n')) {
17+
const match = line.match(/^\s{2}(\w+):\s*(\d+)/);
18+
if (match) result[match[1]] = parseInt(match[2], 10);
19+
}
20+
return result;
21+
};
22+
23+
module.exports = async ({ github, context }) => {
24+
const pr = context.payload.pull_request;
25+
26+
const [baseContent, headContent] = await Promise.all([
27+
getContent({ github, context }, pr.base.sha),
28+
getContent({ github, context }, pr.head.sha),
29+
]);
30+
31+
const baseMap = parseYaml(baseContent);
32+
const headMap = parseYaml(headContent);
33+
34+
const bigIncreases = [];
35+
for (const [plugin, headSize] of Object.entries(headMap)) {
36+
const baseSize = baseMap[plugin];
37+
if (baseSize != null && headSize > baseSize) {
38+
const pct = (headSize - baseSize) / baseSize;
39+
if (pct >= THRESHOLD) {
40+
bigIncreases.push({ plugin, baseSize, headSize, pct });
41+
}
42+
}
43+
}
44+
45+
const { data: comments } = await github.rest.issues.listComments({
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
issue_number: context.issue.number,
49+
});
50+
const existing = comments.find((c) => c.body && c.body.includes(MARKER));
51+
52+
if (bigIncreases.length === 0) {
53+
if (existing) {
54+
await github.rest.issues.deleteComment({
55+
owner: context.repo.owner,
56+
repo: context.repo.repo,
57+
comment_id: existing.id,
58+
});
59+
}
60+
return;
61+
}
62+
63+
const rows = bigIncreases
64+
.sort((a, b) => b.pct - a.pct)
65+
.map(
66+
({ plugin, baseSize, headSize, pct }) =>
67+
`| \`${plugin}\` | ${baseSize.toLocaleString()} | ${headSize.toLocaleString()} | +${(pct * 100).toFixed(1)}% |`
68+
)
69+
.join('\n');
70+
71+
const body =
72+
`@${pr.user.login}, this PR increases one or more page-load bundle sizes by 15% or more:\n\n` +
73+
`| Plugin | Before (bytes) | After (bytes) | Change |\n` +
74+
`|--------|----------------|---------------|--------|\n` +
75+
`${rows}\n\n` +
76+
`Large bundle size increases can affect page load performance. Consider whether dependencies can be lazy-loaded or code split to reduce the bundle.\n\n` +
77+
`See the [bundle optimization guide](https://www.elastic.co/docs/extend/kibana/ci-metrics#ci-metric-resolving-overages) for tips.\n\n` +
78+
`${MARKER}`;
79+
80+
if (existing) {
81+
await github.rest.issues.updateComment({
82+
owner: context.repo.owner,
83+
repo: context.repo.repo,
84+
comment_id: existing.id,
85+
body,
86+
});
87+
} else {
88+
await github.rest.issues.createComment({
89+
issue_number: context.issue.number,
90+
owner: context.repo.owner,
91+
repo: context.repo.repo,
92+
body,
93+
});
94+
}
95+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: bundle-size-limits-comment
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- synchronize
8+
paths:
9+
- 'packages/kbn-optimizer/limits.yml'
10+
11+
jobs:
12+
comment:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
pull-requests: write
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
19+
with:
20+
persist-credentials: false
21+
sparse-checkout: .github
22+
sparse-checkout-cone-mode: true
23+
fetch-depth: 1
24+
25+
- name: Comment on large bundle size increases
26+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
27+
with:
28+
github-token: ${{ secrets.GITHUB_TOKEN }}
29+
script: |
30+
const run = require('./.github/scripts/bundle_size_limits_comment');
31+
await run({ github, context });

0 commit comments

Comments
 (0)