Skip to content

Commit

Permalink
chore: Package size reports. (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinyoklion authored Oct 30, 2024
1 parent 6cbf4f9 commit 67b8cb8
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/browser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ on:

jobs:
build-test-browser:
permissions:
pull-requests: write
runs-on: ubuntu-latest

strategy:
Expand All @@ -31,3 +33,12 @@ jobs:
with:
workspace_name: '@launchdarkly/js-client-sdk'
workspace_path: packages/sdk/browser
- name: Check package size
if: github.event_name == 'pull_request' && matrix.version == '21'
uses: ./actions/package-size
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
target_file: 'packages/sdk/browser/dist/index.js'
package_name: '@launchdarkly/js-client-sdk'
pr_number: ${{ github.event.number }}
size_limit: 21000
9 changes: 9 additions & 0 deletions .github/workflows/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ jobs:
with:
workspace_name: '@launchdarkly/js-sdk-common'
workspace_path: packages/shared/common
- name: Check package size
if: github.event_name == 'pull_request'
uses: ./actions/package-size
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
target_file: 'packages/shared/common/dist/esm/index.mjs'
package_name: '@launchdarkly/js-sdk-common'
pr_number: ${{ github.event.number }}
size_limit: 21000
9 changes: 9 additions & 0 deletions .github/workflows/sdk-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ jobs:
with:
workspace_name: '@launchdarkly/js-client-sdk-common'
workspace_path: packages/shared/sdk-client
- name: Check package size
if: github.event_name == 'pull_request'
uses: ./actions/package-size
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
target_file: 'packages/shared/sdk-client/dist/esm/index.mjs'
package_name: '@launchdarkly/js-client-sdk-common'
pr_number: ${{ github.event.number }}
size_limit: 20000
67 changes: 67 additions & 0 deletions actions/package-size/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Package Size Action
description: Checks that a compressed package is less than a certain size and also comments on the PR.
inputs:
github_token:
description: 'Github token with permission to write PR comments'
required: true
target_file:
description: 'Path to the JavaScript file to check'
required: true
package_name:
description: 'The name of the package'
required: true
pr_number:
description: 'The PR number'
required: true
size_limit:
description: 'The maximum size of the library'
required: true
runs:
using: composite
steps:
- name: Install Brotli
shell: bash
if: github.event_name == 'pull_request'
run: sudo apt-get update && sudo apt-get install brotli
- name: Get package size
shell: bash
run: |
brotli ${{ inputs.target_file }}
export PACK_SIZE=$(stat -c %s ${{ inputs.target_file }}.br)
echo "PACK_SIZE=$PACK_SIZE" >> $GITHUB_ENV
- name: Find Size Comment
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e
id: fc
with:
issue-number: ${{ inputs.pr_number }}
comment-author: 'github-actions[bot]'
body-includes: '${{ inputs.package_name }} size report'

- name: Create comment
if: steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043
with:
issue-number: ${{ inputs.pr_number }}
body: |
${{ inputs.package_name }} size report
This is the brotli compressed size of the ESM build.
Size: ${{ env.PACK_SIZE }} bytes
Size limit: ${{ inputs.size_limit }}
- name: Update comment
if: steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
${{ inputs.package_name }} size report
This is the brotli compressed size of the ESM build.
Size: ${{ env.PACK_SIZE }} bytes
Size limit: ${{ inputs.size_limit }}
- name: Check package size limit
shell: bash
run: |
[ $PACK_SIZE -le ${{ inputs.size_limit }} ] || exit 1

0 comments on commit 67b8cb8

Please sign in to comment.