Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8d3acd8
meaningful names
6543 Oct 20, 2026
b13b29c
increase max axes to 64 and error out if hit
6543 Oct 20, 2026
9be289e
Add tests for the matrix workflow limit
6543 Oct 20, 2026
a7308ff
include matrix
6543 Oct 20, 2026
8a22a57
dups
6543 Oct 20, 2026
68eac67
Limit matrix entries in JSON schema
codex Oct 20, 2026
5b9ad27
Fix matrix parsing through YAML nodes
codex Oct 20, 2026
4c48b8b
Test matrix permutation overflow handling
codex Oct 20, 2026
4c1cf99
refactor
6543 Oct 21, 2026
164576e
refactor
6543 Oct 21, 2026
1945797
works
6543 Oct 21, 2026
860e9ef
rm duplicates then count
6543 Oct 21, 2026
2fbecfe
test(matrix): cover duplicate normal matrix axes
codex Oct 21, 2026
5ba17f4
make it work
6543 Oct 21, 2026
4c69a85
new file was not worth it
6543 Oct 21, 2026
c30690a
fail early addition
6543 Oct 21, 2026
3a55623
fix
6543 Oct 21, 2026
57b032f
Merge branch 'main' into enhance-matrix-feature
6543 Oct 21, 2026
64751a3
Merge branch 'main' into enhance-matrix-feature
6543 Oct 21, 2026
830d818
Remove unused Axis.String from matrix package
claude Oct 22, 2026
c54827d
Update docs/docs/20-usage/30-matrix-workflows.md
6543 Oct 22, 2026
919a5f1
Apply batched suggestions from code review
6543 Oct 22, 2026
6fd312c
Merge branch 'main' into enhance-matrix-feature
6543 Oct 22, 2026
c0d1f1e
fix
6543 Oct 22, 2026
86fbcf7
Update pipeline/frontend/yaml/matrix/matrix.go
6543 Oct 23, 2026
5edfcc9
fix
6543 Oct 23, 2026
a99f355
t.Parallel()
6543 Oct 23, 2026
6168307
Merge branch 'main' into enhance-matrix-feature
6543 Oct 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/docs/20-usage/30-matrix-workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
Woodpecker has integrated support for matrix workflows. Woodpecker executes a separate workflow for each combination in the matrix, allowing you to build and test against multiple configurations.

:::warning
Woodpecker currently supports a maximum of **27 matrix axes** per workflow.
If your matrix exceeds this number, any additional axes will be silently ignored.
Woodpecker generates at most **64 workflows** per matrix.
The variables are also limited to **10** per axis.
A matrix with more combinations is rejected with an error.
:::

Example matrix definition:
Expand Down
2 changes: 1 addition & 1 deletion pipeline/frontend/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (b *PipelineBuilder) Build() (items []*Item, errorsAndWarnings error) {

for _, y := range b.Yamls {
// matrix axes
axes, err := matrix.ParseString(string(y.Data))
axes, err := matrix.Parse(y.Data)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions pipeline/frontend/yaml/linter/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1072,23 +1072,23 @@
"additionalProperties": true
},
"matrix": {
"description": "Execute pipeline for each matrix combination. Read more: https://woodpecker-ci.org/docs/usage/matrix-workflows",
"description": "Execute pipeline for each matrix combination. Each axis supports at most 10 values and the include list is limited to 64 entries; the total matrix combination count is checked when parsing. Read more: https://woodpecker-ci.org/docs/usage/matrix-workflows",
"type": "object",
"properties": {
"include": {
"type": "array",
"items": {
"type": "object"
},
"minLength": 1
"maxItems": 64
}
},
"additionalProperties": {
"type": "array",
"items": {
"type": ["boolean", "string", "number"]
},
"minLength": 1
"maxItems": 10
}
},
"labels": {
Expand Down
42 changes: 42 additions & 0 deletions pipeline/frontend/yaml/linter/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"io"
"os"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -213,3 +214,44 @@ func TestLintConcurrent(t *testing.T) {
})
}
}

