Skip to content

Commit f05e865

Browse files
chore: Add pr comment for build size
Adding CI process and scripts to create a comment on PRs that provide details around the file size increase or decrease for minified loaders.
1 parent d51cf2d commit f05e865

File tree

7 files changed

+2411
-2952
lines changed

7 files changed

+2411
-2952
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,36 @@ on:
77
pull_request:
88

99
jobs:
10+
size-check:
11+
if: github.event_name == 'pull_request'
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 30
14+
container:
15+
image: ubuntu:latest
16+
defaults:
17+
run:
18+
shell: bash
19+
steps:
20+
- name: Setup Container
21+
run: apt update && apt install -y git
22+
- uses: actions/checkout@v3
23+
- uses: actions/setup-node@v3
24+
with:
25+
node-version: lts/*
26+
- name: Install Dependencies
27+
run: npm ci
28+
- name: Running Prod Build
29+
run: npm run cdn:build:dev
30+
- name: Generating Asset Size Report
31+
run: node ./tools/scripts/diff-sizes.mjs -o build
32+
- name: Creating PR Comment
33+
run: |
34+
node ./tools/scripts/comment-pr.mjs \
35+
--pull-request=${{ github.event.pull_request.number }} \
36+
--token=${{ secrets.GITHUB_TOKEN }} \
37+
--input=./build/size_report.md \
38+
--tag='<!-- browser_agent asset size report -->'
39+
1040
lint:
1141
runs-on: ubuntu-latest
1242
timeout-minutes: 30

package-lock.json

Lines changed: 2118 additions & 2722 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@
112112
"eslint-plugin-promise": "^6.1.1",
113113
"fastify": "^4.13.0",
114114
"fastify-plugin": "^4.4.0",
115+
"filesize": "^10.0.6",
116+
"fs-extra": "^11.1.0",
115117
"function-bind": "^1.1.1",
116118
"glob": "^7.0.5",
117119
"husky": "^8.0.0",
@@ -126,9 +128,10 @@
126128
"minimatch": "^3.0.3",
127129
"multiparty": "^4.1.2",
128130
"newrelic": "^4.11.0",
129-
"node-fetch": "^3.2.10",
131+
"node-fetch": "^3.3.1",
130132
"npm-run-all": "^4.1.5",
131133
"object-inspect": "^1.5.0",
134+
"octokit": "^2.0.14",
132135
"preprocessify": "0.0.6",
133136
"request": "2.74.0",
134137
"sauce-connect-launcher": "^1.2.4",

tools/jil/util/browsers-supported.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
},
1010
{
1111
"browserName": "chrome",
12-
"platform": "Windows 10",
13-
"platformName": "Windows 10",
14-
"version": "108",
15-
"browserVersion": "108"
12+
"platform": "Windows 11",
13+
"platformName": "Windows 11",
14+
"version": "107",
15+
"browserVersion": "107"
1616
},
1717
{
1818
"browserName": "chrome",
@@ -23,19 +23,19 @@
2323
},
2424
{
2525
"browserName": "chrome",
26-
"platform": "Windows 10",
27-
"platformName": "Windows 10",
28-
"version": "101",
29-
"browserVersion": "101"
26+
"platform": "Windows 11",
27+
"platformName": "Windows 11",
28+
"version": "100",
29+
"browserVersion": "100"
3030
}
3131
],
3232
"edge": [
3333
{
3434
"browserName": "MicrosoftEdge",
3535
"platform": "Windows 11",
3636
"platformName": "Windows 11",
37-
"version": "110",
38-
"browserVersion": "110"
37+
"version": "111",
38+
"browserVersion": "111"
3939
},
4040
{
4141
"browserName": "MicrosoftEdge",
@@ -55,8 +55,8 @@
5555
"browserName": "MicrosoftEdge",
5656
"platform": "Windows 10",
5757
"platformName": "Windows 10",
58-
"version": "101",
59-
"browserVersion": "101"
58+
"version": "100",
59+
"browserVersion": "100"
6060
}
6161
],
6262
"safari": [
@@ -77,7 +77,7 @@
7777
{
7878
"browserName": "firefox",
7979
"platform": "Windows 10",
80-
"version": "110"
80+
"version": "111"
8181
},
8282
{
8383
"browserName": "firefox",
@@ -92,7 +92,7 @@
9292
{
9393
"browserName": "firefox",
9494
"platform": "Windows 10",
95-
"version": "101"
95+
"version": "100"
9696
}
9797
],
9898
"android": [

tools/scripts/comment-pr.mjs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env node
2+
3+
/*
4+
* Copyright 2020 New Relic Corporation. All rights reserved.
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
/**
9+
* @file Adds the provided input text as a comment to a specified Github pull request, or if an optional tag string is
10+
* provided, updates an existing comment containing that tag.
11+
*/
12+
13+
import yargs from 'yargs'
14+
import { hideBin } from 'yargs/helpers'
15+
import fs from 'fs-extra'
16+
import { Octokit } from 'octokit'
17+
18+
const config = yargs(hideBin(process.argv))
19+
.usage('$0 [options]')
20+
21+
.number('p')
22+
.alias('p', 'pull-request')
23+
.describe('p', 'Numeric ID of the pull request to post a comment to')
24+
25+
.string('t')
26+
.alias('t', 'token')
27+
.describe('t', 'Github authentication token')
28+
29+
.string('i')
30+
.alias('i', 'input')
31+
.describe('i', 'Input file containing the comment contents.')
32+
33+
.string('tag')
34+
.describe('tag', 'Tag to place in the comment to support updating of comment')
35+
36+
.argv
37+
38+
;(async () => {
39+
const client = new Octokit({
40+
auth: config.token
41+
})
42+
43+
let comment
44+
// If a tag argument is passed, the script will look for an existing PR comment containing the text of the tag and
45+
// update that existing comment rather than creating a new one.
46+
if (config.tag) {
47+
for await (const { data: comments } of client.paginate.iterator(client.rest.issues.listComments, {
48+
owner: 'newrelic',
49+
repo: 'newrelic-browser-agent',
50+
issue_number: config.pullRequest
51+
})) {
52+
comment = comments.find((comment) => comment?.body?.includes(config.tag))
53+
if (comment) break
54+
}
55+
}
56+
57+
if (comment) {
58+
await client.rest.issues.updateComment({
59+
owner: 'newrelic',
60+
repo: 'newrelic-browser-agent',
61+
issue_number: config.pullRequest,
62+
comment_id: comment.id,
63+
body: (await fs.readFile(config.input)) + `\n${config.tag}`
64+
})
65+
} else {
66+
await client.rest.issues.createComment({
67+
owner: 'newrelic',
68+
repo: 'newrelic-browser-agent',
69+
issue_number: config.pullRequest,
70+
body: (await fs.readFile(config.input)) + `\n${config.tag}`
71+
})
72+
}
73+
})()

0 commit comments

Comments
 (0)