Skip to content

Commit 4f594f2

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

File tree

1 file changed

+112
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)