Run CI orchestration and setup as Java 25 source programs
Some checks failed
Build, test and publish / verify (push) Failing after 11s
Some checks failed
Build, test and publish / verify (push) Failing after 11s
This commit is contained in:
54
ci/Ci.java
Normal file
54
ci/Ci.java
Normal file
@@ -0,0 +1,54 @@
|
||||
import java.nio.file.*;
|
||||
import java.time.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
/** Run from the repository root with JDK 25: java ci/Ci.java <command>. */
|
||||
public class Ci {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
if (Runtime.version().feature() < 25) throw new IllegalArgumentException("JDK 25 or newer is required");
|
||||
if (args.length == 0) throw new IllegalArgumentException(usage());
|
||||
var env = new HashMap<>(System.getenv());
|
||||
Path root = Path.of("").toAbsolutePath();
|
||||
var commands = new Commands(Duration.ofMinutes(args[0].equals("publish") ? 15 : 75));
|
||||
switch (args[0]) {
|
||||
case "verify", "publish", "cleanup" -> {
|
||||
var pipeline = new Pipeline(root, env, commands);
|
||||
switch (args[0]) {
|
||||
case "verify" -> pipeline.verify();
|
||||
case "publish" -> pipeline.publish();
|
||||
default -> pipeline.cleanup();
|
||||
}
|
||||
}
|
||||
case "attempt" -> {
|
||||
Path file = Path.of(Setup.required(env, "GITHUB_ENV"));
|
||||
String id = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSSSSSSSS")
|
||||
.withZone(ZoneOffset.UTC).format(Instant.now());
|
||||
Files.writeString(file, "CI_RUN_ATTEMPT=" + id + "\n", StandardOpenOption.APPEND);
|
||||
}
|
||||
case "configure-gitea" -> Setup.configureGitea(env);
|
||||
case "configure-docker" -> {
|
||||
if (args.length != 2) throw new IllegalArgumentException("Supply the daemon.json path");
|
||||
Setup.configureDocker(Path.of(args[1]));
|
||||
}
|
||||
case "install-runner" -> Setup.installRunner(root, env, commands,
|
||||
args.length == 2 && args[1].equals("--prepare-only"));
|
||||
case "test" -> CiTests.run();
|
||||
default -> throw new IllegalArgumentException(usage());
|
||||
}
|
||||
} catch (Commands.Failure e) {
|
||||
System.err.println(e.getMessage());
|
||||
System.exit(e.exitCode);
|
||||
} catch (Exception e) {
|
||||
// Never dump HTTP bodies, process arguments, environment or tokens.
|
||||
System.err.println(e instanceof IllegalArgumentException || e instanceof Setup.ApiFailure ? e.getMessage()
|
||||
: "CI failed (" + e.getClass().getSimpleName() + "). Check diagnostics and configuration.");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static String usage() {
|
||||
return "Usage: java ci/Ci.java verify|publish|cleanup|attempt|test|configure-gitea|configure-docker <path>|install-runner [--prepare-only]";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user