Skip to content

Commit db2d33b

Browse files
authored
chore: add monitor metrics ci (#58)
1 parent 97e2027 commit db2d33b

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Monitor Metrics
2+
3+
on:
4+
# schedule:
5+
# - cron: '0 21 * * *'
6+
workflow_dispatch:
7+
8+
jobs:
9+
monitor:
10+
strategy:
11+
matrix:
12+
include:
13+
- product: MODERNJS_FRAMEWORK
14+
- product: MODERNJS_MODULE
15+
- product: RSPRESS
16+
- product: RSBUILD
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 1
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v3
26+
with:
27+
node-version: 16
28+
cache-dependency-path: pnpm-lock.yaml
29+
30+
- name: Install Pnpm
31+
run: corepack enable && pnpm -v && pnpm store path
32+
33+
- name: Install Dependencies
34+
run: pnpm run install:scripts
35+
36+
- name: Build Scripts
37+
run: cd scripts && pnpm run build
38+
39+
- name: Monitor Metrics
40+
run: |
41+
result=$(cd scripts && MONITOR=1 node ./dist/compare.js ${{ matrix.product }})
42+
echo "$result"
43+
echo "diff-result=${result//$'\n'/'@@'}" >> $GITHUB_OUTPUT
44+
if [[ $result =~ "Threshold exceeded" ]]; then
45+
echo "Some benchmark metrics exceed the threshold, please visit the previous step for more information"
46+
exit 1
47+
fi

scripts/src/compare.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import axios from 'axios';
12
import { readJson } from 'fs-extra';
23
import { Metrics } from './shared/types';
34
import { DefaultBenchCase, getCommitLink, getMetricsPath } from './shared';
@@ -75,8 +76,11 @@ export async function compare(productName: string) {
7576
const caseName =
7677
process.argv[3] ||
7778
DefaultBenchCase[productName as keyof typeof DefaultBenchCase];
78-
const { jsonPath } = await getMetricsPath(productName, caseName);
79-
const allMetrics: Metrics[] = await readJson(jsonPath);
79+
const { jsonPath, remoteURL } = await getMetricsPath(productName, caseName);
80+
const allMetrics: Metrics[] =
81+
process.env.MONITOR === '1'
82+
? (await axios.get(remoteURL)).data
83+
: await readJson(jsonPath);
8084
const keys = Object.keys(allMetrics);
8185
const currentKey = keys[keys.length - 1];
8286
const baseKey = keys[keys.length - 2];

0 commit comments

Comments
 (0)