Skip to content

Commit 391b9ca

Browse files
committed
feat: fetch commit info from gh-pages
1 parent 47f8cd5 commit 391b9ca

File tree

9 files changed

+91
-24
lines changed

9 files changed

+91
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ output_resource/
4343
.pnpm-store/
4444
modern.js
4545
cases/**/pnpm-lock.yaml
46+
./data

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Modern.js Benchmark
22

3+
## Data
4+
5+
Benchmark data is stored in the [gh-pages](https://github.com/modern-js-dev/modern-js-benchmark/tree/gh-pages) branch.
6+
37
## Cases
48

59
### mwa-minimal

data/commits-info.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"id": "192dbc7",
4+
"time": 1653555753000
5+
},
6+
{
7+
"id": "c3a31de",
8+
"time": 1653630607000
9+
}
10+
]

scripts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"dependencies": {
2020
"@types/node": "17.0.35",
2121
"@types/fs-extra": "9.0.13",
22+
"axios": "0.27.2",
2223
"execa": "5.1.1",
2324
"prettier": "2.6.2",
2425
"gzip-size": "6.0.0",

scripts/pnpm-lock.yaml

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logger from 'consola';
22
import { dev } from './runners/dev';
33
import { build } from './runners/build';
4-
import { cloneRepo } from './shared';
4+
import { cloneRepo, saveCommitInfo } from './shared';
55

66
const cases = [
77
{
@@ -29,6 +29,7 @@ async function main() {
2929
for (const runner of caseToRun.runners) {
3030
await runner(caseToRun.name);
3131
}
32+
await saveCommitInfo();
3233
} else {
3334
logger.error(`case name not found: ${currentCase}`);
3435
}

scripts/src/shared/fs.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import axios from 'axios';
12
import { join } from 'path';
23
import {
34
remove,
@@ -29,22 +30,21 @@ export async function updateFile(
2930
}
3031
}
3132

32-
export async function saveCommitInfo(id: string, time: number) {
33-
if (await pathExists(COMMITS_INFO_PATH)) {
34-
const content: Array<{ id: string; time: number }> = await readJson(
35-
COMMITS_INFO_PATH,
36-
);
33+
export async function saveCommitInfo() {
34+
const id = await getCommitId(MODERN_PATH);
35+
const time = await getCommitTime(MODERN_PATH);
36+
const response = await axios.get(
37+
'https://github.com/modern-js-dev/modern-js-benchmark/raw/gh-pages/commits-info.json',
38+
);
39+
const content: Array<{ id: string; time: number }> = response.data;
3740

38-
if (content.find(item => item.id === id)) {
39-
return;
40-
}
41-
42-
content.push({ id, time });
43-
content.sort((a, b) => a.time - b.time);
44-
await outputJson(COMMITS_INFO_PATH, content, { spaces: 2 });
45-
} else {
46-
outputJson(COMMITS_INFO_PATH, [{ id, time }]);
41+
if (content.find(item => item.id === id)) {
42+
return;
4743
}
44+
45+
content.push({ id, time });
46+
content.sort((a, b) => a.time - b.time);
47+
await outputJson(COMMITS_INFO_PATH, content, { spaces: 2 });
4848
}
4949

5050
export async function saveMetrics(metrics: Metrics) {
@@ -55,7 +55,6 @@ export async function saveMetrics(metrics: Metrics) {
5555
}
5656

5757
const commitId = await getCommitId(MODERN_PATH);
58-
const commitTime = await getCommitTime(MODERN_PATH);
5958

6059
const jsonName = `${CASE_NAME}.json`;
6160
const jsonPath = join(DATA_PATH, commitId, jsonName);
@@ -67,8 +66,6 @@ export async function saveMetrics(metrics: Metrics) {
6766
await outputJson(jsonPath, metrics, { spaces: 2 });
6867
}
6968

70-
await saveCommitInfo(commitId, commitTime);
71-
7269
logger.success(`Successfully write metrics to ${jsonName}.`);
7370
logger.log(JSON.stringify(metrics, null, 2) + '\n');
7471
}

scripts/src/shared/types.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,3 @@ export type Metrics = Partial<{
2929
yarnInstallTime: number;
3030
dependenciesCount: number;
3131
}>;
32-
33-
export type MetricsRecord = {
34-
commitId: string;
35-
commitTime: string;
36-
metrics: Metrics;
37-
};

scripts/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"module": "CommonJS",
1010
"skipLibCheck": true,
1111
"esModuleInterop": true,
12+
"isolatedModules": true,
1213
"moduleResolution": "Node",
1314
"lib": ["esnext", "dom"]
1415
},

0 commit comments

Comments
 (0)