func TestMatrixSchemaWorkflowLimit(t *testing.T) {
tests := []struct {
name string
count int
include bool
wantErr bool
}{
{name: "10 axis values", count: 10},
{name: "11 axis values", count: 11, wantErr: true},
{name: "64 include entries", count: 64, include: true},
{name: "65 include entries", count: 65, include: true, wantErr: true},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var matrix string
if tt.include {
entries := make([]string, tt.count)
for i := range entries {
entries[i] = fmt.Sprintf(" - VERSION: %d", i)
}
matrix = "matrix:\n include:\n" + strings.Join(entries, "\n")
} else {
values := make([]string, tt.count)
for i := range values {
values[i] = fmt.Sprintf(" - %d", i)
}
matrix = "matrix:\n VERSION:\n" + strings.Join(values, "\n")
}
config := "steps:\n test:\n image: alpine\n commands: [echo test]\n" + matrix

_, err := schema.LintString(config)
if tt.wantErr {
require.Error(t, err)
} else {
require.NoError(t, err)
}
})
}
}
2 changes: 2 additions & 0 deletions pipeline/frontend/yaml/matrix/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func FuzzParse(f *testing.F) {
f.Add([]byte("matrix:\n include:\n - GO: 1\n OS: linux"))
f.Add([]byte("matrix: {}"))
f.Add([]byte("matrix:\n A: [x]"))
f.Add([]byte(largeMatrix(10, 128)))
f.Add([]byte(largeMatrix(64, 2)))

f.Fuzz(func(_ *testing.T, data []byte) {
_, _ = Parse(data)
Expand Down
218 changes: 145 additions & 73 deletions pipeline/frontend/yaml/matrix/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,24 @@
package matrix

import (
"fmt"
"sort"
"strings"

go_yaml "go.yaml.in/yaml/v4"

pipeline_errors "go.woodpecker-ci.org/woodpecker/v3/pipeline/errors"
"go.woodpecker-ci.org/woodpecker/v3/pipeline/frontend/yaml"
)

const (
limitTags = 10
limitAxis = 25
limitVariables = 10
maxWorkflows = 64
)

var (
ErrorMaxWorkflowsReached = fmt.Errorf("matrix config produced more than %d workflows", maxWorkflows)

ErrorMaxAxisVariablesReached = fmt.Errorf("matrix config has more than %d variables in an axis", limitVariables)
)

// Matrix represents the pipeline matrix.
Expand All @@ -33,112 +41,176 @@ type Matrix map[string][]string
// Axis represents a single permutation of entries from the pipeline matrix.
type Axis map[string]string

// String returns a string representation of an Axis as a comma-separated list
// of environment variables.
func (a Axis) String() string {
var envs []string
for k, v := range a {
envs = append(envs, k+"="+v)
}
return strings.Join(envs, " ")
}

// Parse parses the Yaml matrix definition.
func Parse(data []byte) ([]Axis, error) {
axis, err := parseList(data)
if err == nil && len(axis) != 0 {
return axis, nil
value := new(go_yaml.Node)
if err := yaml.Unmarshal(data, value); err != nil {
return nil, compilerError(err)
}

matrix, err := parse(data)
if err != nil {
return nil, err
if value.Kind == go_yaml.DocumentNode && len(value.Content) == 1 {
value = value.Content[0]
}

if len(matrix) == 0 {
if value == nil || value.Kind != go_yaml.MappingNode {
return []Axis{}, nil
}

return calc(matrix), nil
}
matrixNode := dereferenceAlias(mappingValue(value, "matrix"))
if matrixNode == nil ||
(matrixNode.Kind == go_yaml.ScalarNode && matrixNode.Tag == "!!null") ||
matrixNode.Kind == go_yaml.MappingNode && len(matrixNode.Content) == 0 {
return []Axis{}, nil
}

if includeNode := mappingValue(matrixNode, "include"); includeNode != nil {
return parseInclude(includeNode)
}

// ParseString parses the Yaml string matrix definition.
func ParseString(data string) ([]Axis, error) {
return Parse([]byte(data))
matrix, err := parseMatrix(matrixNode)
if err != nil {
return nil, err
}
return calcAxes(matrix)
}

func calc(matrix Matrix) []Axis {
// calculate number of permutations and extract the list of tags
// (ie go_version, redis_version, etc)
var perm int
var tags []string
for k, v := range matrix {
// an axis without values contributes no permutations and would
// cause a division by zero below
if len(v) == 0 {
func calcAxes(matrix Matrix) ([]Axis, error) {
// fail early if we know the outcome is more than allowed already
if len(matrix) > maxWorkflows {
return nil, ErrorMaxWorkflowsReached
}

// calculate number of permutations and extract the list of variable
// names (ie go_version, redis_version, etc)
var axisCount int
var names []string
for name, values := range matrix {
// an axis without values contributes no permutations
if len(values) == 0 {
continue
}
perm *= len(v)
if perm == 0 {
perm = len(v)

Comment thread
6543 marked this conversation as resolved.
Resolved
if len(values) > limitVariables {
return nil, ErrorMaxAxisVariablesReached
}
tags = append(tags, k)
if axisCount == 0 {
axisCount = len(values)
} else {
axisCount *= len(values)
}

// enforce limit
if axisCount > maxWorkflows {
return nil, ErrorMaxWorkflowsReached
}

names = append(names, name)
}
// map iteration order is random: sort the tags so the permutation order

// map iteration order is random: sort the names so the permutation order
// is deterministic and derived workflow numbering is stable across
// repeated compilations of the same pipeline.
sort.Strings(tags)
sort.Strings(names)

// structure to hold the transformed result set
var axisList []Axis
var axes []Axis

// for each axis calculate the unique set of values that should be used.
for p := 0; p < perm; p++ {
for axisIndex := 0; axisIndex < axisCount; axisIndex++ {
axis := map[string]string{}
decrease := perm
for i, tag := range tags {
elems := matrix[tag]
decrease /= len(elems)
elem := p / decrease % len(elems)
axis[tag] = elems[elem]

// enforce a maximum number of tags in the pipeline matrix.
if i > limitTags {
break
}
// number of consecutive axes that share the same value of a variable
axesPerValue := axisCount
for _, name := range names {
values := matrix[name]
axesPerValue /= len(values)
valueIndex := axisIndex / axesPerValue % len(values)
axis[name] = values[valueIndex]
}

// append to the list of axis.
axisList = append(axisList, axis)
axes = append(axes, axis)
}

return uniqueAxes(axes), nil
}

func parseMatrix(node *go_yaml.Node) (Matrix, error) {
matrix := make(Matrix)
if err := node.Decode(&matrix); err != nil {
return nil, compilerError(err)
}
return matrix, nil
}

// enforce a maximum number of axis that should be calculated.
if p > limitAxis {
break
func parseInclude(node *go_yaml.Node) ([]Axis, error) {
var axes []Axis
if err := node.Decode(&axes); err != nil {
return nil, compilerError(err)
}

if len(axes) > maxWorkflows {
return nil, ErrorMaxWorkflowsReached
}

for _, values := range axes {
if len(values) > limitVariables {
return nil, ErrorMaxAxisVariablesReached
}
}

return axisList
return uniqueAxes(axes), nil
}

func parse(raw []byte) (Matrix, error) {
data := struct {
Matrix map[string][]string
}{}
if err := yaml.Unmarshal(raw, &data); err != nil {
return nil, &pipeline_errors.PipelineError{Message: err.Error(), Type: pipeline_errors.PipelineErrorTypeCompiler}
func uniqueAxes(axes []Axis) []Axis {
unique := make([]Axis, 0, len(axes))
for _, axis := range axes {
duplicate := false
for _, existing := range unique {
if equalAxes(axis, existing) {
duplicate = true
break
}
}
if !duplicate {
unique = append(unique, axis)
}
}
return unique
}

func equalAxes(left, right Axis) bool {
if len(left) != len(right) {
return false
}
for name, value := range left {
otherValue, ok := right[name]
if !ok || otherValue != value {
return false
}
}
return data.Matrix, nil
return true
}

func parseList(raw []byte) ([]Axis, error) {
data := struct {
Matrix struct {
Include []Axis
func mappingValue(node *go_yaml.Node, key string) *go_yaml.Node {
node = dereferenceAlias(node)
if node == nil || node.Kind != go_yaml.MappingNode {
return nil
}
for i := 0; i+1 < len(node.Content); i += 2 {
if node.Content[i].Value == key {
return node.Content[i+1]
}
}{}
}
return nil
}

if err := yaml.Unmarshal(raw, &data); err != nil {
return nil, &pipeline_errors.PipelineError{Message: err.Error(), Type: pipeline_errors.PipelineErrorTypeCompiler}
func dereferenceAlias(node *go_yaml.Node) *go_yaml.Node {
for node != nil && node.Kind == go_yaml.AliasNode {
node = node.Alias
}
return data.Matrix.Include, nil
return node
}

func compilerError(err error) error {
return &pipeline_errors.PipelineError{Message: err.Error(), Type: pipeline_errors.PipelineErrorTypeCompiler}
}
Loading