8000 Detect workflow event type by sosedoff · Pull Request #35 · nektos/act · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Detect workflow event type #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions actions/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,9 @@ func (runner *runnerImpl) setupWorkflows() error {
if err != nil {
return err
}

defer workflowReader.Close()

runner.workflowConfig, err = parser.Parse(workflowReader)
/*
if err != nil {
parserError := err.(*parser.ParserError)
for _, e := range parserError.Errors {
fmt.Fprintln(os.Stderr, e)
}
}
*/
return err
}

Expand Down
1 change: 1 addition & 0 deletions actions/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestRunEvent(t *testing.T) {
{"regex.workflow", "push", "exit with `NEUTRAL`: 78"},
{"gitref.workflow", "push", ""},
{"env.workflow", "push", ""},
{"detect_event.workflow", "", ""},
}
log.SetLevel(log.DebugLevel)

Expand Down
9 changes: 9 additions & 0 deletions actions/testdata/detect_event.workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
workflow "detect-event" {
on = "pull_request"
resolves = ["build"]
}

action "build" {
uses = "./action1"
args = "echo 'build'"
}
18 changes: 15 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ func setupLogging(cmd *cobra.Command, args []string) {

func newRunCommand(runnerConfig *actions.RunnerConfig) func(*cobra.Command, []string) error {
return func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
runnerConfig.EventName = "push"
} else {
if len(args) > 0 {
runnerConfig.EventName = args[0]
}

Expand All @@ -77,6 +75,20 @@ func parseAndRun(cmd *cobra.Command, runnerConfig *actions.RunnerConfig) error {
}
defer runner.Close()

// set default event type if we only have a single workflow in the file.
// this way user dont have to specify the event.
if runnerConfig.EventName == "" {
if events := runner.ListEve 5E8E nts(); len(events) == 1 {
log.Debugf("Using detected workflow event: %s", events[0])
runnerConfig.EventName = events[0]
}
}

// fall back to default event name if we could not detect one.
if runnerConfig.EventName == "" {
runnerConfig.EventName = "push"
}

// check if we should just print the graph
list, err := cmd.Flags().GetBool("list")
if err != nil {
Expand Down
0