-
Notifications
You must be signed in to change notification settings - Fork 2.1k
427 lines (369 loc) · 16 KB
/
web-interface-check.yml
File metadata and controls
427 lines (369 loc) · 16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
name: <Web> Interface check
on: [pull_request]
# github.head_ref is only defined on pull_request events
concurrency:
group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
jobs:
dts-and-size:
if:
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
runs-on: ubuntu-latest
outputs:
SPINE_WASM_UP_TO_DATE_BASE: ${{ steps.check-wasm-up-to-date-base.outputs.SPINE_WASM_UP_TO_DATE_BASE }}
SPINE_WASM_UP_TO_DATE_HEAD: ${{ steps.check-wasm-up-to-date-head.outputs.SPINE_WASM_UP_TO_DATE_HEAD }}
strategy:
fail-fast: false
matrix:
config:
- { target: base }
- { target: head }
steps:
- uses: actions/setup-node@v4
with:
node-version: '18.x'
- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v14
with:
version: 3.1.41
- name: Verify
run: |
which emcc
emcc -v
- name: Install ninja
run: |
if ! command -v ninja &> /dev/null; then
echo "Ninja not found, installing..."
# sudo apt update
sudo apt install ninja-build
else
echo "Ninja is already installed."
fi
which ninja
- uses: actions/checkout@v4
name: Checkout Base Ref
if: ${{ matrix.config.target == 'base' }}
with:
repository: ${{ github.event.pull_request.base.repo.full_name }}
ref: ${{ github.base_ref }}
- uses: actions/checkout@v4
name: Checkout Head Ref for using the latest .github/workflows for base
if: ${{ matrix.config.target == 'base' }}
with:
path: './engine-HEAD'
- uses: actions/checkout@v4
name: Checkout Head Ref
if: ${{ matrix.config.target == 'head' }}
- name: Show Refs
run: |
echo "Commit log:"
git --no-pager log -3
echo "git status"
git status
- name: Apply emscripten patches (base)
if: ${{ matrix.config.target == 'base' }}
run: |
ls -l $EMSDK/upstream/emscripten/
echo "--------------------------------- Save bind.cpp ---------------------------------"
cp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp.bak
echo "--------------------------------- Apply embind bind.cpp patches ---------------------------------"
cp -f ./engine-HEAD/.github/workflows/emscripten-patches/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/
echo "--------------------------------- Apply patches DONE! ---------------------------------"
cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
- name: Apply emscripten patches (head)
if: ${{ matrix.config.target == 'head' }}
run: |
ls -l $EMSDK/upstream/emscripten/
echo "--------------------------------- Save bind.cpp ---------------------------------"
cp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp.bak
echo "--------------------------------- Apply embind bind.cpp patches ---------------------------------"
cp -f .github/workflows/emscripten-patches/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/
echo "--------------------------------- Apply patches DONE! ---------------------------------"
cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
- run: |
echo "EXT_VERSION=$(node .github/workflows/get-native-external-version.js)" >> $GITHUB_ENV
- uses: actions/checkout@v4
name: Download external
with:
repository: cocos/cocos-engine-external
path: './native/external'
ref: "${{ env.EXT_VERSION }}"
fetch-depth: 1
- name: Build Spine 3.8 WASM
run: |
cd ./native/cocos/editor-support/spine-wasm
sed -i 's/set(BUILD_WASM 0)/set(BUILD_WASM 1)/g' CMakeLists.txt
sed -i 's/set(SPINE_VERSION "4.2")/set(SPINE_VERSION "3.8")/g' CMakeLists.txt
cat CMakeLists.txt
rm -rf build-wasm
mkdir build-wasm
cd build-wasm
emcmake cmake .. -GNinja
ninja
ls -l
- name: Build Spine 3.8 ASMJS
run: |
cd ./native/cocos/editor-support/spine-wasm
sed -i 's/set(BUILD_WASM 1)/set(BUILD_WASM 0)/g' CMakeLists.txt
sed -i 's/set(SPINE_VERSION "4.2")/set(SPINE_VERSION "3.8")/g' CMakeLists.txt
cat CMakeLists.txt
rm -rf build-asmjs
mkdir build-asmjs
cd build-asmjs
emcmake cmake .. -GNinja
ninja
ls -l
- name: Copy Spine 3.8 files to external directory
run: |
SPINE_VERSION="3.8"
DIST_PATH="dist-${{ matrix.config.target }}/3.8"
mkdir -p $DIST_PATH
cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./$DIST_PATH/
cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./$DIST_PATH/spine.wasm.js
cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./$DIST_PATH/
cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./$DIST_PATH/spine.asm.js
mkdir -p ./native/external/emscripten/spine/$SPINE_VERSION
echo "-------- Before replace spine wasm -----------"
ls -l ./native/external/emscripten/spine/$SPINE_VERSION
cp -f ./$DIST_PATH/* ./native/external/emscripten/spine/$SPINE_VERSION
echo "-------- After replace spine wasm ------------"
ls -l ./native/external/emscripten/spine/$SPINE_VERSION
echo "-----------------------------------------------"
cd ./native/external
git status
- name: Build Spine 4.2 WASM
run: |
cd ./native/cocos/editor-support/spine-wasm
sed -i 's/set(BUILD_WASM 0)/set(BUILD_WASM 1)/g' CMakeLists.txt
sed -i 's/set(SPINE_VERSION "3.8")/set(SPINE_VERSION "4.2")/g' CMakeLists.txt
cat CMakeLists.txt
git status
rm -rf build-wasm
mkdir build-wasm
cd build-wasm
emcmake cmake .. -GNinja
ninja
ls -l
- name: Build Spine 4.2 ASMJS
run: |
cd ./native/cocos/editor-support/spine-wasm
sed -i 's/set(SPINE_VERSION "3.8")/set(SPINE_VERSION "4.2")/g' CMakeLists.txt
sed -i 's/set(BUILD_WASM 1)/set(BUILD_WASM 0)/g' CMakeLists.txt
cat CMakeLists.txt
git status
rm -rf build-asmjs
mkdir build-asmjs
cd build-asmjs
emcmake cmake .. -GNinja
ninja
ls -l
- name: Copy Spine 4.2 files to external directory
run: |
DIST_PATH="dist-${{ matrix.config.target }}/4.2"
mkdir -p $DIST_PATH
cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./$DIST_PATH/
cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./$DIST_PATH/spine.wasm.js
cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./$DIST_PATH/
cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./$DIST_PATH/spine.asm.js
mkdir -p ./native/external/emscripten/spine/4.2/
echo "-------- Before replace spine wasm -----------"
ls -l ./native/external/emscripten/spine/4.2/
cp -f ./$DIST_PATH/* ./native/external/emscripten/spine/4.2/
echo "-------- After replace spine wasm ------------"
ls -l ./native/external/emscripten/spine/4.2/
echo "-----------------------------------------------"
cd ./native/external
git status
- name: Check if spine wasm files are up-to-date (base)
id: check-wasm-up-to-date-base
if: ${{ matrix.config.target == 'base' }}
run: |
cd ./native/external
diff_output=$(git diff)
if [ -n "$diff_output" ]; then
echo "SPINE_WASM_UP_TO_DATE_BASE=false" >> $GITHUB_OUTPUT
else
echo "SPINE_WASM_UP_TO_DATE_BASE=true" >> $GITHUB_OUTPUT
fi
- name: Check if spine wasm files are up-to-date (head)
id: check-wasm-up-to-date-head
if: ${{ matrix.config.target == 'head' }}
run: |
cd ./native/external
diff_output=$(git diff)
if [ -n "$diff_output" ]; then
echo "SPINE_WASM_UP_TO_DATE_HEAD=false" >> $GITHUB_OUTPUT
else
echo "SPINE_WASM_UP_TO_DATE_HEAD=true" >> $GITHUB_OUTPUT
fi
- name: Upload Spine Artifact
uses: actions/upload-artifact@v4
with:
name: spine-emscripten-${{ matrix.config.target }}
path: dist-${{ matrix.config.target }}
- name: Build Declarations (base)
if: ${{ matrix.config.target == 'base' }}
run: |
ROOT_DIR=$(pwd)
npm install
cd ./engine-HEAD
npm install --ignore-scripts
# Use package-size-check.js in HEAD
node .github/workflows/package-size-check.js "$ROOT_DIR"
- name: Build Declarations (head)
if: ${{ matrix.config.target == 'head' }}
run: |
ROOT_DIR=$(pwd)
npm install
node .github/workflows/package-size-check.js "$ROOT_DIR"
- name: Pack for compare
run: |
mkdir package-for-compare
cp ./bin/.declarations/cc.d.ts ./package-for-compare
cp -r build-cc-out-2d-empty-legacy-pipline ./package-for-compare
cp -r build-cc-out-2d-legacy-pipline ./package-for-compare
cp -r build-cc-out-2d-new-pipline ./package-for-compare
cp -r build-cc-out-all ./package-for-compare
cp -r build-cc-out-all-web ./package-for-compare
- name: Upload Declarations Artifact
uses: actions/upload-artifact@v4
with:
name: package-for-compare-${{ matrix.config.target }}
path: package-for-compare
- name: Restore patches
run: |
echo "-------------------------- Restore patches ---------------------------------"
rm $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
mv $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp.bak $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
echo "-------------------------- Restore patches DONE! ---------------------------------"
cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
interface_check:
if:
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
runs-on: ubuntu-latest
needs: dts-and-size
steps:
- uses: actions/setup-node@v4
with:
node-version: '18.x'
- uses: actions/checkout@v4
- name: Download Artifacts (base)
uses: actions/download-artifact@v4
with:
name: package-for-compare-base
path: artifacts/package-for-compare-base
- name: Download Artifacts (head)
uses: actions/download-artifact@v4
with:
name: package-for-compare-head
path: artifacts/package-for-compare-head
- uses: LouisBrunner/diff-action@v2.0.0
with:
old: ./artifacts/package-for-compare-base/cc.d.ts
new: ./artifacts/package-for-compare-head/cc.d.ts
mode: addition
tolerance: worse
output: ./interface-diff.txt
- name: optimize interface check report
run: |
cat ./interface-diff.txt
node ./.github/workflows/interface-check-report.js
- name: After optimize interface check report
run: |
cat ./interface-diff.txt
- name: Check Package Size
run: |
PACKAGE_SIZE_INFO="## Code Size Check Report
| Wechat (WASM) | Before | After | Diff |
|:-:|:-:|:-:|:-:|"
BASE_SIZE=0
HEAD_SIZE=0
DIFF_SIZE=0
ICON="✅ "
reset_diff_vars() {
BASE_SIZE=0
HEAD_SIZE=0
DIFF_SIZE=0
ICON="✅ "
}
check_diff() {
ccbuild_out_folder_name="$1"
if [ -d ./artifacts/package-for-compare-base/$ccbuild_out_folder_name ]; then
BASE_SIZE=$(du -sb ./artifacts/package-for-compare-base/$ccbuild_out_folder_name | awk '{print $1}')
fi
HEAD_SIZE=$(du -sb ./artifacts/package-for-compare-head/$ccbuild_out_folder_name | awk '{print $1}')
DIFF_SIZE=$((HEAD_SIZE - BASE_SIZE))
if [ "$DIFF_SIZE" -gt 0 ]; then
ICON="⚠️ +"
elif [ "$DIFF_SIZE" -lt 0 ]; then
ICON="👍 "
else
ICON="✅ "
fi
}
# Check Wechat platform
check_diff "build-cc-out-2d-empty-legacy-pipline"
PACKAGE_SIZE_INFO=$(printf "%s\n%s\n" "${PACKAGE_SIZE_INFO}" "| 2D Empty (legacy pipeline) | $BASE_SIZE bytes | $HEAD_SIZE bytes | $ICON$DIFF_SIZE bytes |")
reset_diff_vars
check_diff "build-cc-out-2d-legacy-pipline"
PACKAGE_SIZE_INFO=$(printf "%s\n%s\n" "${PACKAGE_SIZE_INFO}" "| 2D All (legacy pipeline) | $BASE_SIZE bytes | $HEAD_SIZE bytes | $ICON$DIFF_SIZE bytes |")
reset_diff_vars
check_diff "build-cc-out-2d-new-pipline"
PACKAGE_SIZE_INFO=$(printf "%s\n%s\n" "${PACKAGE_SIZE_INFO}" "| 2D All (new pipeline) | $BASE_SIZE bytes | $HEAD_SIZE bytes | $ICON$DIFF_SIZE bytes |")
reset_diff_vars
check_diff "build-cc-out-all"
PACKAGE_SIZE_INFO=$(printf "%s\n%s\n" "${PACKAGE_SIZE_INFO}" "| (2D + 3D) All | $BASE_SIZE bytes | $HEAD_SIZE bytes | $ICON$DIFF_SIZE bytes |")
reset_diff_vars
PACKAGE_SIZE_INFO=$(printf "%s\n" "${PACKAGE_SIZE_INFO}")
# Check Web platform
WEB_PLATFORM_TABLE_HEADER="| Web (WASM + ASMJS) | Before | After | Diff |
|:-:|:-:|:-:|:-:|"
PACKAGE_SIZE_INFO=$(printf "%s\n\n\n%s\n" "${PACKAGE_SIZE_INFO}" "$WEB_PLATFORM_TABLE_HEADER")
check_diff "build-cc-out-all-web"
PACKAGE_SIZE_INFO=$(printf "%s\n%s\n" "${PACKAGE_SIZE_INFO}" "| (2D + 3D) All | $BASE_SIZE bytes | $HEAD_SIZE bytes | $ICON$DIFF_SIZE bytes |")
reset_diff_vars
printf "%s\n" "$PACKAGE_SIZE_INFO"
DIFF_FILE_PATH=./interface-diff.txt
ORIGINAL_DIFF_CONTENT=$(cat ${DIFF_FILE_PATH})
echo "Original Diff: "
printf "%s\n" "$ORIGINAL_DIFF_CONTENT"
# Use printf to avoid \n missing
printf "%s\n" "$PACKAGE_SIZE_INFO" > ${DIFF_FILE_PATH}
printf "%s\n" "$ORIGINAL_DIFF_CONTENT" >> ${DIFF_FILE_PATH}
echo "Diff after merge: "
cat ${DIFF_FILE_PATH}
- name: Write PR number to file
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
fs.writeFileSync('interface-check-pr.txt', process.env.PR_NUMBER);
- name: Upload PR number artifact
uses: actions/upload-artifact@v4
with:
name: interface-check-pr.txt
path: |
interface-check-pr.txt
- name: Upload interface diff artifact
uses: actions/upload-artifact@v4
with:
name: interface-diff.txt
path: |
./interface-diff.txt
check-wasm-up-to-date:
if:
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
runs-on: ubuntu-latest
needs: dts-and-size
steps:
- name: Check if wasm files are up-to-date (head)
run: |
if [ "${{ needs.dts-and-size.outputs.SPINE_WASM_UP_TO_DATE_HEAD }}" == "true" ]; then
echo "Spine WASM files in native/external is up-to-date."
exit 0
else
echo "Spine WASM files in native/external is not up-to-date, please update native/external-config.json"
exit 1
fi