Merge pull request #302 from zh-lx/ci/compare

feat: add comprehensive current branch vs Master comparison workflow
This commit is contained in:
zhoulixiang
2026-01-17 10:45:03 +08:00
committed by GitHub
4 changed files with 1138 additions and 11 deletions

View File

@@ -1,11 +0,0 @@
## PR 的功能
_请详细描述问题,或者贴一个 issue 链接_
## 你的预期是什么
_请详细描述,你修改代码之后的样子_
## 是否进行了详细的自测?
_是/否_

88
.github/workflows/compare.yaml vendored Normal file
View File

@@ -0,0 +1,88 @@
name: Bundle Size Comparison
on:
pull_request:
branches: [main]
types: [opened, synchronize, reopened]
push:
branches: [main]
jobs:
compare-size:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node 18
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Run comparison (size, accuracy & speed)
id: compare
run: |
echo "COMPARE_OUTPUT<<EOF" >> $GITHUB_OUTPUT
npm run compare 2>&1 | tee -a $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
continue-on-error: false
- name: Comment PR with comparison results
if: github.event_name == 'pull_request'
env:
COMPARE_OUTPUT: ${{ steps.compare.outputs.COMPARE_OUTPUT }}
uses: actions/github-script@v7
with:
script: |
const compareOutput = process.env.COMPARE_OUTPUT;
// 查找是否已有对比评论
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('📦 CDN vs Local 完整对比')
);
const timestamp = new Date().toUTCString();
const body = '## 📦 CDN vs Local 完整对比\n\n```\n' +
compareOutput +
'\n```\n\n_Updated at ' + timestamp + '_\n\n---\n💡 **提示**: 此评论会在每次推送新提交时自动更新';
if (botComment) {
// 更新现有评论
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
console.log('✅ 已更新对比评论');
} else {
// 创建新评论
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
console.log('✅ 已创建对比评论');
}
- name: Display comparison in logs
if: github.event_name == 'push'
run: npm run compare

1048
benchmark/compare.js Normal file
View File

File diff suppressed because it is too large Load Diff

View File

@@ -8,6 +8,8 @@
"scripts": {
"test": "vitest run --coverage",
"build": "rollup -c && rollup -c rollup.esm.config.js",
"build:compare": "npm run build && node benchmark/compare.js",
"compare": "node benchmark/compare.js",
"commit": "git-cz",
"lint": "eslint ."
},