From 589ff1627177fb80d66df28477dffbc3836a507c Mon Sep 17 00:00:00 2001 From: Aidan Steele Date: Mon, 8 Apr 2019 21:01:49 +1000 Subject: [PATCH] Render correct graph for non-default events --- actions/runner.go | 4 ++-- actions/runner_test.go | 19 +++++++++++++++++++ actions/testdata/multi.workflow | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 actions/testdata/multi.workflow diff --git a/actions/runner.go b/actions/runner.go index 894d8c7..0509747 100644 --- a/actions/runner.go +++ b/actions/runner.go @@ -104,7 +104,7 @@ func (runner *runnerImpl) ListEvents() []string { // GraphEvent builds an execution path func (runner *runnerImpl) GraphEvent(eventName string) ([][]string, error) { log.Debugf("Listing actions for event '%s'", eventName) - resolves := runner.resolveEvent(runner.config.EventName) + resolves := runner.resolveEvent(eventName) return newExecutionGraph(runner.workflowConfig, resolves...), nil } @@ -140,7 +140,7 @@ func (runner *runnerImpl) Close() error { // get list of resolves for an event func (runner *runnerImpl) resolveEvent(eventName string) []string { - workflows := runner.workflowConfig.GetWorkflows(runner.config.EventName) + workflows := runner.workflowConfig.GetWorkflows(eventName) resolves := make([]string, 0) for _, workflow := range workflows { for _, resolve := range workflow.Resolves { diff --git a/actions/runner_test.go b/actions/runner_test.go index 46c969f..a637074 100644 --- a/actions/runner_test.go +++ b/actions/runner_test.go @@ -8,6 +8,25 @@ import ( "gotest.tools/assert" ) +func TestGraphEvent(t *testing.T) { + runnerConfig := &RunnerConfig{ + Ctx: context.Background(), + WorkflowPath: "multi.workflow", + WorkingDir: "testdata", + EventName: "push", + } + runner, err := NewRunner(runnerConfig) + assert.NilError(t, err) + + graph, err := runner.GraphEvent("push") + assert.NilError(t, err) + assert.DeepEqual(t, graph, [][]string{{"build"}}) + + graph, err = runner.GraphEvent("release") + assert.NilError(t, err) + assert.DeepEqual(t, graph, [][]string{{"deploy"}}) +} + func TestRunEvent(t *testing.T) { if testing.Short() { t.Skip("skipping integration test") diff --git a/actions/testdata/multi.workflow b/actions/testdata/multi.workflow new file mode 100644 index 0000000..1015fb7 --- /dev/null +++ b/actions/testdata/multi.workflow @@ -0,0 +1,19 @@ +workflow "buildwf" { + on = "push" + resolves = ["build"] +} + +action "build" { + uses = "./action1" + args = "echo 'build'" +} + +workflow "deploywf" { + on = "release" + resolves = ["deploy"] +} + +action "deploy" { + uses = "./action2" + runs = ["/bin/sh", "-c", "cat $GITHUB_EVENT_PATH"] +}