diff --git a/cmd/input.go b/cmd/input.go index abca42c..f4d3ae8 100644 --- a/cmd/input.go +++ b/cmd/input.go @@ -51,7 +51,7 @@ func (i *Input) Workdir() string { return i.resolve(".") } -// WorkflowsPath returns path to workflows +// WorkflowsPath returns path to workflow file(s) func (i *Input) WorkflowsPath() string { return i.resolve(i.workflowsPath) } diff --git a/cmd/root.go b/cmd/root.go index dbac7b1..8b9bfe4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -42,7 +42,7 @@ func Execute(ctx context.Context, version string) { rootCmd.Flags().BoolVarP(&input.forcePull, "pull", "p", false, "pull docker image(s) if already present") rootCmd.Flags().StringVarP(&input.eventPath, "eventpath", "e", "", "path to event JSON file") rootCmd.PersistentFlags().StringVarP(&input.actor, "actor", "a", "nektos/act", "user that triggered the event") - rootCmd.PersistentFlags().StringVarP(&input.workflowsPath, "workflows", "W", "./.github/workflows/", "path to workflow files") + rootCmd.PersistentFlags().StringVarP(&input.workflowsPath, "workflows", "W", "./.github/workflows/", "path to workflow file(s)") rootCmd.PersistentFlags().StringVarP(&input.workdir, "directory", "C", ".", "working directory") rootCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output") rootCmd.PersistentFlags().BoolVarP(&input.noOutput, "quiet", "q", false, "disable logging of output from steps") diff --git a/pkg/model/planner.go b/pkg/model/planner.go index ad4d43e..f4f2c58 100644 --- a/pkg/model/planner.go +++ b/pkg/model/planner.go @@ -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 }