Skip to content

Commit d7da866

Browse files
Merge pull request #137 from ThomasAribart/cache-node-dependencies-in-ci
chore: cache node dependencies in CI
2 parents 2820148 + eaf1029 commit d7da866

File tree

2 files changed

+55
-10
lines changed

2 files changed

+55
-10
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Install Node Dependencies
2+
description: Install dependencies using yarn
3+
inputs:
4+
node-version:
5+
required: true
6+
typescript-version:
7+
required: true
8+
runs:
9+
using: composite
10+
steps:
11+
- name: Use Node.js
12+
uses: actions/setup-node@v3
13+
with:
14+
node-version: ${{ inputs.node-version }}
15+
16+
- name: Get yarn cache directory path
17+
id: yarn-cache-dir-path
18+
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
19+
shell: bash
20+
21+
- name: Sync yarn cache
22+
uses: actions/cache@v3
23+
with:
24+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
25+
key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
26+
restore-keys: |
27+
${{ runner.os }}-yarn-
28+
29+
- name: Sync node_modules cache
30+
id: sync-node-modules-cache
31+
uses: actions/cache@v3
32+
with:
33+
path: "**/node_modules"
34+
key: ${{ runner.os }}-modules-${{ inputs.node-version }}-${{ inputs.typescript-version }}-${{ hashFiles('./yarn.lock') }}
35+
36+
- name: Install node_modules
37+
run: if [ '${{ steps.sync-node-modules-cache.outputs.cache-hit }}' != 'true' ]; then yarn install --immutable; fi
38+
shell: bash
39+
40+
- name: Override TS with correct version
41+
run: if [ '${{ steps.sync-node-modules-cache.outputs.cache-hit }}' != 'true' ]; then yarn add --dev typescript@${{ inputs.typescript-version }}; fi
42+
shell: bash

.github/workflows/pull-request.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,29 @@ on:
33
pull_request:
44
types: [opened, reopened, synchronize]
55

6+
env:
7+
CI: true
8+
69
jobs:
7-
build:
10+
build-and-test:
811
runs-on: ubuntu-latest
912
strategy:
1013
matrix:
1114
node: [16, 18]
12-
typescript: ["~4.5.5", "~4.7.4", "~4.8.3", "~4.9.5", "~5.0.4", "latest"]
15+
typescript: ["~4.5.5", "~4.6.4", "~4.7.4", "~4.8.3", "~4.9.5", "~5.0.4"]
1316
name: Node ${{ matrix.node }} / TS ${{ matrix.typescript }}
1417
steps:
15-
- name: "Checkout latest code"
16-
uses: actions/checkout@v3
18+
- uses: actions/checkout@v3
1719
with:
1820
ref: ${{ github.event.pull_request.head.sha }}
19-
- name: Set up node
20-
uses: actions/setup-node@v3
21+
# We need to fetch all branches and commits so that Nx affected has a base to compare against.
22+
fetch-depth: 0
23+
24+
- name: Install node_modules
25+
uses: ./.github/actions/install-node-modules
2126
with:
2227
node-version: ${{ matrix.node }}
23-
- name: Install dependencies
24-
run: yarn
25-
- name: Install TS at correct version
26-
run: yarn add --dev typescript@${{ matrix.typescript }}
28+
typescript-version: ${{ matrix.typescript }}
29+
2730
- name: Run tests
2831
run: yarn test

0 commit comments

Comments
 (0)