Add CiCommand.kt, CiConfig.kt, and CiRunner.kt for CI daemon implementation
All checks were successful
SteamWarCI Build successful

This commit is contained in:
2026-01-22 18:14:22 +01:00
parent f098a482a3
commit bad8d762e4
5 changed files with 376 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
package de.steamwar.commands.ci
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import java.io.File
import java.io.PrintStream
import kotlin.concurrent.thread
class CiCommand : CliktCommand("ci") {
override val hiddenFromHelp = true
override fun help(context: Context): String = "CI daemon for processing git push events"
override fun run() {
echo("SteamWar CI daemon started. Waiting for push events...")
echo("Format: <oldref> <newref> <branch>")
try {
while (true) {
val input = readlnOrNull() ?: break
val parts = input.split(" ")
if (parts.size < 3) {
echo("Invalid input format. Expected: <oldref> <newref> <branch>", err = true)
continue
}
val (oldref, newref, branch) = parts
// Fork/detach the build process
thread(isDaemon = false) {
processBuild(oldref, newref, branch)
}
}
} catch (e: Exception) {
echo("CI daemon error: ${e.message}", err = true)
}
}
private fun processBuild(oldref: String, newref: String, branch: String) {
try {
val config = CiConfig(oldref, newref, branch)
// Create log file
val logFile = File(config.logpath)
logFile.parentFile?.mkdirs()
PrintStream(logFile).use { logStream ->
val runner = CiRunner(config)
runner.run(logStream)
}
} catch (e: Exception) {
System.err.println("Build failed: ${e.message}")
e.printStackTrace()
}
}
}