|
| 1 | +name: Dist Files Size Diff |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - 'src/*/**' |
| 7 | + - '!src/*/doc/**' |
| 8 | + - '.github/**' |
| 9 | + |
| 10 | +jobs: |
| 11 | + dist-files-size-diff: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - uses: marocchino/sticky-pull-request-comment@v2 |
| 16 | + with: |
| 17 | + message: | |
| 18 | + ⏳ The dist files size difference is being calculated... |
| 19 | + |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - uses: actions/setup-node@v4 |
| 23 | + with: |
| 24 | + node-version: '22' |
| 25 | + |
| 26 | + - name: Configure git |
| 27 | + run: | |
| 28 | + git config --global user.email "" |
| 29 | + git config --global user.name "github-action[bot]" |
| 30 | +
|
| 31 | + - name: Get dist files size (from pull request) |
| 32 | + id: pr-dist-files |
| 33 | + run: | |
| 34 | + set -e |
| 35 | +
|
| 36 | + FILES=$(find src -mindepth 2 -path '*/assets/dist/*' \( -name "*.js" -o -name "*.css" \) -not \( -path '*/tests/*' -o -path '*/public/*' \) | sort | while read -r file; do |
| 37 | + echo "{\"$file\": {\"size\": $(wc -c < "$file"), \"size_gz\": $(gzip -c "$file" | wc -c), \"size_brotli\": $(brotli -c "$file" | wc -c)}}" |
| 38 | + done | jq -s 'add' -c) |
| 39 | +
|
| 40 | + echo "files=$FILES" >> $GITHUB_OUTPUT |
| 41 | +
|
| 42 | + - name: Get dist files size (from base branch) |
| 43 | + id: base-dist-files |
| 44 | + run: | |
| 45 | + set -e |
| 46 | +
|
| 47 | + git fetch origin ${{ github.base_ref }}:${{ github.base_ref }} |
| 48 | +
|
| 49 | + FILES=$(find src -mindepth 2 -path '*/assets/dist/*' \( -name "*.js" -o -name "*.css" \) -not \( -path '*/tests/*' -o -path '*/public/*' \) | sort | while read -r file; do |
| 50 | + echo "{\"$file\": {\"size\": $(wc -c < "$file"), \"size_gz\": $(gzip -c "$file" | wc -c), \"size_brotli\": $(brotli -c "$file" | wc -c)}}" |
| 51 | + done | jq -s 'add' -c) |
| 52 | +
|
| 53 | + echo "files=$FILES" >> $GITHUB_OUTPUT |
| 54 | +
|
| 55 | + - name: Generate the diff |
| 56 | + id: diff |
| 57 | + uses: actions/github-script@v7 |
| 58 | + env: |
| 59 | + PR_DIST_FILES: ${{ steps.pr-dist-files.outputs.files }} |
| 60 | + BASE_DIST_FILES: ${{ steps.base-dist-files.outputs.files }} |
| 61 | + with: |
| 62 | + result-encoding: string |
| 63 | + script: | |
| 64 | + console.log('context', context); |
| 65 | + console.log('pr', process.env.PR_DIST_FILES); |
| 66 | + console.log('base', process.env.BASE_DIST_FILES); |
| 67 | + |
| 68 | + return '<table><tr><th>a</td><th>b</td></tr><tr><td>a</td><td>b</td></tr><tr><td>a</td><td>b</td></tr><tr><td>a</td><td>b</td></tr></table>'; |
| 69 | + |
| 70 | + - name: Comment on the pull request (if any failure) |
| 71 | + if: ${{ failure() }} |
| 72 | + uses: marocchino/sticky-pull-request-comment@v2 |
| 73 | + with: |
| 74 | + message: | |
| 75 | + ❌ The dist files size difference could not be calculated. Please check the logs for more details. |
| 76 | + |
| 77 | + - name: Comment on the pull request (if success) |
| 78 | + if: ${{ always() && steps.diff.conclusion == 'success' }} |
| 79 | + uses: marocchino/sticky-pull-request-comment@v2 |
| 80 | + with: |
| 81 | + message: | |
| 82 | + ``` |
| 83 | + ${{ steps.diff.outputs.result }} |
| 84 | + ``` |
0 commit comments