Skip to content

Commit 67b8cb8

Browse files
authored
chore: Package size reports. (#642)
1 parent 6cbf4f9 commit 67b8cb8

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

.github/workflows/browser.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ on:
1212

1313
jobs:
1414
build-test-browser:
15+
permissions:
16+
pull-requests: write
1517
runs-on: ubuntu-latest
1618

1719
strategy:
@@ -31,3 +33,12 @@ jobs:
3133
with:
3234
workspace_name: '@launchdarkly/js-client-sdk'
3335
workspace_path: packages/sdk/browser
36+
- name: Check package size
37+
if: github.event_name == 'pull_request' && matrix.version == '21'
38+
uses: ./actions/package-size
39+
with:
40+
github_token: ${{ secrets.GITHUB_TOKEN }}
41+
target_file: 'packages/sdk/browser/dist/index.js'
42+
package_name: '@launchdarkly/js-client-sdk'
43+
pr_number: ${{ github.event.number }}
44+
size_limit: 21000

.github/workflows/common.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,12 @@ jobs:
2525
with:
2626
workspace_name: '@launchdarkly/js-sdk-common'
2727
workspace_path: packages/shared/common
28+
- name: Check package size
29+
if: github.event_name == 'pull_request'
30+
uses: ./actions/package-size
31+
with:
32+
github_token: ${{ secrets.GITHUB_TOKEN }}
33+
target_file: 'packages/shared/common/dist/esm/index.mjs'
34+
package_name: '@launchdarkly/js-sdk-common'
35+
pr_number: ${{ github.event.number }}
36+
size_limit: 21000

.github/workflows/sdk-client.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,12 @@ jobs:
2222
with:
2323
workspace_name: '@launchdarkly/js-client-sdk-common'
2424
workspace_path: packages/shared/sdk-client
25+
- name: Check package size
26+
if: github.event_name == 'pull_request'
27+
uses: ./actions/package-size
28+
with:
29+
github_token: ${{ secrets.GITHUB_TOKEN }}
30+
target_file: 'packages/shared/sdk-client/dist/esm/index.mjs'
31+
package_name: '@launchdarkly/js-client-sdk-common'
32+
pr_number: ${{ github.event.number }}
33+
size_limit: 20000

actions/package-size/action.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Package Size Action
2+
description: Checks that a compressed package is less than a certain size and also comments on the PR.
3+
inputs:
4+
github_token:
5+
description: 'Github token with permission to write PR comments'
6+
required: true
7+
target_file:
8+
description: 'Path to the JavaScript file to check'
9+
required: true
10+
package_name:
11+
description: 'The name of the package'
12+
required: true
13+
pr_number:
14+
description: 'The PR number'
15+
required: true
16+
size_limit:
17+
description: 'The maximum size of the library'
18+
required: true
19+
runs:
20+
using: composite
21+
steps:
22+
- name: Install Brotli
23+
shell: bash
24+
if: github.event_name == 'pull_request'
25+
run: sudo apt-get update && sudo apt-get install brotli
26+
- name: Get package size
27+
shell: bash
28+
run: |
29+
brotli ${{ inputs.target_file }}
30+
export PACK_SIZE=$(stat -c %s ${{ inputs.target_file }}.br)
31+
echo "PACK_SIZE=$PACK_SIZE" >> $GITHUB_ENV
32+
33+
- name: Find Size Comment
34+
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e
35+
id: fc
36+
with:
37+
issue-number: ${{ inputs.pr_number }}
38+
comment-author: 'github-actions[bot]'
39+
body-includes: '${{ inputs.package_name }} size report'
40+
41+
- name: Create comment
42+
if: steps.fc.outputs.comment-id == ''
43+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043
44+
with:
45+
issue-number: ${{ inputs.pr_number }}
46+
body: |
47+
${{ inputs.package_name }} size report
48+
This is the brotli compressed size of the ESM build.
49+
Size: ${{ env.PACK_SIZE }} bytes
50+
Size limit: ${{ inputs.size_limit }}
51+
52+
- name: Update comment
53+
if: steps.fc.outputs.comment-id != ''
54+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043
55+
with:
56+
comment-id: ${{ steps.fc.outputs.comment-id }}
57+
edit-mode: replace
58+
body: |
59+
${{ inputs.package_name }} size report
60+
This is the brotli compressed size of the ESM build.
61+
Size: ${{ env.PACK_SIZE }} bytes
62+
Size limit: ${{ inputs.size_limit }}
63+
64+
- name: Check package size limit
65+
shell: bash
66+
run: |
67+
[ $PACK_SIZE -le ${{ inputs.size_limit }} ] || exit 1

0 commit comments

Comments
 (0)