Skip to content

Commit 97e2027

Browse files
authored
chore: monitor threshold exceeded (#57)
1 parent 95c5167 commit 97e2027

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

.github/workflows/pr-bench.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ jobs:
7676
result=$(cd scripts && node ./dist/compare.js ${{ inputs.product }})
7777
echo "$result"
7878
echo "diff-result=${result//$'\n'/'@@'}" >> $GITHUB_OUTPUT
79+
if [[ $result =~ "Threshold exceeded" ]]; then
80+
echo "Some benchmark metrics exceed the threshold, please visit the previous step for more information"
81+
exit 1
82+
fi
7983
update-comment:
8084
runs-on: ubuntu-latest
8185
needs: [create-comment, run-bench]

scripts/src/compare.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { readJson } from 'fs-extra';
22
import { Metrics } from './shared/types';
3-
import { DefaultBenchCase, getMetricsPath } from './shared';
3+
import { DefaultBenchCase, getCommitLink, getMetricsPath } from './shared';
44

55
const productName = process.argv[2] || 'MODERNJS_FRAMEWORK';
66

@@ -31,6 +31,7 @@ function generateTable(
3131
base: Record<string, number>,
3232
current: Record<string, number>,
3333
) {
34+
const overThresholdTags: string[] = [];
3435
const properties = Object.keys(base);
3536

3637
const maxPropertyLength = Math.max(...properties.map(p => p.length));
@@ -58,9 +59,16 @@ function generateTable(
5859
10,
5960
)} | ${formattedPercent.padEnd(10)} |`;
6061
table.push(row);
62+
63+
if (percent > 5 && !property.includes('InstallTime')) {
64+
overThresholdTags.push(property);
65+
}
6166
});
6267

63-
return table.join('\n');
68+
console.log('');
69+
console.log(table.join('\n'));
70+
71+
return overThresholdTags;
6472
}
6573

6674
export async function compare(productName: string) {
@@ -74,10 +82,22 @@ export async function compare(productName: string) {
7482
const baseKey = keys[keys.length - 2];
7583
const current = allMetrics[currentKey as any];
7684
const base = allMetrics[baseKey as any];
85+
const baseCommitLink = getCommitLink(productName, baseKey);
86+
const currentCommitLink = getCommitLink(productName, currentKey);
7787

78-
const formatTable = generateTable(base, current);
7988
console.log(`case: ${caseName}`);
80-
console.log(formatTable);
89+
console.log('base: ', baseCommitLink);
90+
console.log('current: ', currentCommitLink);
91+
92+
const overThresholdTags = generateTable(base, current);
93+
94+
if (overThresholdTags.length > 0) {
95+
console.log('');
96+
console.log(
97+
`Threshold exceeded in ${caseName}: `,
98+
JSON.stringify(overThresholdTags),
99+
);
100+
}
81101
}
82102

83103
compare(productName);

scripts/src/shared/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ export function getRemoteDataUrl(product: string) {
6565
}`;
6666
}
6767

68+
export function getCommitLink(product: string, commitId: string) {
69+
return `https://github.com/web-infra-dev/${getRepoName(
70+
product,
71+
)}/commit/${commitId}`;
72+
}
73+
6874
export function removeHash(filename: string) {
6975
if (filename.endsWith('.js') || filename.endsWith('.css')) {
7076
const pairs = filename.split('.');

0 commit comments

Comments
 (0)