Repository navigation
Expand file tree
/
Copy pathindex.ts
More file actions
executable file
·150 lines (132 loc) · 3.71 KB
/
Copy pathindex.ts
File metadata and controls
executable file
·150 lines (132 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env bun
import { convert } from "./src/commands/convert";
import { merge } from "./src/commands/merge";
import { split } from "./src/commands/split";
import { parseArgs } from "util";
const { positionals, values } = parseArgs({
args: Bun.argv,
options: {
help: {
type: "boolean",
short: "h",
},
// convert options
from: {
type: "string",
},
to: {
type: "string",
},
["path-prefix"]: {
type: "string",
},
// merge options
["timings-file"]: {
type: "string",
},
prefix: {
type: "string",
},
// split options
pattern: {
type: "string",
multiple: true,
},
total: {
type: "string",
},
["replace-from"]: {
type: "string",
multiple: true,
},
["replace-to"]: {
type: "string",
multiple: true,
},
out: {
type: "string",
},
},
strict: true,
allowPositionals: true,
});
const command = positionals[2];
if (values.help || !command) {
console.log(`
Usage: fairsplice [split|convert|merge] [options]
fairsplice split
----------------
Split test files across workers based on historical timings.
Required options:
--timings-file <file> JSON file with stored timings
--pattern <pattern> Pattern to match test files (can be used multiple times)
--total <total> Total number of workers
--out <file> File to write split result to (JSON)
Optional:
--replace-from <string> Substring to replace in file paths (can be used multiple times)
--replace-to <string> Replacement string (must match number of --replace-from)
Example: fairsplice split --timings-file timings.json --pattern "test_*.py" --total 3 --out split.json
fairsplice convert
------------------
Convert JUnit XML to timing JSON (for a single worker).
Required options:
--from <file> JUnit XML file to read
--to <file> Timing JSON file to write
Optional:
--path-prefix <prefix> Prefix to prepend to all file paths (e.g., "src/tests/")
Example: fairsplice convert --from junit.xml --to timing.json --path-prefix "frontends/apps/e2e/"
fairsplice merge
----------------
Merge timing JSON files and save to timings history.
Required options:
--timings-file <file> JSON file to store timing history
--prefix <prefix> Prefix to match timing JSON files
Example: fairsplice merge --timings-file timings.json --prefix timing-
`);
process.exit(0);
}
if (command === "split") {
if (
!values["timings-file"] ||
!values.pattern ||
!values.total ||
!values.out
) {
console.error(
"Error: --timings-file, --pattern, --total, and --out are required for the split command."
);
process.exit(1);
}
await split({
patterns: values.pattern,
total: values.total,
out: values.out,
replaceFrom: values["replace-from"],
replaceTo: values["replace-to"],
timingsFile: values["timings-file"],
});
process.exit(0);
} else if (command === "convert") {
if (!values.from || !values.to) {
console.error(
"Error: --from and --to are required for the convert command."
);
process.exit(1);
}
await convert({ from: values.from, to: values.to, pathPrefix: values["path-prefix"] });
process.exit(0);
} else if (command === "merge") {
if (!values["timings-file"] || !values.prefix) {
console.error(
"Error: --timings-file and --prefix are required for the merge command."
);
process.exit(1);
}
await merge({ prefix: values.prefix, timingsFile: values["timings-file"] });
process.exit(0);
} else {
console.error(
`Invalid command "${command}". Available commands: split, convert, merge.`
);
process.exit(1);
}