Improve github workflows #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run Tests | |
on: | |
workflow_call: | |
push: | |
paths: | |
- '**.js' | |
- '**.json' | |
- '.github/workflows/run-tests.yml' | |
pull_request: | |
paths: | |
- '**.js' | |
- '**.json' | |
- '.github/workflows/run-tests.yml' | |
jobs: | |
tests: | |
name: Run Tests with Node.js ${{ matrix.node }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node: [ lts/*, latest, 16, 18, 20 ] | |
steps: | |
# https://github.com/actions/cache/blob/main/examples.md#node---npm | |
- name: Get npm cache directory | |
id: npm-cache-dir | |
shell: bash | |
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT} | |
# https://github.com/actions/cache/releases | |
- name: Use cache for npm | |
uses: actions/[email protected] | |
id: npm-cache | |
with: | |
path: ${{ steps.npm-cache-dir.outputs.dir }} | |
key: npm-${{ hashFiles('package.json') }} | |
restore-keys: npm- | |
# https://github.com/actions/checkout/releases | |
- name: Checkout | |
uses: actions/[email protected] | |
- name: Build package-lock | |
run: npm i --package-lock-only | |
# https://github.com/actions/setup-node/releases | |
- name: Setup Node.js | |
uses: actions/[email protected] | |
with: | |
node-version: ${{ matrix.node }} | |
- name: Clean & Install Deps | |
run: npm ci | |
- name: Run Tests | |
run: npm test |