-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Expand file tree
/
Copy pathrun_workflow.java
More file actions
138 lines (122 loc) · 4.09 KB
/
run_workflow.java
File metadata and controls
138 lines (122 loc) · 4.09 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
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Stream;
/**
* Orchestrates the entire README processing workflow by running each step in sequence.
*
* Usage:
* java run-workflow.java # Run complete workflow
* java run-workflow.java [step] # Run specific step (1-5)
* java run-workflow.java [step] [input] # Run step with custom input
*/
void main(String[] args) {
try {
var startTime = System.currentTimeMillis();
if (args.length == 0) {
// Run complete workflow
runCompleteWorkflow();
} else {
// Run specific step
var step = Integer.parseInt(args[0]);
var input = args.length > 1 ? args[1] : null;
runStep(step, input);
}
var duration = System.currentTimeMillis() - startTime;
System.out.printf("Total execution time: %dms%n", duration);
} catch (Exception e) {
var errorMessage = e.getMessage();
System.err.printf("ERROR: Workflow failed: %s%n", errorMessage);
e.printStackTrace();
System.exit(1);
}
}
/**
* Runs the complete workflow
*/
void runCompleteWorkflow() throws IOException, InterruptedException {
System.out.println("Starting complete README processing workflow...\n");
// Step 1: Validate input
System.out.println("=".repeat(50));
runStep(1, null);
// Step 2: Parse projects
System.out.println("=".repeat(50));
runStep(2, null);
// Step 3: Generate stats
System.out.println("=".repeat(50));
runStep(3, null);
// Step 4: Generate tables
System.out.println("=".repeat(50));
runStep(4, null);
// Step 5: Assemble final README
System.out.println("=".repeat(50));
runStep(5, null);
// Step 6: Validate transformation
System.out.println("=".repeat(50));
runStep(6, null);
System.out.println("=".repeat(50));
System.out.println("Workflow completed successfully!");
}
/**
* Runs a specific step
*/
void runStep(int step, String input) throws IOException, InterruptedException {
var command = switch (step) {
case 1 -> buildCommand(
"step_1_validate_input.java",
input != null ? input : Constants.CONTRIBUTE_README_FILE
);
case 2 -> buildCommand(
"step_2_parse_projects.java",
input != null ? input : Constants.CONTRIBUTE_README_FILE,
Constants.TMP_DIR + "/" + Constants.PARSED_PROJECTS_FILE
);
case 3 -> buildCommand(
"step_3_generate_stats.java",
Constants.TMP_DIR + "/" + Constants.PARSED_PROJECTS_FILE,
Constants.TMP_DIR + "/" + Constants.GITHUB_STATS_FILE
);
case 4 -> buildCommand(
"step_4_generate_tables.java",
Constants.TMP_DIR + "/" + Constants.PARSED_PROJECTS_FILE,
Constants.TMP_DIR + "/" + Constants.GITHUB_STATS_FILE,
Constants.TMP_DIR + "/" + Constants.GENERATED_TABLES_FILE
);
case 5 -> buildCommand(
"step_5_assemble_readme.java",
input != null ? input : Constants.CONTRIBUTE_README_FILE,
Constants.TMP_DIR + "/" + Constants.GENERATED_TABLES_FILE,
Constants.README_FILE
);
case 6 -> buildCommand(
"step_6_validate_transformation.java",
input != null ? input : Constants.CONTRIBUTE_README_FILE,
Constants.README_FILE
);
default -> throw new IllegalArgumentException("Invalid step: %d. Must be 1-6.".formatted(step));
};
System.out.printf("Running Step %d...%n", step);
var processBuilder = new ProcessBuilder(command);
processBuilder.directory(Path.of(".").toFile());
var process = processBuilder.start();
var exitCode = process.waitFor();
if (exitCode != 0) {
throw new RuntimeException("Step %d failed with exit code: %d".formatted(step, exitCode));
}
System.out.printf("Step %d completed successfully!%n", step);
}
/**
* Builds a command array for running a script.
*/
String[] buildCommand(String scriptName, String... args) {
var baseCommand = List.of(
"java",
"--enable-preview",
"--source",
"25",
"scripts/" + scriptName
);
var allArgs = List.of(args);
return Stream.concat(baseCommand.stream(), allArgs.stream())
.toArray(String[]::new);
}