diff --git a/.github/workflows/browser.yml b/.github/workflows/browser.yml index da12b51e5..1442c4a56 100644 --- a/.github/workflows/browser.yml +++ b/.github/workflows/browser.yml @@ -12,6 +12,8 @@ on: jobs: build-test-browser: + permissions: + pull-requests: write runs-on: ubuntu-latest strategy: @@ -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 diff --git a/.github/workflows/common.yml b/.github/workflows/common.yml index f2dc03e64..a64766e4c 100644 --- a/.github/workflows/common.yml +++ b/.github/workflows/common.yml @@ -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 diff --git a/.github/workflows/sdk-client.yml b/.github/workflows/sdk-client.yml index 9ac1c9ebe..2c2fbaa7b 100644 --- a/.github/workflows/sdk-client.yml +++ b/.github/workflows/sdk-client.yml @@ -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 diff --git a/actions/package-size/action.yml b/actions/package-size/action.yml new file mode 100644 index 000000000..4413259e9 --- /dev/null +++ b/actions/package-size/action.yml @@ -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