diff --git a/cmd/dump.go b/cmd/dump.go index 0fd58b02..70ff9ab1 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -84,12 +84,16 @@ var dumpCmd = &cobra.Command{ } } + if err := r.CollectCustomMetrics(); err != nil { + cmd.PrintErrf("Skip collecting custom metrics: %v\n", err) + } + if r.CountMeasured() == 0 { return errors.New("nothing could be measured") } if err := r.Validate(); err != nil { - return fmt.Errorf("validation error: %w\n", err) + return fmt.Errorf("validation error: %w", err) } cmd.Println(r.String()) return nil diff --git a/cmd/root.go b/cmd/root.go index adf5f63c..b39d0931 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -202,6 +202,10 @@ var rootCmd = &cobra.Command{ return errors.New("nothing could be measured") } + if err := r.Validate(); err != nil { + return fmt.Errorf("validation error: %w", err) + } + cmd.Println("") if err := r.Out(os.Stdout); err != nil { return err diff --git a/report/custom.go b/report/custom.go index f217c511..5529f547 100644 --- a/report/custom.go +++ b/report/custom.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/olekukonko/tablewriter" + "github.com/samber/lo" "github.com/xeipuuv/gojsonschema" ) @@ -172,6 +173,14 @@ func (s *CustomMetricSet) Validate() error { } return errs } + if len(s.Metrics) != len(lo.UniqBy(s.Metrics, func(m *CustomMetric) string { + return m.Key + })) { + return fmt.Errorf("key of metrics must be unique: %s", lo.Map(s.Metrics, func(m *CustomMetric, _ int) string { + return m.Key + })) + } + return nil } diff --git a/report/report.go b/report/report.go index 8aff140d..1d986f9b 100644 --- a/report/report.go +++ b/report/report.go @@ -474,6 +474,14 @@ func (r *Report) Validate() error { if r.Commit == "" { return fmt.Errorf("coverage report '%s' (env %s) is not set", "commit", "GITHUB_SHA") } + + if len(r.CustomMetrics) != len(lo.UniqBy(r.CustomMetrics, func(s *CustomMetricSet) string { + return s.Key + })) { + return fmt.Errorf("key of custom metrics must be unique: %s", lo.Map(r.CustomMetrics, func(s *CustomMetricSet, _ int) string { + return s.Key + })) + } return nil }