summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCasey Lee <cplee@nektos.com>2019-02-17 02:01:36 +0100
committerGitHub <noreply@github.com>2019-02-17 02:01:36 +0100
commit7fcacaadb364a6a624094f41785359aaac955cb8 (patch)
treec21feed4c8485b84410db094eb42bcc0a2d1f086
parentMerge pull request #34 from sosedoff/regex-fix (diff)
parentAdd extra test for event detection (diff)
downloadforgejo-act-7fcacaadb364a6a624094f41785359aaac955cb8.tar.xz
forgejo-act-7fcacaadb364a6a624094f41785359aaac955cb8.zip
Merge pull request #35 from sosedoff/detect-event-type
Detect workflow event type
-rw-r--r--actions/runner.go9
-rw-r--r--actions/runner_test.go1
-rw-r--r--actions/testdata/detect_event.workflow9
-rw-r--r--cmd/root.go18
4 files changed, 25 insertions, 12 deletions
diff --git a/actions/runner.go b/actions/runner.go
index f650e67..894d8c7 100644
--- a/actions/runner.go
+++ b/actions/runner.go
@@ -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
}
diff --git a/actions/runner_test.go b/actions/runner_test.go
index aea55f1..92ef52c 100644
--- a/actions/runner_test.go
+++ b/actions/runner_test.go
@@ -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)
diff --git a/actions/testdata/detect_event.workflow b/actions/testdata/detect_event.workflow
new file mode 100644
index 0000000..a693395
--- /dev/null
+++ b/actions/testdata/detect_event.workflow
@@ -0,0 +1,9 @@
+workflow "detect-event" {
+ on = "pull_request"
+ resolves = ["build"]
+}
+
+action "build" {
+ uses = "./action1"
+ args = "echo 'build'"
+} \ No newline at end of file
diff --git a/cmd/root.go b/cmd/root.go
index 06138f7..e1dcd9c 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -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]
}
@@ -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.ListEvents(); 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 {