diff --git a/.github/actions/configure-nodejs/action.yml b/.github/actions/configure-nodejs/action.yml new file mode 100644 index 0000000..9976ee1 --- /dev/null +++ b/.github/actions/configure-nodejs/action.yml @@ -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 diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index c3098df..57a9523 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -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