-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtask.go
More file actions
45 lines (35 loc) · 773 Bytes
/
task.go
File metadata and controls
45 lines (35 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package run
import (
"fmt"
"io/ioutil"
"os"
log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2"
"github.com/run-ci/run/pkg/run"
)
// LoadTask is a helper function that reads a task from the
// filesystem and stores it in a Task struct.
func LoadTask(name string) (run.Task, error) {
pwd, err := os.Getwd()
if err != nil {
return run.Task{}, err
}
log.Debugf("looking for tasks in %v", pwd)
path := fmt.Sprintf("%v/tasks/%v.yaml", pwd, name)
f, err := ioutil.ReadFile(path)
if err != nil {
return run.Task{}, err
}
task := run.Task{Name: name}
err = yaml.UnmarshalStrict(f, &task)
if err != nil {
return task, err
}
if task.Mount == "" {
task.Mount = "/mnt/repo"
}
if task.Shell == "" {
task.Shell = "sh"
}
return task, nil
}