Skip to content

Commit

Permalink
Add caching of node_modules and linter caches to Github Actions (#4)
Browse files Browse the repository at this point in the history
Also swapped build/test steps so we don't need to build the packages for tests and then rebuild again in the build step.

Decreased time from 9-10min to 7-8min with package.json or package-lock.json changes and 3-4min with no package.json or package-lock.json changes
  • Loading branch information
mattrunyon authored Apr 30, 2021
1 parent 2decc54 commit aec4aff
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 8 deletions.
40 changes: 35 additions & 5 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,56 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules

- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
# If no package-lock.json or package.json files have changed, it should be safe to restore all node_modules as they were
path: |
node_modules
packages/*/node_modules
key: ${{ runner.os }}-modules-${{ hashFiles('package.json', 'packages/*/package.json', 'package-lock.json', 'packages/*/package-lock.json') }}

- name: Cache npm cache
uses: actions/cache@v2
env:
cache-name: cache-node-modules
cache-name: cache-npm-cache
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('package-lock.json', 'packages/*/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Cache linter caches
uses: actions/cache@v2
with:
path: |
.eslintcache
packages/*/.eslintcache
.stylelintcache
packages/*/.stylelintcache
key: ${{ runner.os }}-lintcache-${{ github.head_ref }}
restore-keys: |
${{ runner.os }}-lintcache-
${{ runner.os }}-
# Only need to install and bootstrap deps if package-locks changed
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci
- name: Test
run: npm run test:ci

- name: Build
run: npm run build

- name: Test
run: npm run test:ci
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"clean:build": "lerna run clean --stream",
"clean:modules": "lerna clean --yes",
"clean": "npm run clean:build && npm run clean:modules",
"bootstrap": "lerna bootstrap --hoist",
"bootstrap": "lerna bootstrap --hoist -- --no-audit --prefer-offline",
"build": "lerna run build --stream",
"build:app": "lerna run --scope=@deephaven/code-studio build",
"build:packages": "lerna run --ignore=@deephaven/code-studio build --stream",
Expand All @@ -19,9 +19,8 @@
"start:app": "lerna run start --scope=@deephaven/code-studio --stream",
"start:packages": "lerna run watch --ignore=@deephaven/code-studio --stream --parallel",
"prestart": "lerna run prestart --stream",
"pretest:ci": "npm run build:packages",
"test": "lerna run test --stream --parallel",
"test:ci": "lerna run test:ci --stream --parallel",
"test:ci": "lerna run test:ci --stream -- -- --maxWorkers=2",
"sync-version": "lerna version ${DEEPHAVEN_VERSION:-error} --no-git-tag-version --yes",
"publish": "lerna publish"
},
Expand Down
1 change: 1 addition & 0 deletions packages/code-studio/src/test/eslint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ it('eslint', async () => {
const eslint = new ESLint({
extensions: ['js', 'jsx', 'ts', 'tsx'],
cache: true,
cacheStrategy: 'content',
});
const results = await eslint.lintFiles('./src');
const formatter = await eslint.loadFormatter();
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/test/eslint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ it('eslint', async () => {
const eslint = new ESLint({
extensions: ['js', 'jsx', 'ts', 'tsx'],
cache: true,
cacheStrategy: 'content',
});
const results = await eslint.lintFiles('./src');
const formatter = await eslint.loadFormatter();
Expand Down
1 change: 1 addition & 0 deletions packages/jsapi-shim/src/test/eslint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ it('eslint', async () => {
const eslint = new ESLint({
extensions: ['js', 'jsx', 'ts', 'tsx'],
cache: true,
cacheStrategy: 'content',
});
const results = await eslint.lintFiles('./src');
const formatter = await eslint.loadFormatter();
Expand Down
1 change: 1 addition & 0 deletions packages/log/src/test/eslint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ it('eslint', async () => {
const eslint = new ESLint({
extensions: ['js', 'jsx', 'ts', 'tsx'],
cache: true,
cacheStrategy: 'content',
});
const results = await eslint.lintFiles('./src');
const formatter = await eslint.loadFormatter();
Expand Down
1 change: 1 addition & 0 deletions packages/react-hooks/src/test/eslint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ it('eslint', async () => {
const eslint = new ESLint({
extensions: ['js', 'jsx', 'ts', 'tsx'],
cache: true,
cacheStrategy: 'content',
});
const results = await eslint.lintFiles('./src');
const formatter = await eslint.loadFormatter();
Expand Down
1 change: 1 addition & 0 deletions packages/utils/src/test/eslint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ it('eslint', async () => {
const eslint = new ESLint({
extensions: ['js', 'jsx', 'ts', 'tsx'],
cache: true,
cacheStrategy: 'content',
});
const results = await eslint.lintFiles('./src');
const formatter = await eslint.loadFormatter();
Expand Down

0 comments on commit aec4aff

Please sign in to comment.