Skip to content

Commit 4b118be

Browse files
committed
generate only missing history files with generate-history script
1 parent b9ab789 commit 4b118be

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

packages/aws-durable-execution-sdk-js-examples/scripts/generate-history.ts

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ async function main() {
1111

1212
parser.add_argument("--pattern", {
1313
type: "str",
14-
required: true,
1514
help: "String pattern to generate history for a specific example that matches the pattern (default: generate all examples)",
1615
});
1716

@@ -35,12 +34,19 @@ async function main() {
3534
type: "str",
3635
});
3736

37+
parser.add_argument("--only-missing", {
38+
action: "store_true",
39+
help: "Only add missing history files for the examples specified",
40+
default: true,
41+
});
42+
3843
const args = parser.parse_args();
3944

4045
const pattern = args.pattern;
4146
const logEvents = args.log;
4247
const skipTime = !args.no_skip_time;
4348
const suffix = args.suffix;
49+
const onlyMissing = args.only_missing;
4450

4551
const examples = await exampleStorage.getExamples();
4652

@@ -68,31 +74,50 @@ async function main() {
6874
await LocalDurableTestRunner.setupTestEnvironment({
6975
skipTime: skipTime,
7076
});
77+
78+
const generated: string[] = [];
7179
for (const example of filteredExamples) {
7280
if (example.path.includes("callback") || !example.durableConfig) {
7381
console.log("Skipping example", example.name);
7482
continue;
7583
}
76-
console.log(`Generating history for ${example.name}`);
84+
85+
const exampleDir = path.dirname(example.path);
86+
const exampleBaseName = path.basename(
87+
example.path,
88+
path.extname(example.path),
89+
);
90+
if (
91+
// If any .history.json file exists in this directory, don't generate a new one
92+
fs
93+
.readdirSync(exampleDir)
94+
.some(
95+
(file) =>
96+
file.startsWith(exampleBaseName) &&
97+
file.endsWith(".history.json"),
98+
) &&
99+
onlyMissing
100+
) {
101+
console.log(`History file already exists for ${example.name}`);
102+
continue;
103+
}
104+
77105
try {
106+
console.log(`Generating history for ${example.name}`);
107+
78108
const runner = new LocalDurableTestRunner({
79109
handlerFunction: (await import(example.path)).handler,
80110
});
81111
const result = await runner.run({
82112
payload: args.payload ? JSON.parse(args.payload) : undefined,
83113
});
84114

85-
const exampleDir = path.dirname(example.path);
86-
const exampleBaseName =
87-
path.basename(example.path, path.extname(example.path)) +
88-
(suffix ? `-${suffix}` : ``);
89-
90115
const historyEvents = result.getHistoryEvents();
91116

92-
const outputPath = `${exampleDir}/${exampleBaseName}.history.json`;
93-
117+
const outputPath = `${exampleDir}/${exampleBaseName + (suffix ? `-${suffix}` : "")}.history.json`;
94118
console.log(`Output: ${outputPath}`);
95119
fs.writeFileSync(outputPath, JSON.stringify(historyEvents, null, 2));
120+
generated.push(example.name);
96121

97122
if (logEvents) {
98123
console.log(
@@ -104,6 +129,9 @@ async function main() {
104129
console.log(`Error generating history for ${example.name}`, err);
105130
}
106131
}
132+
console.log(
133+
`Generated ${generated.length} history files: ${JSON.stringify(generated)}`,
134+
);
107135
} finally {
108136
await LocalDurableTestRunner.teardownTestEnvironment();
109137
}

0 commit comments

Comments
 (0)