Skip to content

Commit

Permalink
Issue-430 - Add shared node setup / module cache
Browse files Browse the repository at this point in the history
  • Loading branch information
huntharo committed May 22, 2024
1 parent db59870 commit 0e18b07
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
34 changes: 34 additions & 0 deletions .github/actions/configure-nodejs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 'Configure Node.js'
description: 'Install Node.js and install Node.js modules or restore cache'

inputs:
node-version:
description: 'NodeJS Version'
default: '18'
lookup-only:
description: 'If true, only checks if cache entry exists and skips download. Does not change save cache behavior. Does not install node on a hit (used primarily for install deps jobs).'
default: 'false'

runs:
using: 'composite'
steps:
- name: Restore Node Modules from Cache
id: cache-node-modules
uses: actions/cache@v4
with:
path: |
node_modules
packages/**/node_modules
!node_modules/.cache
key: node-modules-v2-${{ inputs.node-version }}-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package.json', 'package-lock.json') }}
lookup-only: ${{ inputs.lookup-only }}

- uses: actions/setup-node@v4
if: inputs.lookup-only == 'false' || steps.cache-node-modules.outputs.cache-hit != 'true'
with:
node-version: ${{ inputs.node-version }}

- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
shell: bash
run: npm ci
23 changes: 16 additions & 7 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@ name: Node CI
on: [push, pull_request]

jobs:
build:

install-deps:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/configure-nodejs
with:
node-version: ${{ matrix.node-version }}
lookup-only: 'true' # We only want to lookup from the cache - if a hit, this job does nothing

build:
needs:
- install-deps
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: ./.github/actions/configure-nodejs
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm run test:full

0 comments on commit 0e18b07

Please sign in to comment.