Skip to content

Commit f8f37f6

Browse files
committed
Add CI workflow to compute diff between files dist files
1 parent 320e635 commit f8f37f6

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
consolle.log('context', context);
65+
console.log('pr', process.env.PR_DIST_FILES);
66+
console.log('base', process.env.BASE_DIST_FILES);
67+
68+
- name: Comment on the pull request (if any failure)
69+
if: ${{ failure() }}
70+
uses: marocchino/sticky-pull-request-comment@v2
71+
with:
72+
message: |
73+
❌ The dist files size difference could not be calculated. Please check the logs for more details.
74+
75+
- name: Comment on the pull request (if success)
76+
if: ${{ always() && steps.diff.conclusion == 'success' }}
77+
uses: marocchino/sticky-pull-request-comment@v2
78+
with:
79+
message: |
80+
```
81+
${{ steps.diff.outputs.result }}
82+
```

0 commit comments

Comments
 (0)