diff options
author | Alex Savchuk <a.u.savchuk@gmail.com> | 2022-09-29 07:59:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-29 07:59:52 +0200 |
commit | 21484b5c1ecbd9e1ddb6a57debd7731a3e1fc25f (patch) | |
tree | aef2f8c2d29caf4b8b7ce89def645070f5701852 /cmd | |
parent | fix: restore the job logger setup after job cancelation (#1365) (diff) | |
download | forgejo-act-21484b5c1ecbd9e1ddb6a57debd7731a3e1fc25f.tar.xz forgejo-act-21484b5c1ecbd9e1ddb6a57debd7731a3e1fc25f.zip |
fix: show workflow info even if on.push is not defined (#1329) (#1335)v0.2.32
* fix: show workflow info even if on.push is not defined (#1329)
To fix listing of workflows in such cases list/graph filtering was split with planning.
Now act supports one of the following list (-l)/graph (-g) cases:
* show all jobs of loaded workflows: act -l
* show specific job JOBNAME: act -l -j JOBNAME
* show jobs of loaded workflows in which event EVENTNAME is set up: act -l EVENTNAME
* show jobs of loaded workflows in which first defined workflow event is set up: act -l --detect-event
For planning it supports:
* running specific job JOBNAME with triggered event determined from:
** CLI argument: act -j JOBNAME EVENTNAME
** first defined in loaded workflows event: act -j JOBNAME --detect-event
** only defined in loaded workflows event: act -j JOBNAME
** push event by default: act -j JOBNAME
* running jobs of loaded workflows in which event is set up, event is determined from:
** CLI argument: act EVENTNAME
** first defined in loaded workflows event: act --detect-event
** only defined in loaded workflows event: act
** push event by default: act
Except #1329 this PR fixes #1332, #1318
* Update docs/help
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/root.go | 104 |
1 files changed, 74 insertions, 30 deletions
diff --git a/cmd/root.go b/cmd/root.go index 646ca99..d56d2bb 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -30,7 +30,7 @@ import ( func Execute(ctx context.Context, version string) { input := new(Input) var rootCmd = &cobra.Command{ - Use: "act [event name to run]\nIf no event name passed, will default to \"on: push\"", + Use: "act [event name to run] [flags]\n\nIf no event name passed, will default to \"on: push\"\nIf actions handles only one event it will be used as default instead of \"on: push\"", Short: "Run GitHub actions locally by specifying the event name (e.g. `push`) or an action name directly.", Args: cobra.MaximumNArgs(1), RunE: newRunCommand(ctx, input), @@ -304,48 +304,92 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str return err } - // Determine the event name - var eventName string + jobID, err := cmd.Flags().GetString("job") + if err != nil { + return err + } + + // check if we should just list the workflows + list, err := cmd.Flags().GetBool("list") + if err != nil { + return err + } + + // check if we should just draw the graph + graph, err := cmd.Flags().GetBool("graph") + if err != nil { + return err + } + + // collect all events from loaded workflows events := planner.GetEvents() - if input.autodetectEvent && len(events) > 0 { - // set default event type to first event + + // plan with filtered jobs - to be used for filtering only + var filterPlan *model.Plan + + // Determine the event name to be filtered + var filterEventName string = "" + + if len(args) > 0 { + log.Debugf("Using first passed in arguments event for filtering: %s", args[0]) + filterEventName = args[0] + } else if input.autodetectEvent && len(events) > 0 && len(events[0]) > 0 { + // set default event type to first event from many available + // this way user dont have to specify the event. + log.Debugf("Using first detected workflow event for filtering: %s", events[0]) + filterEventName = events[0] + } + + if jobID != "" { + log.Debugf("Preparing plan with a job: %s", jobID) + filterPlan = planner.PlanJob(jobID) + } else if filterEventName != "" { + log.Debugf("Preparing plan for a event: %s", filterEventName) + filterPlan = planner.PlanEvent(filterEventName) + } else { + log.Debugf("Preparing plan with all jobs") + filterPlan = planner.PlanAll() + } + + if list { + return printList(filterPlan) + } + + if graph { + return drawGraph(filterPlan) + } + + // plan with triggered jobs + var plan *model.Plan + + // Determine the event name to be triggered + var eventName string + + if len(args) > 0 { + log.Debugf("Using first passed in arguments event: %s", args[0]) + eventName = args[0] + } else if len(events) == 1 && len(events[0]) > 0 { + log.Debugf("Using the only detected workflow event: %s", events[0]) + eventName = events[0] + } else if input.autodetectEvent && len(events) > 0 && len(events[0]) > 0 { + // set default event type to first event from many available // this way user dont have to specify the event. - log.Debugf("Using detected workflow event: %s", events[0]) + log.Debugf("Using first detected workflow event: %s", events[0]) eventName = events[0] } else { - if len(args) > 0 { - eventName = args[0] - } else if plan := planner.PlanEvent("push"); plan != nil { - eventName = "push" - } + log.Debugf("Using default workflow event: push") + eventName = "push" } // build the plan for this run - var plan *model.Plan - if jobID, err := cmd.Flags().GetString("job"); err != nil { - return err - } else if jobID != "" { + if jobID != "" { log.Debugf("Planning job: %s", jobID) plan = planner.PlanJob(jobID) } else { - log.Debugf("Planning event: %s", eventName) + log.Debugf("Planning jobs for event: %s", eventName) plan = planner.PlanEvent(eventName) } - // check if we should just list the workflows - if list, err := cmd.Flags().GetBool("list"); err != nil { - return err - } else if list { - return printList(plan) - } - - // check if we should just print the graph - if list, err := cmd.Flags().GetBool("graph"); err != nil { - return err - } else if list { - return drawGraph(plan) - } - // check to see if the main branch was defined defaultbranch, err := cmd.Flags().GetString("defaultbranch") if err != nil { |