From ba825a9e2f6f24d8e69541082f64d27703df165b Mon Sep 17 00:00:00 2001 From: rhysd Date: Sat, 20 Apr 2024 15:02:44 +0900 Subject: [PATCH] do not check if matrix combination values in `exclude` exist in `include` when they contain `${{ }}` (fix #414) --- rule_matrix.go | 10 +++++++++- .../ok/issue-414_expression_in_matrix_exclude.yaml | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 testdata/ok/issue-414_expression_in_matrix_exclude.yaml diff --git a/rule_matrix.go b/rule_matrix.go index b84054590..331ffeaa7 100644 --- a/rule_matrix.go +++ b/rule_matrix.go @@ -112,6 +112,14 @@ func filterMatchesMatrixRow(row []RawYAMLValue, filter RawYAMLValue) bool { return false } +func isYAMLStringWithExpression(val RawYAMLValue) bool { + s, ok := val.(*RawYAMLString) + if !ok { + return false + } + return ContainsExpression(s.Value) +} + func (rule *RuleMatrix) checkExclude(m *Matrix) { if m.Exclude == nil || len(m.Exclude.Combinations) == 0 || (m.Include != nil && m.Include.ContainsExpression()) { return @@ -178,7 +186,7 @@ Outer: continue } - if filterMatchesMatrixRow(vs, a.Value) { + if isYAMLStringWithExpression(a.Value) || filterMatchesMatrixRow(vs, a.Value) { continue } diff --git a/testdata/ok/issue-414_expression_in_matrix_exclude.yaml b/testdata/ok/issue-414_expression_in_matrix_exclude.yaml new file mode 100644 index 000000000..19eb506fb --- /dev/null +++ b/testdata/ok/issue-414_expression_in_matrix_exclude.yaml @@ -0,0 +1,12 @@ +on: [push] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + foo: ['a', 'b'] + exclude: + - foo: ${{ github.event_name }} + steps: + - run: echo ${{ matrix.foo }}