@@ -41,6 +41,7 @@ import (
41
41
"github.com/compose-spec/compose-go/v2/validation"
42
42
"github.com/mitchellh/mapstructure"
43
43
"github.com/sirupsen/logrus"
44
+ "golang.org/x/exp/slices"
44
45
"gopkg.in/yaml.v3"
45
46
)
46
47
@@ -84,6 +85,15 @@ type Options struct {
84
85
Listeners []Listener
85
86
}
86
87
88
+ var versionWarning []string
89
+
90
+ func (o * Options ) warnObsoleteVersion (file string ) {
91
+ if ! slices .Contains (versionWarning , file ) {
92
+ logrus .Warning (fmt .Sprintf ("%s: `version` is obsolete" , file ))
93
+ }
94
+ versionWarning = append (versionWarning , file )
95
+ }
96
+
87
97
type Listener = func (event string , metadata map [string ]any )
88
98
89
99
// Invoke all listeners for an event
@@ -409,6 +419,10 @@ func loadYamlModel(ctx context.Context, config types.ConfigDetails, opts *Option
409
419
if err := schema .Validate (dict ); err != nil {
410
420
return fmt .Errorf ("validating %s: %w" , file .Filename , err )
411
421
}
422
+ if _ , ok := dict ["version" ]; ok {
423
+ opts .warnObsoleteVersion (file .Filename )
424
+ delete (dict , "version" )
425
+ }
412
426
}
413
427
414
428
return err
@@ -438,11 +452,6 @@ func loadYamlModel(ctx context.Context, config types.ConfigDetails, opts *Option
438
452
}
439
453
}
440
454
441
- if _ , ok := dict ["version" ]; ok {
442
- logrus .Warning ("`version` is obsolete" )
443
- delete (dict , "version" )
444
- }
445
-
446
455
dict , err = transform .Canonical (dict )
447
456
if err != nil {
448
457
return nil , err
0 commit comments