Skip to content

Commit 1bee16e

Browse files
feat(cli): Use exit code 2 for ORT runs finishing with issues
When using the CLI in CI/CD the user want to immediately know if the run was successful or not. Therefore the CLI should return a non-zero exit code when the run finished with issues. This aligns the behavior of `osc` with the ORT CLI, that also uses exit code 2 for runs with issues. Signed-off-by: Marcel Bochtler <marcel.bochtler@bosch.com>
1 parent b6ddc05 commit 1bee16e

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

cli/src/commonMain/kotlin/OrtServerMain.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import kotlinx.coroutines.runBlocking
3434
import kotlinx.serialization.json.Json
3535

3636
import org.eclipse.apoapsis.ortserver.cli.model.OrtServerCliException
37+
import org.eclipse.apoapsis.ortserver.cli.model.RunFinishedWithIssuesException
3738
import org.eclipse.apoapsis.ortserver.cli.utils.createAuthenticatedOrtServerClient
3839
import org.eclipse.apoapsis.ortserver.cli.utils.echoError
3940
import org.eclipse.apoapsis.ortserver.cli.utils.useJsonFormat
@@ -63,6 +64,7 @@ fun main(args: Array<String>) {
6364
when (e) {
6465
is AuthenticationException -> cli.echoError("Authentication failed. Please check your credentials.")
6566
is OrtServerCliException, is OrtServerException -> cli.echoError(e.message)
67+
is RunFinishedWithIssuesException -> exitProcess(2)
6668
is CliktError -> {
6769
// The jsonFormat flag is not supported for the help message.
6870
cli.echoFormattedHelp(e)

cli/src/commonMain/kotlin/StartCommand.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import org.eclipse.apoapsis.ortserver.api.v1.model.OrtRun
5353
import org.eclipse.apoapsis.ortserver.api.v1.model.OrtRunStatus
5454
import org.eclipse.apoapsis.ortserver.cli.model.AuthenticationError
5555
import org.eclipse.apoapsis.ortserver.cli.model.CliInputException
56+
import org.eclipse.apoapsis.ortserver.cli.model.RunFinishedWithIssuesException
5657
import org.eclipse.apoapsis.ortserver.cli.model.printables.toPrintable
5758
import org.eclipse.apoapsis.ortserver.cli.utils.createAuthenticatedOrtServerClient
5859
import org.eclipse.apoapsis.ortserver.cli.utils.echoMessage
@@ -127,6 +128,10 @@ class StartCommand : SuspendingCliktCommand(name = "start") {
127128
}
128129

129130
echoMessage(ortRun.toPrintable())
131+
132+
if (ortRun.status == OrtRunStatus.FAILED || ortRun.status == OrtRunStatus.FINISHED_WITH_ISSUES) {
133+
throw RunFinishedWithIssuesException("The ORT run finished with status '${ortRun.status}'.")
134+
}
130135
}
131136

132137
private fun updateProgressBar(ortRun: OrtRun, client: OrtServerClient): OrtRun = runBlocking {

cli/src/commonMain/kotlin/model/Exceptions.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ class CliInputException(message: String, cause: Throwable? = null) : OrtServerCl
3636
*/
3737
class AuthenticationError(message: String = "Authentication required. Please run '$COMMAND_NAME auth login'.") :
3838
OrtServerCliException(message, null)
39+
40+
/**
41+
* An exception thrown when a run has been completed but issues were found.
42+
*/
43+
class RunFinishedWithIssuesException(message: String) : Exception(message)

0 commit comments

Comments
 (0)