Skip to content

Commit

Permalink
ci: run test against different node versions
Browse files Browse the repository at this point in the history
  • Loading branch information
dianjuar committed Sep 26, 2024
1 parent 9406234 commit d2ece96
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 4 deletions.
19 changes: 18 additions & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
name: Setup
description: Setup Node.js, cache and install dependencies
inputs:
node-version:
description: 'The Node.js version to use. The default one is going to be the defined on the .nvmrc file.'
required: false
runs:
using: composite
steps:
- name: Checkout all commits
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set Node.js version based on .nvmrc or Action Input
shell: bash
run: |
if [ -z "${{ inputs.node-version }}" ]; then
version=$(cat .nvmrc)
echo "Setting default value for node-version parameter: $version"
echo "NODE_VERSION=$version" >> $GITHUB_ENV
else
echo "Using provided value for node-version parameter: ${{ inputs.node-version }}"
echo "NODE_VERSION=${{ inputs.node-version }}" >> $GITHUB_ENV
fi
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
# This doesn't just set the registry url, but also sets
# the right configuration in .npmrc that reads NPM token
Expand Down
29 changes: 28 additions & 1 deletion .github/workflows/backwards-compatibility-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,34 @@ jobs:
backwards-compatibility-test:
strategy:
matrix:
nx-version: ['', '18.3.5', '17.3.2', '16.10.0'] # '' means current workspace version
include:
# '' means current workspace version
- nx-version: ''
node-version: 22
- nx-version: ''
node-version: 20
- nx-version: ''
node-version: 18

- nx-version: '18.3.5'
node-version: 20
- nx-version: '18.3.5'
node-version: 18

- nx-version: '17.3.2'
node-version: 20
- nx-version: '17.3.2'
node-version: 18

- nx-version: '16.10.0'
node-version: 20
- nx-version: '16.10.0'
node-version: 18
- nx-version: '16.10.0'
node-version: 16 # This node's version is deprecated

name: Backwards Compatibility Test
uses: ./.github/workflows/integration-test-nx-workspace.yml
with:
nx-version: ${{matrix.nx-version}}
node-version: ${{matrix.node-version}}
3 changes: 3 additions & 0 deletions .github/workflows/basic-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node-version: [18, 20, 22]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
with:
node-version: ${{ matrix.node-version }}

- run: npx nx test ngx-deploy-npm --configuration="ci"

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node-version: [18, 20, 22]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup

with:
node-version: ${{ matrix.node-version }}
- run: npx nx e2e ngx-deploy-npm-e2e --configuration="ci"
22 changes: 21 additions & 1 deletion .github/workflows/integration-test-nx-workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,38 @@ on:
type: string
description: The Nx Workspace version to run the integration test
required: false
node-version:
type: string
description: The Node version to run the integration test
required: false

jobs:
integration-test:
runs-on: ubuntu-latest
steps:
- name: Indicate versions
run: |
if [ -n "${{ inputs.node-version }}" ]; then
echo "Using Node version: ${{ inputs.node-version }}"
else
echo "Using default Node version from .npmrc file"
fi
if [ -n "${{ inputs.nx-version }}" ]; then
echo "Using Nx version: ${{ inputs.nx-version }}"
else
echo "Using default Nx version from package.json file"
fi
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
with:
node-version: ${{ inputs.node-version }}

- name: Read package.json Nx and set default parameter
id: set-default-param
run: |
if [ -z "${{ inputs.nx-version }}" ]; then
version=$(jq -r '.devDependencies.nx' package.json)
echo "Setting default value for nx-version parameter: $version"
Expand Down
9 changes: 9 additions & 0 deletions docs/README_contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [Making a Contribution](#making-a-contribution)
- [E2E test](#e2e-test)
- [Continuous Inspection (SonarQube)](#continuous-inspection-sonarqube)
- [Test different node versions](#test-different-node-versions)
- [When are my changes going to be public?](#when-are-my-changes-going-to-be-public)

## How to start
Expand Down Expand Up @@ -123,6 +124,14 @@ To init the server

To inspect the analysis, go to http://localhost:9000. The credentials are `admin` and password `12345`

## Test different node versions

Here, we run the unit, e2e, and regression tests against different node versions in our CI. We use the [Nx NodeJs Compatibility Matrix](https://nx.dev/nx-api/workspace/documents/nx-nodejs-typescript-version-matrix) to determine which versions should be tested.

The retro compatibility tests are a bit different since we match the Nx Workspace Version with the supported Node versions.

For local development, stick to the one defined in the `.npmrc` file.

## When are my changes going to be public?

The CI handles the publishment of a new version. We use GitHub actions as CI.
Expand Down

0 comments on commit d2ece96

Please sign in to comment.