Skip to content

Commit bf819b6

Browse files
authored
chore: use pnpm compare (#53)
* chore: add github token * chore: use pnpm compare
1 parent c554564 commit bf819b6

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

.github/workflows/pr-bench.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@ jobs:
6767
- name: Install Dependencies
6868
run: pnpm run install:scripts
6969

70+
- name: 🚀 Run specified benchmark
71+
run: cd scripts && PR_NUMBER=${{ inputs.prNumber }} GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} pnpm start ${{ inputs.product }}
72+
7073
- id: print-results
71-
name: 🚀 Run specified benchmark and Print results
74+
name: Print results
7275
run: |
73-
result=$(cd scripts && PR_NUMBER=${{ inputs.prNumber }} pnpm start ${{ inputs.product }})
76+
result=$(cd scripts && node ./dist/compare.js ${{ inputs.product }})
7477
echo "$result"
7578
echo "diff-result=${result//$'\n'/'@@'}" >> $GITHUB_OUTPUT
7679
update-comment:

scripts/src/shared/compare.ts renamed to scripts/src/compare.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { readJson } from 'fs-extra';
2-
import { Metrics } from './types';
2+
import { Metrics } from './shared/types';
3+
import { DefaultBenchCase, getMetricsPath } from './shared';
4+
5+
const productName = process.argv[2] || 'MODERNJS_FRAMEWORK';
36

47
const formatFileSize = (size: number, target = 'KB') => {
58
if (target === 'KB') {
@@ -60,7 +63,11 @@ function generateTable(
6063
return table.join('\n');
6164
}
6265

63-
export async function compare(jsonPath: string) {
66+
export async function compare(productName: string) {
67+
const caseName =
68+
process.argv[3] ||
69+
DefaultBenchCase[productName as keyof typeof DefaultBenchCase];
70+
const { jsonPath } = await getMetricsPath(productName, caseName);
6471
const allMetrics: Metrics[] = await readJson(jsonPath);
6572
const keys = Object.keys(allMetrics);
6673
const currentKey = keys[keys.length - 1];
@@ -71,3 +78,5 @@ export async function compare(jsonPath: string) {
7178
const formatTable = generateTable(base, current);
7279
console.log(formatTable);
7380
}
81+
82+
compare(productName);

scripts/src/main.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
} from './shared';
1010
import { remove } from 'fs-extra';
1111
import { yarnInstall } from './runners/yarn-install';
12-
import { compare } from './shared/compare';
1312

1413
const productName = process.argv[2] || 'MODERNJS_FRAMEWORK';
1514
const caseName =
@@ -43,11 +42,7 @@ async function main() {
4342
console.log('failed to collect install size metrics:', err);
4443
}
4544

46-
const jsonPath = await mergeMetrics(productName, caseName);
47-
48-
if (process.env.PR_NUMBER) {
49-
await compare(jsonPath);
50-
}
45+
await mergeMetrics(productName, caseName);
5146
} else {
5247
logger.error(`Case not found: ${productName} ${caseName}`);
5348
}

scripts/src/shared/fs.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export async function updateFile(
4040
}
4141
}
4242

43-
async function getMetricsPath(productName: string, caseName: string) {
43+
export async function getMetricsPath(productName: string, caseName: string) {
4444
const jsonName = `${caseName}.json`;
4545
return {
4646
jsonName,
@@ -102,10 +102,7 @@ const cleanData = (nums: number[]) => {
102102
return nums;
103103
};
104104

105-
export async function mergeMetrics(
106-
productName: string,
107-
caseName: string,
108-
): Promise<string> {
105+
export async function mergeMetrics(productName: string, caseName: string) {
109106
const { jsonPath, jsonName, remoteURL } = await getMetricsPath(
110107
productName,
111108
caseName,
@@ -146,6 +143,4 @@ export async function mergeMetrics(
146143
await outputJson(jsonPath, allData);
147144
logger.success(`Successfully merged metrics to ${jsonName}.`);
148145
}
149-
150-
return jsonPath;
151146
}

0 commit comments

Comments
 (0)