Matrix and strategy

The strategy key will allow us to set up an environment matrix. GitHub will then run the job in every possible combination of environments set-ups specified on our matrix. To set up a strategy we need to include the strategy key in our job. Inside this key we also need to add the matrix key. The value of the matrix key needs to be an object. The keys of this object can be whatever we like. These keys basically act as parameters. Each value is an array of the different values that we want to pass to our job for that parameter.


Under the strategy key we can also add the fail-fast key. By default this key has a value of true. This means that under this job, if one step fails, all other steps of the job will be stopped.


We can also add the max-parallel keyword. This key takes as its value an integer that specifies how many values of the matrix can run in parallel. By default, GitHub will try to maximize the number of jobs running in parallel.


To reference the values of our matrix we need to use an expression that invokes the matrix context. Using dot notation, we pass the context and the parameter key that we defined in our matrix. GitHub will run the job once with each possible combination of parameter values.

Matrix and strategy 1
Matrix and strategy 2

If we want to exclude a particular combination in our matrix, we can use the exclude key to specify an array of values (one per key) to exclude.

There's also an include key, but it's not the opposite of the exclude key. This key also takes an array of objects with all the parameters of the matrix, but we use it to specify additional configurations or variables that are needed for that combination only.

Matrix and strategy 3