Avoid using log.Fatal
in pkg/*
(#1705)
* fix: common * fix: in runner * fix: decodeNode * fix: GetMatrixes * Revert "fix: common" This reverts commit 6599803b6ae3b7adc168ef41b4afd4d89fc22f34. * fix: GetOutboundIP * test: fix cases --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
50dcc57e4b
commit
816a7d410a
4 changed files with 53 additions and 32 deletions
|
@ -248,15 +248,13 @@ func (j *Job) Container() *ContainerSpec {
|
||||||
switch j.RawContainer.Kind {
|
switch j.RawContainer.Kind {
|
||||||
case yaml.ScalarNode:
|
case yaml.ScalarNode:
|
||||||
val = new(ContainerSpec)
|
val = new(ContainerSpec)
|
||||||
err := j.RawContainer.Decode(&val.Image)
|
if !decodeNode(j.RawContainer, &val.Image) {
|
||||||
if err != nil {
|
return nil
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
case yaml.MappingNode:
|
case yaml.MappingNode:
|
||||||
val = new(ContainerSpec)
|
val = new(ContainerSpec)
|
||||||
err := j.RawContainer.Decode(val)
|
if !decodeNode(j.RawContainer, val) {
|
||||||
if err != nil {
|
return nil
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return val
|
return val
|
||||||
|
@ -267,16 +265,14 @@ func (j *Job) Needs() []string {
|
||||||
switch j.RawNeeds.Kind {
|
switch j.RawNeeds.Kind {
|
||||||
case yaml.ScalarNode:
|
case yaml.ScalarNode:
|
||||||
var val string
|
var val string
|
||||||
err := j.RawNeeds.Decode(&val)
|
if !decodeNode(j.RawNeeds, &val) {
|
||||||
if err != nil {
|
return nil
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
return []string{val}
|
return []string{val}
|
||||||
case yaml.SequenceNode:
|
case yaml.SequenceNode:
|
||||||
var val []string
|
var val []string
|
||||||
err := j.RawNeeds.Decode(&val)
|
if !decodeNode(j.RawNeeds, &val) {
|
||||||
if err != nil {
|
return nil
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
@ -288,16 +284,14 @@ func (j *Job) RunsOn() []string {
|
||||||
switch j.RawRunsOn.Kind {
|
switch j.RawRunsOn.Kind {
|
||||||
case yaml.ScalarNode:
|
case yaml.ScalarNode:
|
||||||
var val string
|
var val string
|
||||||
err := j.RawRunsOn.Decode(&val)
|
if !decodeNode(j.RawRunsOn, &val) {
|
||||||
if err != nil {
|
return nil
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
return []string{val}
|
return []string{val}
|
||||||
case yaml.SequenceNode:
|
case yaml.SequenceNode:
|
||||||
var val []string
|
var val []string
|
||||||
err := j.RawRunsOn.Decode(&val)
|
if !decodeNode(j.RawRunsOn, &val) {
|
||||||
if err != nil {
|
return nil
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
@ -307,8 +301,8 @@ func (j *Job) RunsOn() []string {
|
||||||
func environment(yml yaml.Node) map[string]string {
|
func environment(yml yaml.Node) map[string]string {
|
||||||
env := make(map[string]string)
|
env := make(map[string]string)
|
||||||
if yml.Kind == yaml.MappingNode {
|
if yml.Kind == yaml.MappingNode {
|
||||||
if err := yml.Decode(&env); err != nil {
|
if !decodeNode(yml, &env) {
|
||||||
log.Fatal(err)
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return env
|
return env
|
||||||
|
@ -323,8 +317,8 @@ func (j *Job) Environment() map[string]string {
|
||||||
func (j *Job) Matrix() map[string][]interface{} {
|
func (j *Job) Matrix() map[string][]interface{} {
|
||||||
if j.Strategy.RawMatrix.Kind == yaml.MappingNode {
|
if j.Strategy.RawMatrix.Kind == yaml.MappingNode {
|
||||||
var val map[string][]interface{}
|
var val map[string][]interface{}
|
||||||
if err := j.Strategy.RawMatrix.Decode(&val); err != nil {
|
if !decodeNode(j.Strategy.RawMatrix, &val) {
|
||||||
log.Fatal(err)
|
return nil
|
||||||
}
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
@ -335,7 +329,7 @@ func (j *Job) Matrix() map[string][]interface{} {
|
||||||
// It skips includes and hard fails excludes for non-existing keys
|
// It skips includes and hard fails excludes for non-existing keys
|
||||||
//
|
//
|
||||||
//nolint:gocyclo
|
//nolint:gocyclo
|
||||||
func (j *Job) GetMatrixes() []map[string]interface{} {
|
func (j *Job) GetMatrixes() ([]map[string]interface{}, error) {
|
||||||
matrixes := make([]map[string]interface{}, 0)
|
matrixes := make([]map[string]interface{}, 0)
|
||||||
if j.Strategy != nil {
|
if j.Strategy != nil {
|
||||||
j.Strategy.FailFast = j.Strategy.GetFailFast()
|
j.Strategy.FailFast = j.Strategy.GetFailFast()
|
||||||
|
@ -386,7 +380,7 @@ func (j *Job) GetMatrixes() []map[string]interface{} {
|
||||||
excludes = append(excludes, e)
|
excludes = append(excludes, e)
|
||||||
} else {
|
} else {
|
||||||
// We fail completely here because that's what GitHub does for non-existing matrix keys, fail on exclude, silent skip on include
|
// We fail completely here because that's what GitHub does for non-existing matrix keys, fail on exclude, silent skip on include
|
||||||
log.Fatalf("The workflow is not valid. Matrix exclude key '%s' does not match any key within the matrix", k)
|
return nil, fmt.Errorf("the workflow is not valid. Matrix exclude key %q does not match any key within the matrix", k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -431,7 +425,7 @@ func (j *Job) GetMatrixes() []map[string]interface{} {
|
||||||
} else {
|
} else {
|
||||||
matrixes = append(matrixes, make(map[string]interface{}))
|
matrixes = append(matrixes, make(map[string]interface{}))
|
||||||
}
|
}
|
||||||
return matrixes
|
return matrixes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func commonKeysMatch(a map[string]interface{}, b map[string]interface{}) bool {
|
func commonKeysMatch(a map[string]interface{}, b map[string]interface{}) bool {
|
||||||
|
@ -671,3 +665,17 @@ func (w *Workflow) GetJobIDs() []string {
|
||||||
}
|
}
|
||||||
return ids
|
return ids
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var OnDecodeNodeError = func(node yaml.Node, out interface{}, err error) {
|
||||||
|
log.Fatalf("Failed to decode node %v into %T: %v", node, out, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeNode(node yaml.Node, out interface{}) bool {
|
||||||
|
if err := node.Decode(out); err != nil {
|
||||||
|
if OnDecodeNodeError != nil {
|
||||||
|
OnDecodeNodeError(node, out, err)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
|
@ -250,25 +250,33 @@ func TestReadWorkflow_Strategy(t *testing.T) {
|
||||||
wf := p.Stages[0].Runs[0].Workflow
|
wf := p.Stages[0].Runs[0].Workflow
|
||||||
|
|
||||||
job := wf.Jobs["strategy-only-max-parallel"]
|
job := wf.Jobs["strategy-only-max-parallel"]
|
||||||
assert.Equal(t, job.GetMatrixes(), []map[string]interface{}{{}})
|
matrixes, err := job.GetMatrixes()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, matrixes, []map[string]interface{}{{}})
|
||||||
assert.Equal(t, job.Matrix(), map[string][]interface{}(nil))
|
assert.Equal(t, job.Matrix(), map[string][]interface{}(nil))
|
||||||
assert.Equal(t, job.Strategy.MaxParallel, 2)
|
assert.Equal(t, job.Strategy.MaxParallel, 2)
|
||||||
assert.Equal(t, job.Strategy.FailFast, true)
|
assert.Equal(t, job.Strategy.FailFast, true)
|
||||||
|
|
||||||
job = wf.Jobs["strategy-only-fail-fast"]
|
job = wf.Jobs["strategy-only-fail-fast"]
|
||||||
assert.Equal(t, job.GetMatrixes(), []map[string]interface{}{{}})
|
matrixes, err = job.GetMatrixes()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, matrixes, []map[string]interface{}{{}})
|
||||||
assert.Equal(t, job.Matrix(), map[string][]interface{}(nil))
|
assert.Equal(t, job.Matrix(), map[string][]interface{}(nil))
|
||||||
assert.Equal(t, job.Strategy.MaxParallel, 4)
|
assert.Equal(t, job.Strategy.MaxParallel, 4)
|
||||||
assert.Equal(t, job.Strategy.FailFast, false)
|
assert.Equal(t, job.Strategy.FailFast, false)
|
||||||
|
|
||||||
job = wf.Jobs["strategy-no-matrix"]
|
job = wf.Jobs["strategy-no-matrix"]
|
||||||
assert.Equal(t, job.GetMatrixes(), []map[string]interface{}{{}})
|
matrixes, err = job.GetMatrixes()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, matrixes, []map[string]interface{}{{}})
|
||||||
assert.Equal(t, job.Matrix(), map[string][]interface{}(nil))
|
assert.Equal(t, job.Matrix(), map[string][]interface{}(nil))
|
||||||
assert.Equal(t, job.Strategy.MaxParallel, 2)
|
assert.Equal(t, job.Strategy.MaxParallel, 2)
|
||||||
assert.Equal(t, job.Strategy.FailFast, false)
|
assert.Equal(t, job.Strategy.FailFast, false)
|
||||||
|
|
||||||
job = wf.Jobs["strategy-all"]
|
job = wf.Jobs["strategy-all"]
|
||||||
assert.Equal(t, job.GetMatrixes(),
|
matrixes, err = job.GetMatrixes()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, matrixes,
|
||||||
[]map[string]interface{}{
|
[]map[string]interface{}{
|
||||||
{"datacenter": "site-c", "node-version": "14.x", "site": "staging"},
|
{"datacenter": "site-c", "node-version": "14.x", "site": "staging"},
|
||||||
{"datacenter": "site-c", "node-version": "16.x", "site": "staging"},
|
{"datacenter": "site-c", "node-version": "16.x", "site": "staging"},
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/opencontainers/selinux/go-selinux"
|
"github.com/opencontainers/selinux/go-selinux"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/nektos/act/pkg/common"
|
"github.com/nektos/act/pkg/common"
|
||||||
"github.com/nektos/act/pkg/container"
|
"github.com/nektos/act/pkg/container"
|
||||||
|
@ -361,7 +360,8 @@ func (rc *RunContext) ActionCacheDir() string {
|
||||||
if home, err := os.UserHomeDir(); err == nil {
|
if home, err := os.UserHomeDir(); err == nil {
|
||||||
xdgCache = filepath.Join(home, ".cache")
|
xdgCache = filepath.Join(home, ".cache")
|
||||||
} else if xdgCache, err = filepath.Abs("."); err != nil {
|
} else if xdgCache, err = filepath.Abs("."); err != nil {
|
||||||
log.Fatal(err)
|
// It's almost impossible to get here, so the temp dir is a good fallback
|
||||||
|
xdgCache = os.TempDir()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filepath.Join(xdgCache, "act")
|
return filepath.Join(xdgCache, "act")
|
||||||
|
|
|
@ -118,7 +118,12 @@ func (runner *runnerImpl) NewPlanExecutor(plan *model.Plan) common.Executor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
matrixes := selectMatrixes(job.GetMatrixes(), runner.config.Matrix)
|
var matrixes []map[string]interface{}
|
||||||
|
if m, err := job.GetMatrixes(); err != nil {
|
||||||
|
log.Errorf("Error while get job's matrix: %v", err)
|
||||||
|
} else {
|
||||||
|
matrixes = selectMatrixes(m, runner.config.Matrix)
|
||||||
|
}
|
||||||
log.Debugf("Final matrix after applying user inclusions '%v'", matrixes)
|
log.Debugf("Final matrix after applying user inclusions '%v'", matrixes)
|
||||||
|
|
||||||
maxParallel := 4
|
maxParallel := 4
|
||||||
|
|
Loading…
Reference in a new issue