Files
CLI/src/main/kotlin/commands/ci/CiCommand.kt
2026-01-22 18:14:22 +01:00

57 lines
1.7 KiB
Kotlin

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()
}
}
}