mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-23 02:11:01 +00:00
4276a04f0c
Completely switch to zerolog (Remove usage of logrus and std logger) Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: 6543 <6543@obermui.de>
33 lines
724 B
Go
33 lines
724 B
Go
package schema
|
|
|
|
import (
|
|
_ "embed"
|
|
"fmt"
|
|
|
|
"github.com/xeipuuv/gojsonschema"
|
|
|
|
"github.com/woodpecker-ci/woodpecker/shared/yml"
|
|
)
|
|
|
|
//go:embed schema.json
|
|
var schemaDefinition []byte
|
|
|
|
func Lint(file string) (error, []gojsonschema.ResultError) {
|
|
schemaLoader := gojsonschema.NewBytesLoader(schemaDefinition)
|
|
j, err := yml.LoadYmlFileAsJson(file)
|
|
if err != nil {
|
|
return fmt.Errorf("Failed to load yml file %w", err), nil
|
|
}
|
|
|
|
documentLoader := gojsonschema.NewBytesLoader(j)
|
|
result, err := gojsonschema.Validate(schemaLoader, documentLoader)
|
|
if err != nil {
|
|
return fmt.Errorf("Validation failed %w", err), nil
|
|
}
|
|
|
|
if !result.Valid() {
|
|
return fmt.Errorf("Config not valid"), result.Errors()
|
|
}
|
|
|
|
return nil, nil
|
|
}
|