From edf4e605e5a4bff79d12028708b78eb7c19529e6 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Mon, 14 Nov 2022 02:43:27 +0100 Subject: [PATCH] Cache expensive CI steps (#21) Speed-up pipeline by caching eslint, prettier, TypeScript, node_modules --- .github/workflows/build.yml | 53 +++++++++++++++++++++++++++++++++++++ package.json | 2 +- tsconfig.json | 4 ++- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a8d70e1..bbe3252 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,8 +31,61 @@ jobs: with: node-version: ${{ matrix.node-version }} + - name: Cache node modules + id: cache-npm + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + path: node_modules + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json,**/package.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: Cache eslint + id: cache-eslint + uses: actions/cache@v3 + env: + cache-name: cache-eslint + with: + path: .eslintcache + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json,**/package.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: Cache TypeScript + id: cache-typescript + uses: actions/cache@v3 + env: + cache-name: cache-typescript + with: + path: .tsbuildinfo + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json,**/package.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: Cache prettier + id: cache-prettier + uses: actions/cache@v3 + env: + cache-name: cache-prettier + with: + path: node_modules/.cache/prettier/.prettier-cache + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json,**/package.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + - name: Install dependencies run: npm install + if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }} - name: Lint the project run: npm run lint diff --git a/package.json b/package.json index 6b83298..61532f2 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "main": "dist/src/index.js", "scripts": { - "lint": "ifNotCi() { test \"$CI\" && echo \"$2\" || echo \"$1\"; }; `npm bin`/tsc --noEmit && `npm bin`/prettier --ignore-path=.gitignore `ifNotCi --write --check` '**/**.{ts,js,json}' && `npm bin`/eslint `ifNotCi --fix` --ignore-path=.gitignore '**/**.{ts,js,json}'", + "lint": "ifNotCi() { test \"$CI\" && echo \"$2\" || echo \"$1\"; }; `npm bin`/tsc --noEmit && `npm bin`/prettier --ignore-path=.gitignore `ifNotCi --write \"--check --cache --cache-strategy content\"` '**/**.{ts,js,json}' && `npm bin`/eslint `ifNotCi --fix \"--cache --cache-strategy content\"` --ignore-path=.gitignore '**/**.{ts,js,json}'", "start": "npm run build && npm run link && nodemon", "test": "ifNotCi() { test \"$CI\" && echo \"$2\" || echo \"$1\"; }; npm run code-generation && `npm bin`/jest `ifNotCi --watchAll`", "link": "npm install --no-save file:///$PWD/", diff --git a/tsconfig.json b/tsconfig.json index 85653a1..e72bbd6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,9 @@ "esModuleInterop": true, "importsNotUsedAsValues": "error", "noImplicitAny": true, - "resolveJsonModule": true + "resolveJsonModule": true, + "tsBuildInfoFile": ".tsbuildinfo", + "incremental": true }, "include": ["src/", "tests/"], "exclude": []