Add CiCommand.kt, CiConfig.kt, and CiRunner.kt for CI daemon implementation
All checks were successful
SteamWarCI Build successful
All checks were successful
SteamWarCI Build successful
This commit is contained in:
57
src/main/kotlin/commands/ci/CiCommand.kt
Normal file
57
src/main/kotlin/commands/ci/CiCommand.kt
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user