In the previous article we set a node project with GitHub Actions.
Now we are going to build and test for multiple NodeJS version in one action, because it sometimes important to build and test your software with multiple versions of NodeJS, e.g. to cover backward compatibility or to test against all available LTS releases.
Sounds fun --- let's get to it.
# This workflow will do a clean install of node dependencies, build the source code and run tests
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: CI Pipeline
# trigger build when pushing, or when creating a pull request
on: [push, pull_request]
jobs:
build:
# run build on latest ubuntu
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x]
steps:
# this will check out the current branch (https://github.com/actions/checkout#Push-a-commit-using-the-built-in-token)
- uses: actions/checkout@v3
# installing Node
- name: Use Node.js 16.16.0
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
# install dependencies using clean install to avoid package lock updates
- run: npm ci
# build the project if necessary
- run: npm run build --if-present
# finally run the test
- run: npm test
After that commit & push your work and head over to action section of your repo to view all executed workflows.
In the next article we will add coveralls to view code coverage badge.
Top comments (0)