woodpecker/pipeline/schema/schema.go
Lukas 680d003a29
Add linter revive (#554)
* Add linter revive

* Add underscore to variable name to prevent shadowing

* Remove unnecessary leading underscore

* Revert changes to vendor file

* export ConfigFetcher as interface

* no 'yoda conditions'

* rename envsubst

Co-authored-by: 6543 <6543@obermui.de>
2021-12-01 14:22:06 +01:00

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) ([]gojsonschema.ResultError, error) {
schemaLoader := gojsonschema.NewBytesLoader(schemaDefinition)
j, err := yml.LoadYmlFileAsJSON(file)
if err != nil {
return nil, fmt.Errorf("Failed to load yml file %w", err)
}
documentLoader := gojsonschema.NewBytesLoader(j)
result, err := gojsonschema.Validate(schemaLoader, documentLoader)
if err != nil {
return nil, fmt.Errorf("Validation failed %w", err)
}
if !result.Valid() {
return result.Errors(), fmt.Errorf("Config not valid")
}
return nil, nil
}