Skip to content

Commit 31141b5

Browse files
committed
Move package-size to a shared action.
1 parent 521e393 commit 31141b5

File tree

2 files changed

+69
-45
lines changed

2 files changed

+69
-45
lines changed

.github/workflows/browser.yml

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -33,50 +33,11 @@ jobs:
3333
with:
3434
workspace_name: '@launchdarkly/js-client-sdk'
3535
workspace_path: packages/sdk/browser
36-
- name: Install Brotli
37-
if: github.event_name == 'pull_request'
38-
run: sudo apt-get update && sudo apt-get install brotli
39-
- name: Get package size
36+
- name: Check package size
4037
if: github.event_name == 'pull_request' && matrix.version == '21'
41-
env:
42-
PR_NUMBER: ${{ github.event.number }}
43-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44-
run: |
45-
brotli packages/sdk/browser/dist/index.js
46-
export PACK_SIZE=$(stat -c %s packages/sdk/browser/dist/index.js.br)
47-
echo "PACK_SIZE=$PACK_SIZE" >> $GITHUB_ENV
48-
49-
- name: Find Size Comment
50-
if: github.event_name == 'pull_request' && matrix.version == '21'
51-
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e
52-
id: fc
53-
with:
54-
issue-number: ${{ github.event.number }}
55-
comment-author: 'github-actions[bot]'
56-
body-includes: '@launchdarkly/js-client-sdk size report'
57-
58-
- name: Create comment
59-
if: steps.fc.outputs.comment-id == '' && github.event_name == 'pull_request' && matrix.version == '21'
60-
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043
38+
uses: ./actions/package-size
6139
with:
62-
issue-number: ${{ github.event.number }}
63-
body: |
64-
@launchdarkly/js-client-sdk size report
65-
This is the brotli compressed size of the ESM build.
66-
Size: ${{ env.PACK_SIZE }} bytes
67-
68-
- name: Update comment
69-
if: steps.fc.outputs.comment-id != '' && github.event_name == 'pull_request' && matrix.version == '21'
70-
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043
71-
with:
72-
comment-id: ${{ steps.fc.outputs.comment-id }}
73-
edit-mode: replace
74-
body: |
75-
@launchdarkly/js-client-sdk size report
76-
This is the brotli compressed size of the ESM build.
77-
Size: ${{ env.PACK_SIZE }} bytes
78-
79-
- name: Check package size limit
80-
if: github.event_name == 'pull_request' && matrix.version == '21'
81-
run: |
82-
[ $PACK_SIZE -le 25000 ] || exit 1
40+
github_token: ${{ secrets.GITHUB_TOKEN }}
41+
target_file: 'packages/sdk/browser/dist/index.js'
42+
package_name: '@launchdarkly/js-client-sdk'
43+
pr_numer: ${{ github.event.number }}

actions/package-size/action.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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_numer:
14+
description: 'Th PR number'
15+
required: true
16+
runs:
17+
using: composite
18+
steps:
19+
- name: Install Brotli
20+
shell: bash
21+
if: github.event_name == 'pull_request'
22+
run: sudo apt-get update && sudo apt-get install brotli
23+
- name: Get package size
24+
shell: bash
25+
run: |
26+
brotli ${{ inputs.target_file }}
27+
export PACK_SIZE=$(stat -c %s ${{ inputs.target_file }}.br)
28+
echo "PACK_SIZE=$PACK_SIZE" >> $GITHUB_ENV
29+
30+
- name: Find Size Comment
31+
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e
32+
id: fc
33+
with:
34+
issue-number: ${{ inputs.pr_number }}
35+
comment-author: 'github-actions[bot]'
36+
body-includes: '${{ inputs.package_name }} report'
37+
38+
- name: Create comment
39+
if: steps.fc.outputs.comment-id == '' && github.event_name == 'pull_request' && matrix.version == '21'
40+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043
41+
with:
42+
issue-number: ${{ inputs.pr_number }}
43+
body: |
44+
${{ inputs.package_name }} report
45+
This is the brotli compressed size of the ESM build.
46+
Size: ${{ env.PACK_SIZE }} bytes
47+
48+
- name: Update comment
49+
if: steps.fc.outputs.comment-id != '' && github.event_name == 'pull_request' && matrix.version == '21'
50+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043
51+
with:
52+
comment-id: ${{ steps.fc.outputs.comment-id }}
53+
edit-mode: replace
54+
body: |
55+
${{ inputs.package_name }} report
56+
This is the brotli compressed size of the ESM build.
57+
Size: ${{ env.PACK_SIZE }} bytes
58+
59+
- name: Check package size limit
60+
shell: bash
61+
if: github.event_name == 'pull_request' && matrix.version == '21'
62+
run: |
63+
[ $PACK_SIZE -le 25000 ] || exit 1

0 commit comments

Comments
 (0)