memnarch/action/action.go

35 lines
703 B
Go
Raw Normal View History

package action
import (
2023-09-02 04:42:39 +00:00
"fmt"
"os"
2023-09-02 04:42:39 +00:00
"gopkg.in/yaml.v3"
)
type Action struct {
2023-09-02 04:42:39 +00:00
Build struct {
Cmd string `yaml:"cmd"`
} `yaml:"build,omitempty"`
Deploy struct {
Hosts []string `yaml:"hosts"`
Artifacts map[string][]string `yaml:"artifacts"`
Before map[string]string `yaml:"before,omitempty"`
After map[string]string `yaml:"after,omitempty"`
} `yaml:"deploy,omitempty"`
}
func Read(filename string) (*Action, error) {
2023-09-02 04:42:39 +00:00
b, err := os.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("reading action: %w", err)
}
a := Action{}
if err := yaml.Unmarshal(b, &a); err != nil {
return nil, fmt.Errorf("parsing action: %w", err)
}
return &a, nil
2023-09-02 04:42:39 +00:00
}