Skip to content

Commit 3376db6

Browse files
author
ci-bot
committed
mv script
1 parent 772c225 commit 3376db6

File tree

2 files changed

+117
-31
lines changed

2 files changed

+117
-31
lines changed

.circleci/config.yml

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -382,38 +382,17 @@ jobs:
382382
| grep -v metamask)
383383
COUNT=$(printf '%s\n' "$TEST_NAMES" | wc -l | awk '{print $1}')
384384
echo "Found $COUNT enabled tests. Planning for << parameters.shards >> shard(s)."
385+
385386
# Run planner once to produce a manifest with all bins
386-
printf '%s\n' "$TEST_NAMES" | node scripts/plan-shards.js --shards << parameters.shards >> --index 0 --timings timings-current.json --manifest-out reports/shards/manifest.json --verbose > /dev/null
387-
# Generate overview and per-shard file lists
388-
node -e '
389-
const fs = require("fs");
390-
const path = require("path");
391-
const outDir = path.join("reports","shards");
392-
const m = JSON.parse(fs.readFileSync(path.join(outDir, "manifest.json"), "utf8"));
393-
const bins = Array.isArray(m.bins) ? m.bins : [];
394-
// Build known/unknown stats using timings-current.json if present
395-
const timingsPath = "timings-current.json";
396-
let known = new Set();
397-
try {
398-
const t = JSON.parse(fs.readFileSync(timingsPath, "utf8"));
399-
for (const f of (t.files||[])) if (f && f.file) known.add(String(f.file).trim());
400-
} catch(_) {}
401-
let totalTests = 0, knownCount = 0, unknownCount = 0;
402-
bins.forEach(b => {
403-
const names = (b.items||[]).map(it => typeof it === "string" ? it : (it && it.name) || it).filter(Boolean);
404-
totalTests += names.length;
405-
names.forEach(n => { if (known.has(n)) knownCount++; else unknownCount++; });
406-
});
407-
const overview = bins.map((b,i)=>({ shard:i, count:(b.items||[]).length, totalSec:Number(b.total||0) }));
408-
const lines = overview.map(o=>`#${o.shard}\tcount=${o.count}\ttotal=${o.totalSec.toFixed(2)}s`);
409-
fs.writeFileSync(path.join(outDir, "overview.txt"), lines.join("\n")+"\n");
410-
fs.writeFileSync(path.join(outDir, "overview.json"), JSON.stringify({ shards: bins.length, overview, totals: bins.map(b=>b.total), counts: bins.map(b=>(b.items||[]).length), stats: { totalTests, knownCount, unknownCount } }, null, 2));
411-
bins.forEach((b,i)=>{
412-
const names = (b.items||[]).map(it => typeof it === "string" ? it : (it && it.name) || it).filter(Boolean);
413-
fs.writeFileSync(path.join(outDir, `files-${i}.txt`), names.join("\n") + (names.length?"\n":""));
414-
});
415-
console.log("Wrote overview.txt, overview.json and files-<i>.txt to", outDir);
416-
'
387+
printf '%s\n' "$TEST_NAMES" | node scripts/plan-shards.js \
388+
--shards << parameters.shards >> \
389+
--index 0 \
390+
--timings timings-current.json \
391+
--manifest-out reports/shards/manifest.json \
392+
--verbose > /dev/null
393+
394+
# Generate overview and per-shard file lists using dedicated script
395+
node scripts/generate-shard-overview.js reports/shards timings-current.json
417396
- store_artifacts:
418397
path: ./reports/shards
419398
- store_artifacts:

scripts/generate-shard-overview.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Generate shard planning overview files from manifest.json
5+
*
6+
* Reads a manifest.json file produced by plan-shards.js and generates:
7+
* - overview.txt: Human-readable shard summary
8+
* - overview.json: JSON format with stats
9+
* - files-<i>.txt: Test file list for each shard
10+
*/
11+
12+
const fs = require('fs');
13+
const path = require('path');
14+
15+
const outDir = process.argv[2] || path.join('reports', 'shards');
16+
const timingsPath = process.argv[3] || 'timings-current.json';
17+
const manifestPath = path.join(outDir, 'manifest.json');
18+
19+
if (!fs.existsSync(manifestPath)) {
20+
console.error(`❌ Manifest file not found: ${manifestPath}`);
21+
process.exit(1);
22+
}
23+
24+
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
25+
const bins = Array.isArray(manifest.bins) ? manifest.bins : [];
26+
27+
// Build known/unknown stats using timings file if present
28+
let known = new Set();
29+
try {
30+
const timings = JSON.parse(fs.readFileSync(timingsPath, 'utf8'));
31+
for (const f of (timings.files || [])) {
32+
if (f && f.file) {
33+
known.add(String(f.file).trim());
34+
}
35+
}
36+
} catch (err) {
37+
console.warn(`⚠️ Could not load timings from ${timingsPath}: ${err.message}`);
38+
}
39+
40+
// Calculate statistics
41+
let totalTests = 0;
42+
let knownCount = 0;
43+
let unknownCount = 0;
44+
45+
bins.forEach(bin => {
46+
const names = (bin.items || [])
47+
.map(it => typeof it === 'string' ? it : (it && it.name) || it)
48+
.filter(Boolean);
49+
50+
totalTests += names.length;
51+
names.forEach(name => {
52+
if (known.has(name)) {
53+
knownCount++;
54+
} else {
55+
unknownCount++;
56+
}
57+
});
58+
});
59+
60+
// Generate overview data
61+
const overview = bins.map((bin, i) => ({
62+
shard: i,
63+
count: (bin.items || []).length,
64+
totalSec: Number(bin.total || 0)
65+
}));
66+
67+
// Write overview.txt (human-readable)
68+
const lines = overview.map(o =>
69+
`#${o.shard}\tcount=${o.count}\ttotal=${o.totalSec.toFixed(2)}s`
70+
);
71+
fs.writeFileSync(
72+
path.join(outDir, 'overview.txt'),
73+
lines.join('\n') + '\n'
74+
);
75+
76+
// Write overview.json (structured data)
77+
const overviewData = {
78+
shards: bins.length,
79+
overview,
80+
totals: bins.map(b => b.total),
81+
counts: bins.map(b => (b.items || []).length),
82+
stats: {
83+
totalTests,
84+
knownCount,
85+
unknownCount,
86+
knownPercentage: totalTests > 0 ? ((knownCount / totalTests) * 100).toFixed(1) : 0
87+
}
88+
};
89+
fs.writeFileSync(
90+
path.join(outDir, 'overview.json'),
91+
JSON.stringify(overviewData, null, 2)
92+
);
93+
94+
// Write files-<i>.txt (test list per shard)
95+
bins.forEach((bin, i) => {
96+
const names = (bin.items || [])
97+
.map(it => typeof it === 'string' ? it : (it && it.name) || it)
98+
.filter(Boolean);
99+
100+
fs.writeFileSync(
101+
path.join(outDir, `files-${i}.txt`),
102+
names.join('\n') + (names.length ? '\n' : '')
103+
);
104+
});
105+
106+
console.log(`✅ Wrote overview.txt, overview.json and ${bins.length} shard files to ${outDir}`);
107+
console.log(` Total tests: ${totalTests} (${knownCount} with timing data, ${unknownCount} unknown)`);

0 commit comments

Comments
 (0)