Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Package size reports. #642

Merged
merged 20 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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