Merge pull request #259 from arbourd/set-single-workflow

Change -W command to accept a single file
This commit is contained in:
Casey Lee 2020-05-27 07:35:59 -07:00 committed by GitHub
commit 39667011b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 6 deletions

View file

@ -51,7 +51,7 @@ func (i *Input) Workdir() string {
return i.resolve(".") return i.resolve(".")
} }
// WorkflowsPath returns path to workflows // WorkflowsPath returns path to workflow file(s)
func (i *Input) WorkflowsPath() string { func (i *Input) WorkflowsPath() string {
return i.resolve(i.workflowsPath) return i.resolve(i.workflowsPath)
} }

View file

@ -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().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.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.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().StringVarP(&input.workdir, "directory", "C", ".", "working directory")
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output") rootCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output")
rootCmd.PersistentFlags().BoolVarP(&input.noOutput, "quiet", "q", false, "disable logging of output from steps") rootCmd.PersistentFlags().BoolVarP(&input.noOutput, "quiet", "q", false, "disable logging of output from steps")

View file

@ -46,10 +46,25 @@ func (r *Run) Job() *Job {
return r.Workflow.GetJob(r.JobID) return r.Workflow.GetJob(r.JobID)
} }
// NewWorkflowPlanner will load all workflows from a directory // NewWorkflowPlanner will load a specific workflow or all workflows from a directory
func NewWorkflowPlanner(dirname string) (WorkflowPlanner, error) { func NewWorkflowPlanner(path string) (WorkflowPlanner, error) {
log.Debugf("Loading workflows from '%s'", dirname) fi, err := os.Stat(path)
files, err := ioutil.ReadDir(dirname) 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 { if err != nil {
return nil, err return nil, err
} }