From 76d7fed3924a1e7d62d63c34e21b1396be93486c Mon Sep 17 00:00:00 2001 From: Bhav Khurana <96694482+bhav-khurana@users.noreply.github.com> Date: Fri, 8 Dec 2023 15:53:49 +0530 Subject: [PATCH] Feat: Cache npm dependencies (#1162) * Feat: Cache npm dependencies * Add required changes * Replace with npm ci * Replace with npm install * Remove continue_on_error --- .github/workflows/pull-requests.yml | 21 ++++++++++++-- .github/workflows/push.yml | 43 +++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml index b303360aff..202f555303 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/pull-requests.yml @@ -28,7 +28,22 @@ jobs: - name: Checkout the Repository uses: actions/checkout@v3 - - name: Install Dependencies + - name: Restore node_modules from cache + id: cache-npm + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + path: | + ~/.npm + node_modules + key: ${{ runner.os }}-generate-docs-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-generate-docs-${{ env.cache-name }}- + ${{ runner.os }}-generate-docs- + ${{ runner.os }}- + + - name: Install dependencies run: npm install --legacy-peer-deps - name: Run linting check @@ -71,8 +86,8 @@ jobs: uses: actions/setup-node@v3 with: node-version: '16.14.1' - - - name: resolve dependency + + - name: Resolve dependency run: npm install -g @graphql-inspector/cli - name: Clone API repository diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 2169009ec0..4e2ef1ea17 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -19,7 +19,7 @@ on: env: CODECOV_UNIQUE_NAME: CODECOV_UNIQUE_NAME-${{ github.run_id }}-${{ github.run_number }} -jobs: +jobs: Code-Coverage: runs-on: ubuntu-latest steps: @@ -27,7 +27,25 @@ jobs: - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - - run: npm install --legacy-peer-deps + + - name: Cache node modules + id: cache-npm + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + path: | + ~/.npm + node_modules + key: ${{ runner.os }}-code-coverage-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-code-coverage-${{ env.cache-name }}- + ${{ runner.os }}-code-coverage- + ${{ runner.os }}- + + - if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }} + name: List the state of node modules + run: npm install --legacy-peer-deps - run: npm run test -- --watchAll=false --coverage - name: Present and upload coverage to Codecov as ${{env.CODECOV_UNIQUE_NAME}} uses: codecov/codecov-action@v3 @@ -42,9 +60,24 @@ jobs: steps: - name: Checkout the Repository uses: actions/checkout@v3 - - - name: Install Dependencies - run: yarn install --legacy-peer-deps + + - name: Restore node_modules from cache + id: cache-npm + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + path: | + ~/.npm + node_modules + key: ${{ runner.os }}-generate-docs-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-generate-docs-${{ env.cache-name }}- + ${{ runner.os }}-generate-docs- + ${{ runner.os }}- + + name: Install dependencies + run: npm install --legacy-peer-deps - name: Install TypeScript Globally and add GraphQL tag run: yarn global add typescript