Skip to content

Commit

Permalink
fix(minor): Fail CI also for update benchmark baseline updates that f…
Browse files Browse the repository at this point in the history
…ails due to EPERM (#212)

To ensure we don't "succeed" when the benchmark throws due to permissioning errors (e.g. networking without disabling sandbox)
  • Loading branch information
hassila authored Dec 20, 2023
1 parent 645e475 commit 2d3544e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Plugins/BenchmarkCommandPlugin/BenchmarkCommandPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ import PackagePlugin
throw MyError.benchmarkThresholdImprovement
case .benchmarkJobFailed:
print("One benchmark job failed during runtime, continuing with remaining.")
case .noPermissions:
throw MyError.noPermissions
}
} else {
print("One or more benchmarks returned an unexpected return code \(status)")
Expand All @@ -379,5 +381,6 @@ import PackagePlugin
case baselineNotFound
case invalidArgument
case buildFailed
case noPermissions
}
}
1 change: 1 addition & 0 deletions Plugins/BenchmarkCommandPlugin/Command+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ enum ExitCode: Int32 {
case benchmarkJobFailed = 3
case thresholdImprovement = 4
case baselineNotFound = 5
case noPermissions = 6
}
1 change: 1 addition & 0 deletions Plugins/BenchmarkHelpGenerator/Command+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ enum ExitCode: Int32 {
case benchmarkJobFailed = 3
case thresholdImprovement = 4
case baselineNotFound = 5
case noPermissions = 6
}
3 changes: 3 additions & 0 deletions Plugins/BenchmarkTool/BenchmarkTool+Baselines.swift
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ extension BenchmarkTool {
print("")
print("swift package --allow-writing-to-package-directory benchmark baseline update")
print("")
if let operation = baselineOperation, [.compare, .check, .update].contains(operation) {
exitBenchmark(exitCode: .noPermissions)
}
} else {
print("Failed to open file \(outputPath), errno = [\(errno)]")
}
Expand Down
6 changes: 4 additions & 2 deletions Plugins/BenchmarkTool/BenchmarkTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ struct BenchmarkTool: AsyncParsableCommand {
// check what failed and react accordingly
switch exitCode {
case .benchmarkJobFailed:
if baselineOperation == .check { // We need to fail with exit code for the baseline checks such that CI fails properly
// We need to fail with exit code for the baseline checks such that CI fails properly
if let operation = baselineOperation, [.compare, .check, .update].contains(operation) {
exitBenchmark(exitCode: .thresholdRegression)
}
if let failedBenchmark {
Expand All @@ -149,7 +150,8 @@ struct BenchmarkTool: AsyncParsableCommand {
print("Likely your benchmark crashed, try running the tool in the debugger, e.g.")
print("lldb \(benchmarkExecutablePath)")
print("Or check Console.app for a backtrace if on macOS.")
if baselineOperation == .check { // We need to fail with exit code for the baseline checks such that CI fails properly
// We need to fail with exit code for the baseline checks such that CI fails properly
if let operation = baselineOperation, [.compare, .check, .update].contains(operation) {
exitBenchmark(exitCode: .thresholdRegression)
}
}
Expand Down
1 change: 1 addition & 0 deletions Plugins/BenchmarkTool/Command+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ enum ExitCode: Int32 {
case benchmarkJobFailed = 3
case thresholdImprovement = 4
case baselineNotFound = 5
case noPermissions = 6
}

0 comments on commit 2d3544e

Please sign in to comment.