GitHub Actions — Testing Against an Exact Node.js Version

Most of the Node.js examples for GitHub Actions use version numbers like 12.x. This value describes the latest Node.js v12 release, independently from the minor or patch version.

The Node.js GitHub Action supports exact version numbers beside the wildcard match. This is helpful when you want to replicate your production environment with GitHub Actions.

GitHub Actions Series Overview

Use an Exact Node.js Version in GitHub Actions

Exact version numbers align with your production setup. You may run your GitHub Action the exact Node.js version 12.16.2 like this:

name: Run tests

on: [push, pull_request]

jobs:  
  test:
    runs-on: ubuntu-latest

    steps:
    - name: Use Node.js 12.16.2
      uses: actions/setup-node@v1
      with:
        node-version: 12.16.2

This action uses single, exact Node.js version. You may want to ensure that your app works with future releases of Node.js. Create a matrix with exact and wildcard versions to ensure your code works in the given setup:

name: Run tests

on: [push, pull_request]

jobs:  
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [8.17.0, 10.20.1, 12.16.2, 13.x]

    steps:
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}

This example shows three exact versions for Node.js v8, v10, and v12. Also, the matrix includes the latest Node.js v13 development release. Eventually, the v13 release line becomes a v14 LTS release. You can bump the version numbers in your workflow when upgrading your Node.js environments.

Explore the Library

Find interesting tutorials and solutions for your problems.