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 {
2023-09-17 05:23:59 +00:00
Hosts map[string]string `yaml:"hosts"`
2023-09-02 04:42:39 +00:00
Artifacts map[string][]string `yaml:"artifacts"`
2023-09-17 05:23:59 +00:00
Before map[string][]string `yaml:"before,omitempty"`
After map[string][]string `yaml:"after,omitempty"`
2023-09-02 04:42:39 +00:00
} `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
}