1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-10-10 19:32:04 +00:00

fix: schema validation must accept aliases and merges (#1012)

- aliases are an indirection to follow
  https://yaml.org/spec/1.2.1/#id2785586
- merges cannot be conveniently validated and are skipped
  https://yaml.org/type/merge.html

Resolves forgejo/runner#1011

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1012): <!--number 1012 --><!--line 0 --><!--description Zml4OiBzY2hlbWEgdmFsaWRhdGlvbiBtdXN0IGFjY2VwdCBhbGlhc2VzIGFuZCBtZXJnZXM=-->fix: schema validation must accept aliases and merges<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1012
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
Earl Warren 2025-09-18 07:19:44 +00:00 committed by earl-warren
parent 797e0cd250
commit b8ab05e367
No known key found for this signature in database
GPG key ID: F128CBE6AB3A7201
2 changed files with 48 additions and 0 deletions

View file

@ -237,6 +237,9 @@ func (s *Node) UnmarshalYAML(node *yaml.Node) error {
if node != nil && node.Kind == yaml.DocumentNode {
return s.UnmarshalYAML(node.Content[0])
}
if node != nil && node.Kind == yaml.AliasNode {
return s.UnmarshalYAML(node.Alias)
}
def := s.Schema.GetDefinition(s.Definition)
if s.Context == nil {
s.Context = def.Context
@ -360,6 +363,15 @@ func (s *Node) checkMapping(node *yaml.Node, def Definition) error {
if node.Kind != yaml.MappingNode {
return fmt.Errorf("%sExpected a mapping got %v", formatLocation(node), getStringKind(node.Kind))
}
// merges cannot be conveniently validated and are skipped
// https://yaml.org/type/merge.html
for i, n := range node.Content {
if i%2 == 0 {
if n.Kind == yaml.ScalarNode && n.Value == "<<" && (n.Tag == "" || n.ShortTag() == "!!merge") {
return nil
}
}
}
insertDirective := regexp.MustCompile(`\${{\s*insert\s*}}`)
var allErrors error
for i, k := range node.Content {