From 7c3cf18bae0174dd0955c40c349289be6405ed7a Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Sun, 5 Jun 2022 20:26:13 +0200 Subject: [PATCH 01/10] Update workflow.go --- pkg/model/workflow.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/model/workflow.go b/pkg/model/workflow.go index 55b80fc365d..675ec46009e 100644 --- a/pkg/model/workflow.go +++ b/pkg/model/workflow.go @@ -224,17 +224,23 @@ func (j *Job) GetMatrixes() []map[string]interface{} { if m := j.Matrix(); m != nil { includes := make([]map[string]interface{}, 0) + extraIncludes := make([]map[string]interface{}, 0) for _, v := range m["include"] { switch t := v.(type) { case []interface{}: for _, i := range t { i := i.(map[string]interface{}) + extraInclude := true for k := range i { if _, ok := m[k]; ok { includes = append(includes, i) + extraInclude = false break } } + if extraInclude { + extraIncludes = append(extraIncludes, i) + } } case interface{}: v := v.(map[string]interface{}) @@ -273,10 +279,23 @@ func (j *Job) GetMatrixes() []map[string]interface{} { } matrixes = append(matrixes, matrix) } - for _, include := range includes { + for _, matrix := range matrixes { + for _, include := range includes { + if commonKeysMatch(matrix, include) { + log.Debugf("Adding include values '%v'", include) + for k, v := range include { + matrix[k] = v + } + } + } + } + for _, include := range extraIncludes { log.Debugf("Adding include '%v'", include) matrixes = append(matrixes, include) } + if len(matrixes) == 0 { + matrixes = append(matrixes, make(map[string]interface{})) + } } else { matrixes = append(matrixes, make(map[string]interface{})) } From 4f88fee9fee663aabf0094b231efe7e9bdaaffa2 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Sun, 5 Jun 2022 20:42:36 +0200 Subject: [PATCH 02/10] Update workflow.go --- pkg/model/workflow.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/model/workflow.go b/pkg/model/workflow.go index 675ec46009e..ed4e2f1930a 100644 --- a/pkg/model/workflow.go +++ b/pkg/model/workflow.go @@ -279,15 +279,21 @@ func (j *Job) GetMatrixes() []map[string]interface{} { } matrixes = append(matrixes, matrix) } - for _, matrix := range matrixes { - for _, include := range includes { + for _, include := range includes { + matched := false + for _, matrix := range matrixes { if commonKeysMatch(matrix, include) { - log.Debugf("Adding include values '%v'", include) + matched = true + log.Debugf("Adding include values '%v' to existing entry", include) for k, v := range include { matrix[k] = v } } } + if matched { + log.Debugf("Adding include '%v'", include) + matrixes = append(matrixes, include) + } } for _, include := range extraIncludes { log.Debugf("Adding include '%v'", include) From 39b762538ab43ca5edec9920bec201c8492d4359 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Sun, 5 Jun 2022 21:23:28 +0200 Subject: [PATCH 03/10] Update workflow.go --- pkg/model/workflow.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/model/workflow.go b/pkg/model/workflow.go index ed4e2f1930a..306f41900e4 100644 --- a/pkg/model/workflow.go +++ b/pkg/model/workflow.go @@ -282,7 +282,7 @@ func (j *Job) GetMatrixes() []map[string]interface{} { for _, include := range includes { matched := false for _, matrix := range matrixes { - if commonKeysMatch(matrix, include) { + if commonKeysMatch2(matrix, include, m) { matched = true log.Debugf("Adding include values '%v' to existing entry", include) for k, v := range include { @@ -291,8 +291,7 @@ func (j *Job) GetMatrixes() []map[string]interface{} { } } if matched { - log.Debugf("Adding include '%v'", include) - matrixes = append(matrixes, include) + extraIncludes = append(extraIncludes, include) } } for _, include := range extraIncludes { @@ -320,6 +319,16 @@ func commonKeysMatch(a map[string]interface{}, b map[string]interface{}) bool { return true } +func commonKeysMatch2(a map[string]interface{}, b map[string]interface{}, a map[string]interface{}) bool { + for aKey, aVal := range a { + _, useKey := m[aKey] + if bVal, ok := b[aKey]; useKey && ok && !reflect.DeepEqual(aVal, bVal) { + return false + } + } + return true +} + // ContainerSpec is the specification of the container to use for the job type ContainerSpec struct { Image string `yaml:"image"` From 9bc5f80bf251dd129b509c1627a06d4846c73572 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Sun, 5 Jun 2022 21:41:37 +0200 Subject: [PATCH 04/10] Update workflow.go --- pkg/model/workflow.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/model/workflow.go b/pkg/model/workflow.go index 306f41900e4..2bf3ad6a610 100644 --- a/pkg/model/workflow.go +++ b/pkg/model/workflow.go @@ -319,7 +319,7 @@ func commonKeysMatch(a map[string]interface{}, b map[string]interface{}) bool { return true } -func commonKeysMatch2(a map[string]interface{}, b map[string]interface{}, a map[string]interface{}) bool { +func commonKeysMatch2(a map[string]interface{}, b map[string]interface{}, m map[string]interface{}) bool { for aKey, aVal := range a { _, useKey := m[aKey] if bVal, ok := b[aKey]; useKey && ok && !reflect.DeepEqual(aVal, bVal) { From 7074fb49c218ab07dfd83dfaa9667a91ad41b85d Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Sun, 5 Jun 2022 21:44:14 +0200 Subject: [PATCH 05/10] Update workflow.go --- pkg/model/workflow.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/model/workflow.go b/pkg/model/workflow.go index 2bf3ad6a610..d88b233825d 100644 --- a/pkg/model/workflow.go +++ b/pkg/model/workflow.go @@ -319,7 +319,7 @@ func commonKeysMatch(a map[string]interface{}, b map[string]interface{}) bool { return true } -func commonKeysMatch2(a map[string]interface{}, b map[string]interface{}, m map[string]interface{}) bool { +func commonKeysMatch2(a map[string]interface{}, b map[string]interface{}, m map[string][]interface{}) bool { for aKey, aVal := range a { _, useKey := m[aKey] if bVal, ok := b[aKey]; useKey && ok && !reflect.DeepEqual(aVal, bVal) { From e5532ce128f32dd4a0f202d75381cb27108ce12e Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Sun, 5 Jun 2022 21:46:09 +0200 Subject: [PATCH 06/10] Update workflow.go --- pkg/model/workflow.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/model/workflow.go b/pkg/model/workflow.go index d88b233825d..c089d83fc90 100644 --- a/pkg/model/workflow.go +++ b/pkg/model/workflow.go @@ -290,7 +290,7 @@ func (j *Job) GetMatrixes() []map[string]interface{} { } } } - if matched { + if !matched { extraIncludes = append(extraIncludes, include) } } From 39fd8f5d8d4d48eb9bf88ab08b59fc4aac209862 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Fri, 17 Jun 2022 20:41:05 +0200 Subject: [PATCH 07/10] Add Tests --- pkg/runner/testdata/evalmatrix/push.yml | 63 ++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/pkg/runner/testdata/evalmatrix/push.yml b/pkg/runner/testdata/evalmatrix/push.yml index 94e9741e9df..dd742ecd116 100644 --- a/pkg/runner/testdata/evalmatrix/push.yml +++ b/pkg/runner/testdata/evalmatrix/push.yml @@ -15,4 +15,65 @@ jobs: echo $MATRIX exit ${{matrix.A && '0' || '1'}} env: - MATRIX: ${{toJSON(matrix)}} \ No newline at end of file + MATRIX: ${{toJSON(matrix)}} + _additionalInclude_0: + strategy: + matrix: + include: + - def: val + runs-on: ubuntu-latest + steps: + - name: Check if the matrix key A exists + run: | + echo $MATRIX + exit ${{matrix.def == 'val' && '0' || '1'}} + env: + MATRIX: ${{toJSON(matrix)}} + - run: | + echo "::set-output name=result::success" + id: result + outputs: + result: ${{ steps.result.outputs.result }} + _additionalInclude_1: + needs: _additionalInclude_0 + if: always() + runs-on: ubuntu-latest + steps: + - name: Check if the matrix key A exists + run: | + echo $MATRIX + exit ${{needs._additionalInclude_0.outputs.result == 'success' && '0' || '1'}} + _additionalProperties_0: + strategy: + matrix: + x: + - 0 + y: + - 0 + z: + - 0 + include: + - def: val + z: 0 + runs-on: ubuntu-latest + steps: + - name: Check if the matrix key A exists + run: | + echo $MATRIX + exit ${{matrix.def == 'val' && matrix.x == 0 && matrix.y == 0 && matrix.z == 0 && '0' || '1'}} + env: + MATRIX: ${{toJSON(matrix)}} + - run: | + echo "::set-output name=result::success" + id: result + outputs: + result: ${{ steps.result.outputs.result }} + _additionalProperties_1: + needs: _additionalProperties_0 + if: always() + runs-on: ubuntu-latest + steps: + - name: Check if the matrix key A exists + run: | + echo $MATRIX + exit ${{needs._additionalProperties_0.outputs.result == 'success' && '0' || '1'}} From 988b2c7c52b1d105c1e235aeb2c8db2bc07ad4da Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Fri, 17 Jun 2022 21:35:18 +0200 Subject: [PATCH 08/10] Update workflow.go --- pkg/model/workflow.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/model/workflow.go b/pkg/model/workflow.go index c089d83fc90..92e459acf04 100644 --- a/pkg/model/workflow.go +++ b/pkg/model/workflow.go @@ -244,12 +244,17 @@ func (j *Job) GetMatrixes() []map[string]interface{} { } case interface{}: v := v.(map[string]interface{}) + extraInclude := true for k := range v { if _, ok := m[k]; ok { includes = append(includes, v) + extraInclude = false break } } + if extraInclude { + extraIncludes = append(extraIncludes, v) + } } } delete(m, "include") From ae19331fb0acccf47b752c8440bacc56f2589839 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Fri, 17 Jun 2022 22:15:36 +0200 Subject: [PATCH 09/10] Modify Test --- pkg/model/workflow_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/model/workflow_test.go b/pkg/model/workflow_test.go index f15d570b2a0..9a58e6cb9c9 100644 --- a/pkg/model/workflow_test.go +++ b/pkg/model/workflow_test.go @@ -247,6 +247,7 @@ func TestReadWorkflow_Strategy(t *testing.T) { {"datacenter": "site-c", "node-version": "14.x", "site": "staging"}, {"datacenter": "site-c", "node-version": "16.x", "site": "staging"}, {"datacenter": "site-d", "node-version": "16.x", "site": "staging"}, + {"php-version": 5.4}, {"datacenter": "site-a", "node-version": "10.x", "site": "prod"}, {"datacenter": "site-b", "node-version": "12.x", "site": "dev"}, }, From ce5ae6a7e4d8ad5952a9a7f3fc21ccbbde5333a6 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Fri, 17 Jun 2022 22:19:46 +0200 Subject: [PATCH 10/10] use tabs --- pkg/model/workflow_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/model/workflow_test.go b/pkg/model/workflow_test.go index 9a58e6cb9c9..6d3b307f5e4 100644 --- a/pkg/model/workflow_test.go +++ b/pkg/model/workflow_test.go @@ -247,7 +247,7 @@ func TestReadWorkflow_Strategy(t *testing.T) { {"datacenter": "site-c", "node-version": "14.x", "site": "staging"}, {"datacenter": "site-c", "node-version": "16.x", "site": "staging"}, {"datacenter": "site-d", "node-version": "16.x", "site": "staging"}, - {"php-version": 5.4}, + {"php-version": 5.4}, {"datacenter": "site-a", "node-version": "10.x", "site": "prod"}, {"datacenter": "site-b", "node-version": "12.x", "site": "dev"}, },