Skip to content

Commit

Permalink
Merge pull request #137 from ThomasAribart/cache-node-dependencies-in-ci
Browse files Browse the repository at this point in the history
chore: cache node dependencies in CI
  • Loading branch information
ThomasAribart committed May 11, 2023
2 parents 2820148 + eaf1029 commit d7da866
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
42 changes: 42 additions & 0 deletions .github/actions/install-node-modules/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Install Node Dependencies
description: Install dependencies using yarn
inputs:
node-version:
required: true
typescript-version:
required: true
runs:
using: composite
steps:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
shell: bash

- name: Sync yarn cache
uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Sync node_modules cache
id: sync-node-modules-cache
uses: actions/cache@v3
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ inputs.node-version }}-${{ inputs.typescript-version }}-${{ hashFiles('./yarn.lock') }}

- name: Install node_modules
run: if [ '${{ steps.sync-node-modules-cache.outputs.cache-hit }}' != 'true' ]; then yarn install --immutable; fi
shell: bash

- name: Override TS with correct version
run: if [ '${{ steps.sync-node-modules-cache.outputs.cache-hit }}' != 'true' ]; then yarn add --dev typescript@${{ inputs.typescript-version }}; fi
shell: bash
23 changes: 13 additions & 10 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@ on:
pull_request:
types: [opened, reopened, synchronize]

env:
CI: true

jobs:
build:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [16, 18]
typescript: ["~4.5.5", "~4.7.4", "~4.8.3", "~4.9.5", "~5.0.4", "latest"]
typescript: ["~4.5.5", "~4.6.4", "~4.7.4", "~4.8.3", "~4.9.5", "~5.0.4"]
name: Node ${{ matrix.node }} / TS ${{ matrix.typescript }}
steps:
- name: "Checkout latest code"
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up node
uses: actions/setup-node@v3
# We need to fetch all branches and commits so that Nx affected has a base to compare against.
fetch-depth: 0

- name: Install node_modules
uses: ./.github/actions/install-node-modules
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: yarn
- name: Install TS at correct version
run: yarn add --dev typescript@${{ matrix.typescript }}
typescript-version: ${{ matrix.typescript }}

- name: Run tests
run: yarn test

0 comments on commit d7da866

Please sign in to comment.