Skip to content

Commit

Permalink
ci: Calculate Node.js version dynamically for the ci matrix (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Sep 6, 2022
1 parent 3242d99 commit 544817d
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI
on: [push, pull_request]

jobs:
build:

# https://thekevinwang.com/2021/09/19/github-actions-dynamic-matrix/
prepare_matrix:
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.generate-matrix.outputs.versions }}
steps:
- name: Generate Node.js versions matrix
id: generate-matrix
run: |
current_lts=$(curl -s https://nodejs.org/en/ | grep -E -o 'Download [0-9.]+ LTS' | grep -E -o '([0-9]+)' | head -n 1)
previous_lts=$(( current_lts - 2 ))
next_lts=$(( current_lts + 2 ))
VERSIONS="[$previous_lts, $current_lts, $next_lts]"
echo ::set-output name=versions::${VERSIONS}
build:
runs-on: ubuntu-latest
needs:
- prepare_matrix
strategy:
matrix:
node-version: [14, 16, 18]

node-version: ${{ fromJSON(needs.prepare_matrix.outputs.versions) }}
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # tag=v3
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: |
npm ci
npm test
npm run lint
npm i -g npm
npm ci || npm install
name: Install dev dependencies
- run: npm run lint
name: Linter
- run: npm run test
name: Tests

0 comments on commit 544817d

Please sign in to comment.