Skip to content

Commit ffec68d

Browse files
committed
chore: fix BENCH_ARTIFACTS to run all generation
1 parent 35ad232 commit ffec68d

2 files changed

Lines changed: 55 additions & 40 deletions

File tree

.github/workflows/bench.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ jobs:
120120
failure: 'true'
121121
result: ''
122122
123+
- name: Output Result
124+
if: ${{ success() }}
125+
uses: cloudposse/github-action-matrix-outputs-write@main
126+
with:
127+
matrix-step-name: benchmark-${{ inputs.bench-file }}
128+
matrix-key: ${{ matrix.node-version }}
129+
outputs: |-
130+
result: '${{ env.BENCH_REPORT_FILE }}'
131+
123132
- name: Add Job Summary
124133
run: |
125134
result=$(cat ./${{ env.BENCH_REPORT_FILE }})
@@ -166,7 +175,6 @@ jobs:
166175
node scripts/generate-reports.mjs
167176
env:
168177
BENCH_FILE: ${{ inputs.bench-file }}
169-
BENCH_ARTIFACTS: ${{ needs.read.outputs.result }}
170178

171179
- name: Clean temporary report folder
172180
run: rm -r ./temp-reports

scripts/write-bench-results.mjs

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,55 @@
11
import { mkdir, rename } from 'node:fs/promises';
2-
import { basename, resolve } from 'node:path';
2+
import { resolve } from 'node:path';
33
import { existAsync, rootFolder } from './utils.mjs';
4+
import { readdir } from 'node:fs/promises';
5+
6+
const artifactsDir = './temp-reports';
7+
const benchFile = process.env.BENCH_FILE;
48

59
/**
6-
* The object result with the artifacts names
7-
* The result will be a record with the possible states:
8-
*
9-
* ```js
10-
* // when is called by bench.yml
11-
* { '18.18.0': 'result-1-18.18.0-add-property.js.md' }
12-
* // when is called by watch_bench.yml
13-
* { 'add-property.js:18.18.0': 'result-1-18.18.0-add-property.js.md' }
14-
* ```
15-
*
16-
* @type {{ result: { [nodeVersion: string]: string } }}
10+
* Get all benchmark report files from the temp-reports directory
11+
* Parse the node version from the filename format: report-runid-nodeversion-benchfile.md
12+
* @returns {Promise<{ [nodeVersion: string]: string }>} Map of node version to report filename
1713
*/
18-
const benchResult = JSON.parse(process.env.BENCH_ARTIFACTS);
19-
20-
function getBenchmarkFile(key) {
21-
const filepath = process.env.BENCH_FILE || key.split(':')[0];
22-
23-
return basename(filepath, '.mjs');
24-
}
25-
26-
function getBenchmarkNodeVersion(key) {
27-
return process.env.BENCH_FILE ? key : key.split(':')[1];
14+
async function getBenchmarkFiles() {
15+
const files = await readdir(artifactsDir);
16+
const benchFiles = {};
17+
18+
for (const file of files) {
19+
// Only process files related to the current benchmark
20+
if (file.includes(benchFile)) {
21+
// Extract the node version from the filename pattern: report-runid-nodeversion-benchfile.md
22+
const parts = file.split('-');
23+
// The node version should be the third part (index 2) in the filename
24+
if (parts.length >= 3) {
25+
const nodeVersion = parts[2];
26+
benchFiles[nodeVersion] = file;
27+
}
28+
}
29+
}
30+
31+
return benchFiles;
2832
}
2933

30-
for (const key of Object.keys(benchResult.result)) {
31-
const benchFile = getBenchmarkFile(key);
32-
const nodeVersion = getBenchmarkNodeVersion(key).replace(/\./g, '_');
33-
34-
const major = nodeVersion.split('_')[0];
35-
const reportFilepath = benchResult.result[key];
36-
37-
const outputFolder = resolve(rootFolder, `./v${major}/v${nodeVersion}`);
38-
39-
const outputFolderExist = await existAsync(outputFolder);
40-
41-
if (!outputFolderExist) {
42-
await mkdir(outputFolder, {
43-
recursive: true,
44-
});
34+
async function processBenchmarks() {
35+
const benchFiles = await getBenchmarkFiles();
36+
37+
for (const nodeVersion of Object.keys(benchFiles)) {
38+
const benchmarkFile = benchFile;
39+
const reportFilepath = resolve(artifactsDir, benchFiles[nodeVersion]);
40+
41+
const normalizedNodeVersion = nodeVersion.replace(/\./g, '_');
42+
const major = normalizedNodeVersion.split('_')[0];
43+
const outputFolder = resolve(rootFolder, `./v${major}/v${normalizedNodeVersion}`);
44+
45+
if (!await existAsync(outputFolder)) {
46+
await mkdir(outputFolder, { recursive: true });
47+
}
48+
49+
const outputFilepath = resolve(outputFolder, benchmarkFile.replace('.mjs', '.md'));
50+
await rename(reportFilepath, outputFilepath);
51+
console.log(`Moved ${benchmarkFile} report for Node.js v${nodeVersion} to ${outputFilepath}`);
4552
}
46-
47-
await rename(`./temp-reports/${reportFilepath}`, `${outputFolder}/${benchFile}.md`, 'utf-8');
4853
}
54+
55+
processBenchmarks().catch(console.error);

0 commit comments

Comments
 (0)