diff --git a/config.go b/config.go index e3ceb1e..3f67d6b 100644 --- a/config.go +++ b/config.go @@ -7,23 +7,25 @@ import ( ) type config struct { - onlyDegression bool - threshold float64 - base string - compare []string - benchCmd string - benchArgs []string - gitPath string + onlyDegression bool + failWithoutResults bool + threshold float64 + base string + compare []string + benchCmd string + benchArgs []string + gitPath string } func newConfig(c *cli.Context) config { return config{ - onlyDegression: c.Bool("only-degression"), - threshold: c.Float64("threshold"), - base: c.String("base"), - compare: strings.Split(c.String("compare"), ","), - benchCmd: c.String("bench-cmd"), - benchArgs: strings.Fields(c.String("bench-args")), - gitPath: c.String("git-path"), + onlyDegression: c.Bool("only-degression"), + failWithoutResults: c.Bool("fail-without-results"), + threshold: c.Float64("threshold"), + base: c.String("base"), + compare: strings.Split(c.String("compare"), ","), + benchCmd: c.String("bench-cmd"), + benchArgs: strings.Fields(c.String("bench-args")), + gitPath: c.String("git-path"), } } diff --git a/main.go b/main.go index 84d1d80..ddf8026 100644 --- a/main.go +++ b/main.go @@ -41,6 +41,10 @@ func main() { Name: "only-degression", Usage: "Show only benchmarks with worse score", }, + &cli.BoolFlag{ + Name: "fail-without-results", + Usage: "Exit with an error if the parsing fails", + }, &cli.Float64Flag{ Name: "threshold", Usage: "The program fails if the benchmark gets worse than the threshold", @@ -146,6 +150,15 @@ func run(c config) error { return xerrors.Errorf("failed to run a benchmark: %w", err) } + if c.failWithoutResults { + if len(prevSet) == 0 { + return xerrors.New("could not parse any benchmark results for the previous commit") + } + if len(headSet) == 0 { + return xerrors.New("could not parse any benchmark results for the current commit") + } + } + var ratios []result var rows [][]string for benchName, headBenchmarks := range headSet {