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
- Getting Started With Node.js
- Create a Testing Matrix
- Using MongoDB
- Using Redis
- Using MongoDB Replica Sets
- Run on Pull Request
- Customize the Job Name
- Run a Workflow When Creating a Tag
- Testing Against an Exact Node.js Version
- Trigger Builds on Schedule (Cron)
- How to Test Lerna Monorepos
- How to Add Comments in YAML Files
- Clone Another Repository
- Run on Push or Pull Request, but Not Both
- Limit Concurrency and Cancel In-Progress Jobs
- Test Against the Latest Node.js Version
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.