Skip to content

Commit

Permalink
[ci] Check package size for Pull Requests (#17739)
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar authored Oct 18, 2024
1 parent b34203f commit 75c9870
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 9 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/interface-check-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@ const fs = require('fs');
const interfaceDiffPath = ps.join(__dirname, '../../interface-diff.txt');
let reportContent = fs.readFileSync(interfaceDiffPath, 'utf8');

// Remove the first line that show the package size.
const firstLineEnd = reportContent.indexOf('\n');
const packageSizeIncreasePrompt = reportContent.substring(0, firstLineEnd);
reportContent = reportContent.substring(firstLineEnd + 1);
//

if (reportContent.includes('@')) {
reportContent = reportContent.split('\n').slice(3).join('\n');
reportContent = `## Interface Check Report
reportContent = `## ${packageSizeIncreasePrompt}
## Interface Check Report
\`\`\`diff
! WARNING this pull request has changed these public interfaces:
${reportContent}
\`\`\`
`;
} else {
reportContent = `## Interface Check Report
reportContent = `## ${packageSizeIncreasePrompt}
## Interface Check Report
This pull request does not change any public interfaces !`;
}

fs.writeFileSync(interfaceDiffPath, reportContent, 'utf8');
49 changes: 49 additions & 0 deletions .github/workflows/package-size-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const fs = require('fs-extra');
const ps = require('path');
const { buildEngine } = require('@cocos/ccbuild');

const engineRoot = ps.resolve(__dirname, '..', '..');
console.log(`Engine root: ${engineRoot}`);

const exportsDir = ps.join(engineRoot, 'exports');
const files = fs.readdirSync(exportsDir);
const features = [];
files.forEach(file => {
const filePath = ps.join(exportsDir, file);
const feature = ps.parse(ps.basename(filePath)).name;
features.push(feature);
});

console.log(`features: [ ${features.join(', ')} ]`);

(async () => {
const outDir = ps.join(engineRoot, 'build-cc-out');

const options = {
engine: engineRoot,
out: outDir,
platform: "WECHAT",
moduleFormat: "system",
compress: true,
split: false,
nativeCodeBundleMode: "wasm",
assetURLFormat: "runtime-resolved",
noDeprecatedFeatures: true,
sourceMap: false,
features,
loose: true,
mode: "BUILD",
flags: {
DEBUG: false,
NET_MODE: 0,
SERVER_MODE: false
},
wasmCompressionMode: 'brotli',
inlineEnum: true,
};

await fs.ensureDir(outDir);
await fs.emptyDir(outDir);

await buildEngine(options);
})();
23 changes: 23 additions & 0 deletions .github/workflows/web-interface-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:
working-directory: ./engine
run: |
npm install
if [ -e ./.github/workflows/package-size-check.js ]; then
node ./.github/workflows/package-size-check.js
fi
- name: Clear npm Cache
run: |
Expand Down Expand Up @@ -68,6 +71,7 @@ jobs:
working-directory: ./engine-HEAD
run: |
npm install
node ./.github/workflows/package-size-check.js
- uses: LouisBrunner/[email protected]
with:
Expand All @@ -77,6 +81,25 @@ jobs:
tolerance: worse
output: ./engine/interface-diff.txt

- name: Check package size
run: |
BASE_SIZE=0
if [ -d ./engine/build-cc-out ]; then
BASE_SIZE=$(du -sk ./engine/build-cc-out | awk '{print $1 * 1024}')
fi
HEAD_SIZE=$(du -sk ./engine-HEAD/build-cc-out | awk '{print $1 * 1024}')
DIFF_SIZE=$((HEAD_SIZE - BASE_SIZE))
if [ "$DIFF_SIZE" -gt 0 ]; then
PACKAGE_SIZE_INFO="📈📈📈 Package Size increased by $DIFF_SIZE bytes, OLD: $BASE_SIZE, NEW: $HEAD_SIZE"
elif [ "$DIFF_SIZE" -lt 0 ]; then
PACKAGE_SIZE_INFO="📉📉📉 Package Size decreased by $DIFF_SIZE bytes, OLD: $BASE_SIZE, NEW: $HEAD_SIZE"
else
PACKAGE_SIZE_INFO="🟢🟢🟢 Package Size is not changed, BASE: $BASE_SIZE, HEAD: $HEAD_SIZE"
fi
echo "PACKAGE_SIZE_INFO: ${PACKAGE_SIZE_INFO}"
sed -i "1s/^/$PACKAGE_SIZE_INFO\n/" ./engine/interface-diff.txt
- name: optimize interface check report
working-directory: ./engine
run: |
Expand Down
4 changes: 2 additions & 2 deletions cocos/asset/asset-manager/plist-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class PlistParser extends SAXParser {
/**
* @en parse a xml string as plist object.
* @zh 将xml字符串解析为plist对象。
* @param {String} xmlTxt - plist xml contents
* @param xmlTxt - plist xml contents
* @return {*} plist object
*/
public parse (xmlTxt): any {
public parse (xmlTxt: string): any {
const xmlDoc = this._parseXML(xmlTxt);
const plist = xmlDoc.documentElement;
if (plist.tagName !== 'plist') {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@cocos/box2d": "1.0.1",
"@cocos/cannon": "1.2.8",
"@cocos/ccbuild": "^2.2.15",
"@cocos/ccbuild": "^2.2.16",
"@cocos/dragonbones-js": "^1.0.1"
}
}

0 comments on commit 75c9870

Please sign in to comment.