1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

Change -W command to accept a single file

Currently setting workflows with the -W (--workflows) flag only accepts
a folder. It is not possible to run a single workflow.yml file.

This commit allows either a single file or a directory to be passed into
the workflows flag.
This commit is contained in:
Dylan Arbour 2020-05-26 23:29:50 -04:00
parent 2df2727f1a
commit ed64e6193c
3 changed files with 21 additions and 6 deletions

View file

@ -46,10 +46,25 @@ func (r *Run) Job() *Job {
return r.Workflow.GetJob(r.JobID)
}
// NewWorkflowPlanner will load all workflows from a directory
func NewWorkflowPlanner(dirname string) (WorkflowPlanner, error) {
log.Debugf("Loading workflows from '%s'", dirname)
files, err := ioutil.ReadDir(dirname)
// NewWorkflowPlanner will load a specific workflow or all workflows from a directory
func NewWorkflowPlanner(path string) (WorkflowPlanner, error) {
fi, err := os.Stat(path)
if err != nil {
return nil, err
}
var files []os.FileInfo
var dirname string
if fi.IsDir() {
log.Debugf("Loading workflows from '%s'", path)
dirname = path
files, err = ioutil.ReadDir(path)
} else {
log.Debugf("Loading workflow '%s'", path)
dirname, err = filepath.Abs(filepath.Dir(path))
files = []os.FileInfo{fi}
}
if err != nil {
return nil, err
}