mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-03-20 03:46:09 +08:00
Closes #25 Reviewed-on: https://gitea.com/actions-oss/act-cli/pulls/30 Co-authored-by: Christopher Homberger <christopher.homberger@web.de> Co-committed-by: Christopher Homberger <christopher.homberger@web.de>
39 lines
828 B
Go
39 lines
828 B
Go
package model
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
func resolveAliasesExt(node *yaml.Node, path map[*yaml.Node]bool, skipCheck bool) error {
|
|
if !skipCheck && path[node] {
|
|
return errors.New("circular alias")
|
|
}
|
|
switch node.Kind {
|
|
case yaml.AliasNode:
|
|
aliasTarget := node.Alias
|
|
if aliasTarget == nil {
|
|
return errors.New("unresolved alias node")
|
|
}
|
|
path[node] = true
|
|
*node = *aliasTarget
|
|
if err := resolveAliasesExt(node, path, true); err != nil {
|
|
return err
|
|
}
|
|
delete(path, node)
|
|
|
|
case yaml.DocumentNode, yaml.MappingNode, yaml.SequenceNode:
|
|
for _, child := range node.Content {
|
|
if err := resolveAliasesExt(child, path, false); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func resolveAliases(node *yaml.Node) error {
|
|
return resolveAliasesExt(node, map[*yaml.Node]bool{}, false)
|
|
}
|