fairsplice
Advanced tools
Comparing version 0.1.3 to 0.2.0
15
index.ts
@@ -29,2 +29,5 @@ #!/usr/bin/env bun | ||
}, | ||
out: { | ||
type: "string", | ||
}, | ||
}, | ||
@@ -57,4 +60,5 @@ strict: true, | ||
--index <index> Worker index | ||
--out <file> File to write selected test files to (newline separated) | ||
Example: fairsplice select --pattern "test_*.py" --pattern "tests*.py" --total 3 --index 1 | ||
Example: fairsplice select --pattern "test_*.py" --pattern "tests*.py" --total 3 --index 1 --out selected.txt | ||
`); | ||
@@ -72,6 +76,11 @@ process.exit(0); | ||
if (command === "save") { | ||
await save(values); | ||
await save({ from: values.from }); | ||
process.exit(0); | ||
} else if (command === "select") { | ||
await select(values); | ||
await select({ | ||
patterns: values.pattern, | ||
total: values.total, | ||
index: values.index, | ||
out: values.out, | ||
}); | ||
process.exit(0); | ||
@@ -78,0 +87,0 @@ } else { |
{ | ||
"name": "fairsplice", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"module": "index.ts", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -61,2 +61,3 @@ # Fairsplice | ||
- `--index <index>`: Index of the current worker (0-based). | ||
- `--out <file>`: File to write selected test files to (newline separated) | ||
@@ -63,0 +64,0 @@ Example: |
@@ -48,3 +48,13 @@ import { createClient } from "redis"; | ||
for (const [i, hash] of hashes.entries()) { | ||
const timings = results[i].result.map(Number); | ||
console.log(results[i]); | ||
const result = results[i]; | ||
if ( | ||
typeof result === "number" || | ||
typeof result === "string" || | ||
result?.length === 0 || | ||
!result | ||
) { | ||
continue; | ||
} | ||
const timings = Array.from(result).map(Number); | ||
const timing = average(timings); | ||
@@ -51,0 +61,0 @@ timingByHash[hash] = timing; |
@@ -5,6 +5,4 @@ import { saveTimings } from "../backend/redis"; | ||
export async function save( | ||
options: Record<string, string[] | string | boolean | undefined> | ||
) { | ||
if (!options.from) { | ||
export async function save({ from }: { from: string | undefined }) { | ||
if (!from) { | ||
console.warn( | ||
@@ -17,3 +15,3 @@ "Please provide the --from option to specify the file to read test results from" | ||
// read junit xml file | ||
const junitXmlFile = Bun.file(options.from); | ||
const junitXmlFile = Bun.file(from); | ||
const xmlString = await junitXmlFile.text(); | ||
@@ -20,0 +18,0 @@ |
@@ -7,8 +7,16 @@ import { Glob } from "bun"; | ||
export async function select( | ||
options: Record<string, string[] | string | boolean | undefined> | ||
) { | ||
if (!options.pattern || !options.total || !options.index) { | ||
export async function select({ | ||
patterns, | ||
total, | ||
index, | ||
out, | ||
}: { | ||
patterns: string[] | undefined; | ||
total: string | undefined; | ||
index: string | undefined; | ||
out: string | undefined; | ||
}) { | ||
if (!patterns || !total || !index || !out) { | ||
console.warn( | ||
"Please provide the --pattern and --total and --index options." | ||
"Please provide the --pattern and --total and --index and --out flags." | ||
); | ||
@@ -20,3 +28,3 @@ process.exit(1); | ||
const files: string[] = []; | ||
for (const pattern of options.pattern) { | ||
for (const pattern of patterns) { | ||
const glob = new Glob(pattern); | ||
@@ -47,8 +55,12 @@ files.push(...glob.scanSync()); | ||
// select files | ||
const total = parseInt(options.total, 10); | ||
const index = parseInt(options.index, 10); | ||
const totalInt = parseInt(total, 10); | ||
const indexInt = parseInt(index, 10); | ||
const [selected, estimatedTiming] = splitFiles(hashTimesMap, total); | ||
const [selected, estimatedTiming] = splitFiles(hashTimesMap, totalInt); | ||
console.log(selected[index].map((hash) => hashToFile[hash]).join(" ")); | ||
// write to file | ||
const filenames = selected[indexInt] | ||
.map((hash) => hashToFile[hash]) | ||
.join("\n"); | ||
await Bun.write(out, filenames); | ||
} |
@@ -1,4 +0,4 @@ | ||
export const REDIS_KEY_PREFIX = "fairsplice:timings:"; | ||
export const REDIS_KEY_PREFIX = "fairsplice:timings"; | ||
export const NUMBER_OF_TIMINGS_TO_KEEP = 10; | ||
export const REDIS_URL = process.env.FAIRSPLICE_REDIS_URL; | ||
export const DEFAULT_TIMING_IF_MISSING = 1000; |
29940
18
375
100