38 lines
754 B
Go
38 lines
754 B
Go
|
package actions
|
||
|
|
||
|
import (
|
||
|
"gopkg.in/yaml.v3"
|
||
|
"io/ioutil"
|
||
|
)
|
||
|
|
||
|
type ActionInput struct {
|
||
|
Description string `yaml:"description"`
|
||
|
Default string `yaml:"default"`
|
||
|
}
|
||
|
|
||
|
type ActionDefinition struct {
|
||
|
Name string `yaml:"name"`
|
||
|
Description string `yaml:"description"`
|
||
|
Inputs map[string]ActionInput `yaml:"inputs"`
|
||
|
Runs struct {
|
||
|
Using string `yaml:"using"`
|
||
|
Main string `yaml:"main"`
|
||
|
} `yaml:"runs"`
|
||
|
}
|
||
|
|
||
|
func GetDefinitionFromFile(defPath string) (*ActionDefinition, error) {
|
||
|
defRaw, err := ioutil.ReadFile(defPath)
|
||
|
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
var def ActionDefinition
|
||
|
|
||
|
if yamlError := yaml.Unmarshal(defRaw, &def); yamlError != nil {
|
||
|
return nil, yamlError
|
||
|
}
|
||
|
|
||
|
return &def, nil
|
||
|
}
|