From 835b36cb63fa7437792847fa7cac603e2f5e0d82 Mon Sep 17 00:00:00 2001 From: Casey Lee Date: Mon, 10 Feb 2020 16:53:14 -0800 Subject: [PATCH] ci tests Signed-off-by: Casey Lee --- .github/workflows/integration/entrypoint.sh | 2 +- .golangci.yml | 4 ++-- cmd/root.go | 8 +++---- pkg/common/executor.go | 8 ++++++- pkg/common/git.go | 2 +- pkg/model/planner.go | 7 +++--- pkg/model/workflow.go | 26 +++++++++++++++++---- pkg/runner/run_context.go | 13 +++++++++-- 8 files changed, 50 insertions(+), 20 deletions(-) diff --git a/.github/workflows/integration/entrypoint.sh b/.github/workflows/integration/entrypoint.sh index e6df23fd..262d0515 100644 --- a/.github/workflows/integration/entrypoint.sh +++ b/.github/workflows/integration/entrypoint.sh @@ -1,3 +1,3 @@ #!/bin/sh set -e -go test -cover ./runner +go test -cover ./pkg/runner diff --git a/.golangci.yml b/.golangci.yml index 8b00dd95..b30b33ab 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,7 +1,7 @@ linters-settings: gocyclo: # minimal code complexity to report, 30 by default (but we recommend 10-20) - min-complexity: 10 + min-complexity: 12 gocritic: disabled-checks: - ifElseChain @@ -18,4 +18,4 @@ linters: - nakedret - prealloc - scopelint - - gocritic \ No newline at end of file + - gocritic diff --git a/cmd/root.go b/cmd/root.go index 3bde51b2..06c42e45 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -61,13 +61,11 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str var eventName string if len(args) > 0 { eventName = args[0] - } else { + } else if events := planner.GetEvents(); len(events) == 1 { // set default event type if we only have a single workflow in the file. // this way user dont have to specify the event. - if events := planner.GetEvents(); len(events) == 1 { - log.Debugf("Using detected workflow event: %s", events[0]) - eventName = events[0] - } + log.Debugf("Using detected workflow event: %s", events[0]) + eventName = events[0] } // build the plan for this run diff --git a/pkg/common/executor.go b/pkg/common/executor.go index 00025671..7023e42c 100644 --- a/pkg/common/executor.go +++ b/pkg/common/executor.go @@ -87,7 +87,13 @@ func NewParallelExecutor(executors ...Executor) Executor { errChan := make(chan error) for _, executor := range executors { - go executor.ChannelError(errChan)(ctx) + e := executor + go func() { + err := e.ChannelError(errChan)(ctx) + if err != nil { + log.Fatal(err) + } + }() } for i := 0; i < len(executors); i++ { diff --git a/pkg/common/git.go b/pkg/common/git.go index 75056801..f50a8322 100644 --- a/pkg/common/git.go +++ b/pkg/common/git.go @@ -225,7 +225,7 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) Executor { logger.Errorf("Unable to clone %v %s: %v", input.URL, refName, err) return err } - os.Chmod(input.Dir, 0755) + _ = os.Chmod(input.Dir, 0755) } w, err := r.Worktree() diff --git a/pkg/model/planner.go b/pkg/model/planner.go index fb24ddca..8a5765f8 100644 --- a/pkg/model/planner.go +++ b/pkg/model/planner.go @@ -151,11 +151,12 @@ func (p *Plan) mergeStages(stages []*Stage) { for i := 0; i < len(newStages); i++ { newStages[i] = new(Stage) if i >= len(p.Stages) { - newStages[i].Runs = append(stages[i].Runs) + newStages[i].Runs = append(newStages[i].Runs, stages[i].Runs...) } else if i >= len(stages) { - newStages[i].Runs = append(p.Stages[i].Runs) + newStages[i].Runs = append(newStages[i].Runs, p.Stages[i].Runs...) } else { - newStages[i].Runs = append(p.Stages[i].Runs, stages[i].Runs...) + newStages[i].Runs = append(newStages[i].Runs, p.Stages[i].Runs...) + newStages[i].Runs = append(newStages[i].Runs, stages[i].Runs...) } } p.Stages = newStages diff --git a/pkg/model/workflow.go b/pkg/model/workflow.go index 2cb24d87..df1df8ba 100644 --- a/pkg/model/workflow.go +++ b/pkg/model/workflow.go @@ -3,6 +3,7 @@ package model import ( "fmt" "io" + "log" "regexp" "strings" @@ -23,15 +24,24 @@ func (w *Workflow) On() []string { switch w.RawOn.Kind { case yaml.ScalarNode: var val string - w.RawOn.Decode(&val) + err := w.RawOn.Decode(&val) + if err != nil { + log.Fatal(err) + } return []string{val} case yaml.SequenceNode: var val []string - w.RawOn.Decode(&val) + err := w.RawOn.Decode(&val) + if err != nil { + log.Fatal(err) + } return val case yaml.MappingNode: var val map[string]interface{} - w.RawOn.Decode(&val) + err := w.RawOn.Decode(&val) + if err != nil { + log.Fatal(err) + } var keys []string for k := range val { keys = append(keys, k) @@ -60,11 +70,17 @@ func (j *Job) Needs() []string { switch j.RawNeeds.Kind { case yaml.ScalarNode: var val string - j.RawNeeds.Decode(&val) + err := j.RawNeeds.Decode(&val) + if err != nil { + log.Fatal(err) + } return []string{val} case yaml.SequenceNode: var val []string - j.RawNeeds.Decode(&val) + err := j.RawNeeds.Decode(&val) + if err != nil { + log.Fatal(err) + } return val } return nil diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 4fbc17e2..81a0c710 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -45,7 +45,10 @@ func (rc *RunContext) Close(ctx context.Context) error { // Executor returns a pipeline executor for all the steps in the job func (rc *RunContext) Executor() common.Executor { - rc.setupTempDir() + err := rc.setupTempDir() + if err != nil { + return common.NewErrorExecutor(err) + } steps := make([]common.Executor, 0) for i, step := range rc.Run.Job().Steps { @@ -74,7 +77,13 @@ func (rc *RunContext) setupTempDir() error { tempBase = "/tmp" } rc.Tempdir, err = ioutil.TempDir(tempBase, "act-") - os.Chmod(rc.Tempdir, 0755) + if err != nil { + return err + } + err = os.Chmod(rc.Tempdir, 0755) + if err != nil { + return err + } log.Debugf("Setup tempdir %s", rc.Tempdir) return err }