DEV Community

Sean Killeen
Sean Killeen

Posted on • Originally published at seankilleen.com on

How To Specify Pairs of Items in GitHub Actions Matrix Strategies

Came across this and wasn’t aware of it (though it makes total sense in retrospect), so I figured I’d pass the tip along.

Background: What is a Matrix Strategy in GitHub Actions?

Sometimes you need an GitHub Action Job to run for multiple combinations of items. In my case, I was looking to run an action to publish a Docker container across a combination of Ruby, Node, and GitHub Pages versions.

Running an action in this way will create an instance of that job for every combination in the matrix entries:

jobs:
  build_release:
    name: "Build and Release"
    strategy:
      matrix:
        RUBY_VERSION: [2.7.3]
        NODE_MAJOR_VERSION: [16, 18]
        GITHUB_PAGES_VERSION: [226]
    runs-on: ubuntu-latest
    env:

      RUBY_VERSION: ${{ matrix.RUBY_VERSION }}
      NODE_MAJOR_VERSION: ${{ matrix.NODE_MAJOR_VERSION }}
      GITHUB_PAGES_VERSION: ${{ matrix.GITHUB_PAGES_VERSION }}

Enter fullscreen mode Exit fullscreen mode

…But do we really want every combination?

Read the rest of this article at SeanKilleen.com!

Top comments (0)