forked from tscircuit/snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from nocodeventure-nl/259
259
- Loading branch information
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
name: Size | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- synchronize | ||
- reopened | ||
branches: | ||
- main | ||
|
||
permissions: | ||
pull-requests: write | ||
jobs: | ||
size: | ||
name: Report bundle size | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
|
||
steps: | ||
- name: Checkout base branch | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.base_ref }} | ||
|
||
- name: Setup Bun | ||
uses: oven-sh/setup-bun@v1 | ||
with: | ||
bun-version: latest | ||
|
||
- name: Install dependencies (base) | ||
run: bun install | ||
|
||
- name: Build (base) | ||
run: bun run build | ||
|
||
- name: Get base bundle size breakdown | ||
id: base-size | ||
run: | | ||
echo "total=$(du -sh dist | cut -f1)" >> $GITHUB_OUTPUT | ||
echo "breakdown<<EOF" >> $GITHUB_OUTPUT | ||
find dist -type f -name "*.js" -o -name "*.css" | while read file; do | ||
echo "$(du -sh $file | cut -f1) - $(basename $file)" | ||
done >> $GITHUB_OUTPUT | ||
echo "EOF" >> $GITHUB_OUTPUT | ||
- name: Checkout PR branch | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install dependencies (PR) | ||
run: bun install | ||
|
||
- name: Build (PR) | ||
run: bun run build | ||
|
||
- name: Get PR bundle size breakdown | ||
id: pr-size | ||
run: | | ||
echo "total=$(du -sh dist | cut -f1)" >> $GITHUB_OUTPUT | ||
echo "breakdown<<EOF" >> $GITHUB_OUTPUT | ||
find dist -type f -name "*.js" -o -name "*.css" | while read file; do | ||
echo "$(du -sh $file | cut -f1) - $(basename $file)" | ||
done >> $GITHUB_OUTPUT | ||
echo "EOF" >> $GITHUB_OUTPUT | ||
- name: Calculate size difference | ||
id: size-diff | ||
run: | | ||
base_size=$(echo ${{ steps.base-size.outputs.total }} | sed 's/[^0-9.]*//g') | ||
pr_size=$(echo ${{ steps.pr-size.outputs.total }} | sed 's/[^0-9.]*//g') | ||
diff=$(echo "$pr_size - $base_size" | bc) | ||
if (( $(echo "$diff > 0" | bc -l) )); then | ||
echo "total=+$diff" >> $GITHUB_OUTPUT | ||
else | ||
echo "total=$diff" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Update comment | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
header: Bundle Size Report | ||
message: | | ||
## Bundle Size Report | ||
### Total Size | ||
- Base branch: ${{ steps.base-size.outputs.total }} | ||
- PR branch: ${{ steps.pr-size.outputs.total }} | ||
- Difference: ${{ steps.size-diff.outputs.total }}MB | ||
### Base Branch Breakdown | ||
``` | ||
${{ steps.base-size.outputs.breakdown }} | ||
``` | ||
### PR Branch Breakdown | ||
``` | ||
${{ steps.pr-size.outputs.breakdown }} | ||
``` |