|
| 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