Skip to content

Commit ed71a6f

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

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
id: base-dist-size
76+
run: |
77+
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}
78+
git checkout ${{ github.base_ref }}
79+
yarn --immutable && yarn build
80+
81+
- name: Get dist files size (from base branch)
82+
id: base-dist-size
83+
run: |
84+
set -e
85+
86+
find src -mindepth 2 -path '*/assets/dist/*' \( -name "*.js" -o -name "*.css" \) -not \( -path '*/tests/*' -o -path '*/public/*' \) | sort | while read -r file; do
87+
echo "{\"$file\": {\"size\": $(wc -c < "$file"), \"size_gz\": $(gzip -c "$file" | wc -c), \"size_brotli\": $(brotli -c "$file" | wc -c)}}"
88+
done | jq -s 'add' -c
89+
90+
- name: Generate the diff
91+
id: diff
92+
uses: actions/github-script@v7
93+
env:
94+
PR_DIST_SIZE: ${{ steps.pr-dist-size.outputs.result }}
95+
BASE_DIST_SIZE: ${{ steps.base-dist-size.outputs.result }}
96+
with:
97+
script: |
98+
console.log(process.env.PR_DIST_SIZE);
99+
console.log(process.env.BASE_DIST_SIZE);
100+
101+
- name: Comment on the pull request (if any failure)
102+
if: ${{ failure() }}
103+
uses: marocchino/sticky-pull-request-comment@v2
104+
with:
105+
message: |
106+
❌ The dist files size difference could not be calculated. Please check the logs for more details.
107+
108+
- name: Comment on the pull request (if success)
109+
if: ${{ always() && steps.diff.conclusion == 'success' }}
110+
uses: marocchino/sticky-pull-request-comment@v2
111+
with:
112+
message: |
113+
```
114+
${{ steps.diff.outputs.result }}
115+
```

0 commit comments

Comments
 (0)