Skip to content

Commit 5e16273

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

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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: Install tools
27+
run: |
28+
git config --global user.email ""
29+
git config --global user.name "github-action[bot]"
30+
cd .github/dist-files-size-diff
31+
npm install
32+
33+
- run: corepack enable
34+
- name: Get yarn cache directory path
35+
id: yarn-cache-dir-path
36+
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
37+
- uses: actions/cache@v4
38+
id: yarn-cache
39+
with:
40+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
41+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/package.json') }}
42+
restore-keys: |
43+
${{ runner.os }}-yarn-
44+
45+
- name: Install dependencies and build files (from pull request)
46+
run: |
47+
yarn --immutable && yarn build
48+
49+
- name: Check if dist files are built
50+
id: changes
51+
run: echo "STATUS=$(git status --porcelain)" >> $GITHUB_OUTPUT
52+
53+
- name: Changes were found
54+
if: steps.changes.outputs.STATUS != ''
55+
uses: marocchino/sticky-pull-request-comment@v2
56+
with:
57+
message: |
58+
⚠️ The dist files size cannot be calculated because we found that dist files are not up-to-date.
59+
Please make sure to build the dist files (with `yarn build`) before creating a pull request.
60+
61+
- name: Stop the workflow
62+
if: steps.changes.outputs.STATUS != ''
63+
run: exit 1
64+
65+
- name: Get dist files size (from pull request)
66+
id: pr-dist-size
67+
run: |
68+
set -e
69+
70+
find src -mindepth 2 -path '*/assets/dist/*' \( -name "*.js" -o -name "*.css" \) -not \( -path '*/tests/*' -o -path '*/public/*' \) | sort | while read -r file; do
71+
echo "{\"$file\": {\"size\": $(wc -c < "$file"), \"size_gz\": $(gzip -c "$file" | wc -c), \"size_brotli\": $(brotli -c "$file" | wc -c)}}"
72+
done | jq -s 'add' -c
73+
74+
- name: Install dependencies and build files (from reference branch)
75+
run: |
76+
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}
77+
git checkout ${{ github.base_ref }}
78+
yarn --immutable && yarn build
79+
80+
- name: Get dist files size (from base branch)
81+
id: base-dist-size
82+
run: |
83+
set -e
84+
85+
find src -mindepth 2 -path '*/assets/dist/*' \( -name "*.js" -o -name "*.css" \) -not \( -path '*/tests/*' -o -path '*/public/*' \) | sort | while read -r file; do
86+
echo "{\"$file\": {\"size\": $(wc -c < "$file"), \"size_gz\": $(gzip -c "$file" | wc -c), \"size_brotli\": $(brotli -c "$file" | wc -c)}}"
87+
done | jq -s 'add' -c
88+
89+
- name: Generate the diff
90+
id: diff
91+
uses: actions/github-script@v7
92+
env:
93+
PR_DIST_SIZE: ${{ steps.pr-dist-size.outputs.result }}
94+
BASE_DIST_SIZE: ${{ steps.base-dist-size.outputs.result }}
95+
with:
96+
script: |
97+
console.log(process.env.PR_DIST_SIZE);
98+
console.log(process.env.BASE_DIST_SIZE);
99+
100+
- name: Comment on the pull request (if any failure)
101+
if: ${{ failure() }}
102+
uses: marocchino/sticky-pull-request-comment@v2
103+
with:
104+
message: |
105+
❌ The dist files size difference could not be calculated. Please check the logs for more details.
106+
107+
- name: Comment on the pull request (if success)
108+
if: ${{ always() && steps.diff.conclusion == 'success' }}
109+
uses: marocchino/sticky-pull-request-comment@v2
110+
with:
111+
message: |
112+
```
113+
${{ steps.diff.outputs.result }}
114+
```

0 commit comments

Comments
 (0)