Skip to content
Merged
127 changes: 127 additions & 0 deletions .github/workflows/size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Size
Comment thread
NullVoxPopuli marked this conversation as resolved.
Outdated

on:
workflow_dispatch:
inputs:
BRANCH:
description: Branch to checkout
required: false
default: 'main'
type: string
# Prevents forks / PRs from getting a GITHUB_TOKEN with write access
pull_request_target:
Comment thread
NullVoxPopuli marked this conversation as resolved.
Outdated
branches:
- main
- beta
- release
- lts-*

# https://github.com/mshick/add-pr-comment/issues/67#issuecomment-1523288799
#
# https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
permissions:
pull-requests: write
issues: write

jobs:
compare_sizes:
name: 'Compare Sizes and Comment'
runs-on: 'ubuntu-latest'

steps:
- name: '[DEBUG] Dump GitHub context'
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"

- uses: actions/checkout@v4
Comment thread
NullVoxPopuli marked this conversation as resolved.
Outdated
with:
ref: ${{ inputs.BRANCH }}
- uses: ./.github/actions/setup

- run: pnpm build
- run: sudo snap install dust

- name: "Get sizes for development outputs"
id: dev
run: |
cd dist
dust --ignore_hidden \
--reverse --apparent-size \
--filter ".+.js$" \
--no-percent-bars \
--only-file \
--full-paths > out.txt

echo 'sizes<<EOF' >> $GITHUB_OUTPUT
while IFS= read -r line; do
echo "$line" >> $GITHUB_OUTPUT
done <<< $(cat out.txt)
echo 'EOF' >> $GITHUB_OUTPUT
cat out.txt

- name: "[Main] Build"
run: |
git remote -v
git fetch origin
git checkout main
git clean -Xfd
git clean -fd
pnpm install
pnpm build

- name: "[Main] Get sizes for development outputs"
id: main-dev
run: |
cd dist
dust --ignore_hidden \
--reverse --apparent-size \
--filter ".+.js$" \
--no-percent-bars \
--only-file \
--full-paths > out.txt

echo 'sizes<<EOF' >> $GITHUB_OUTPUT
while IFS= read -r line; do
echo "$line" >> $GITHUB_OUTPUT
done <<< $(cat out.txt)
echo 'EOF' >> $GITHUB_OUTPUT
cat out.txt

#########################
# Intended Layout:
#
# | | This PR | Main |
# | Dev | x1 | y1 |
# | Prod | x2 | y2 |
#
# NOTE: we we don't have a prod build for this library
# because we currently expect non-compiler usage
# (so consumers should have terser or similar properly configured for DCE)
#
#########################
- uses: mshick/add-pr-comment@v2
with:
Comment thread
NullVoxPopuli marked this conversation as resolved.
message: |
<table><thead><tr><th></th><th>This PR</th><th>main</th></tr></thead>
<tbody>
<tr><td>Dev</td><td>

```
${{ steps.dev.outputs.sizes }}
```

</td><td>

```
${{ steps.main-dev.outputs.sizes }}
```

</td></tr>
</tbody></table>



env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}