Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
GitHub Actions Cookbook

You're reading from   GitHub Actions Cookbook A practical guide to automating repetitive tasks and streamlining your development process

Arrow left icon
Product type Paperback
Published in Apr 2024
Publisher Packt
ISBN-13 9781835468944
Length 250 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Michael Kaufmann Michael Kaufmann
Author Profile Icon Michael Kaufmann
Michael Kaufmann
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Chapter 1: GitHub Actions Workflows FREE CHAPTER 2. Chapter 2: Authoring and Debugging Workflows 3. Chapter 3: Building GitHub Actions 4. Chapter 4: The Workflow Runtime 5. Chapter 5: Automate Tasks in GitHub with GitHub Actions 6. Chapter 6: Build and Validate Your Code 7. Chapter 7: Release Your Software with GitHub Actions 8. Index 9. Other Books You May Enjoy

Building different versions using a matrix

In this recipe, we are going to build and test our software for different versions, in our case, of the NodeJS environment.

Getting ready

Make sure you have cloned the repository from the previous recipe. Create a new branch to modify the workflow:

$ git switch -c build-matrix

Open the .github/workflows/ci.yml file in an editor.

How to do it…

  1. Add the following code to the workflow file:
    strategy:
      matrix:
        node-version: ["21.x", "20.x"]

    Adjust the versions if needed.

  2. In the actions/setup-node action, set the node version to the corresponding value from the matrix context:
    - uses: actions/setup-node@v4
      with:
        node-version: ${{ matrix.node-version }}
        check-latest: true
  3. Commit and push your changes and create a pull request:
    $ git add .
    $ git commit
    $ git push -u origin build-matrix
    $ gh pr create --fill...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime