feat: allow to pass spec inline

This allows to pass the contents from `spec` directly from `drone.yml`, for use
with autogenerated drone configurations.
This commit is contained in:
sh0rez
2019-08-14 16:19:38 +02:00
parent f92bc07dad
commit 35d6bee743
+9 -3
View File
@@ -87,10 +87,16 @@ func (p *Plugin) Exec() error {
args = append(args, "push")
if p.Config.Spec != "" {
raw, err := ioutil.ReadFile(p.Config.Spec)
var raw []byte
// if spec is not a valid file, assume inlining
if _, err := os.Stat(p.Config.Spec); os.IsNotExist(err) {
raw = []byte(p.Config.Spec)
} else { // otherwise read it
raw, err = ioutil.ReadFile(p.Config.Spec)
if err != nil {
return errors.Wrap(err, "failed to read template")
if err != nil {
return errors.Wrap(err, "failed to read template")
}
}
spec, err := template.RenderTrim(string(raw), p)