Skip to content

Commit 9e0479f

Browse files
authored
chore(ci): add size threadhold (#10934)
1 parent c3e3de0 commit 9e0479f

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

.github/actions/binary-limit/action.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: Binary Size Limit
33
description: Compare binary size with default
44

55
inputs:
6-
percentage-threshold:
7-
description: "the"
8-
default: "5"
6+
size-threshold:
7+
description: "the increase size limit in bytes, default is 50kb"
8+
default: "51200"
99
required: false
1010

1111
runs:
@@ -16,5 +16,6 @@ runs:
1616
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
1717
with:
1818
script: |
19+
const limit = parseInt("${{ inputs.size-threshold }}") || 51200;
1920
const action = require("./.github/actions/binary-limit/binary-limit-script.js");
20-
await action({github, context});
21+
await action({github, context, limit});

.github/actions/binary-limit/binary-limit-script.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ const fs = require("node:fs");
22

33
/**
44
* @param {import("@octokit/rest")} github
5+
* @param {Number} limit
56
*/
6-
module.exports = async function action({ github, context }) {
7+
module.exports = async function action({ github, context, limit }) {
78
const commits = await github.rest.repos.listCommits({
89
owner: context.repo.owner,
910
repo: context.repo.repo,
@@ -38,9 +39,19 @@ module.exports = async function action({ github, context }) {
3839
"./crates/node_binding/rspack.linux-x64-gnu.node"
3940
).size;
4041

41-
const comment = compareBinarySize(headSize, baseSize, baseCommit);
42+
console.log(`Base commit size: ${baseSize}`);
43+
console.log(`Head commit size: ${headSize}`);
44+
45+
const comment = compareBinarySize(headSize, baseSize, context, baseCommit);
4246

4347
await commentToPullRequest(github, context, comment);
48+
49+
const increasedSize = headSize - baseSize;
50+
if (increasedSize > limit) {
51+
throw new Error(
52+
`Binary size increased by ${increasedSize} bytes, exceeding the limit of ${limit} bytes`
53+
);
54+
}
4455
};
4556

4657
async function commentToPullRequest(github, context, comment) {
@@ -85,11 +96,12 @@ const SIZE_LIMIT_HEADING = "## 📦 Binary Size-limit";
8596
const DATA_URL_BASE =
8697
"https://raw.githubusercontent.com/web-infra-dev/rspack-ecosystem-benchmark/data";
8798

88-
function compareBinarySize(headSize, baseSize, baseCommit) {
99+
function compareBinarySize(headSize, baseSize, context, baseCommit) {
89100
const message = baseCommit.commit.message.split("\n")[0];
90101
const author = baseCommit.commit.author.name;
102+
const headSha = context.payload.pull_request?.head.sha || context.sha;
91103

92-
const info = `> Comparing binary size with Commit: [${message} by ${author}](${baseCommit.html_url})\n\n`;
104+
const info = `> Comparing [\`${headSha.slice(0, 7)}\`](${context.payload.repository.html_url}/commit/${headSha}) to [${message} by ${author}](${baseCommit.html_url})\n\n`;
93105

94106
const diff = headSize - baseSize;
95107
const percentage = (Math.abs(diff / baseSize) * 100).toFixed(2);

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,16 @@ jobs:
127127
test-windows,
128128
test-mac,
129129
test-wasm,
130-
check-changed
130+
check-changed,
131+
size-limit
131132
]
132133
if: ${{ always() && !cancelled() }}
133134
runs-on: ubuntu-latest
134135
steps:
135136
- name: Log
136137
run: echo ${{ join(needs.*.result, ',') }}
137138
- name: Test check
138-
if: ${{ needs.check-changed.outputs.code_changed == 'true' && join(needs.*.result, ',')!='success,success,success,success,success,success' }}
139+
if: ${{ needs.check-changed.outputs.code_changed == 'true' && join(needs.*.result, ',')!='success,success,success,success,success,success,success' }}
139140
run: echo "Tess Failed" && exit 1
140141
- name: No check to Run test
141142
run: echo "Success"

.github/workflows/size-limit.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ jobs:
5555
5656
- name: Binary Size-limit
5757
uses: ./.github/actions/binary-limit
58+
with:
59+
# 50k 50*1024
60+
size-threshold: 51200

0 commit comments

Comments
 (0)