From 560b89b7987dc62a48c706465ba29efca2eebbb3 Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Sat, 1 Jan 2022 03:30:40 +0800 Subject: [PATCH] chore: cache dependencies --- .github/workflows/test.yml | 52 ++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 27067b68a..cbf3c6013 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,19 +4,49 @@ on: [push, pull_request] jobs: build: - - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} strategy: matrix: - node-version: [14.x, 16.x] + node-version: [14.x] + os: [ubuntu-latest] steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - run: npm i -g yarn - - run: yarn - - run: yarn prerelease + - uses: actions/checkout@v2 + + # install node + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + # install yarn + - run: npm i -g yarn + + # https://github.com/actions/cache/blob/main/examples.md#node---yarn + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + + - name: Cache yarn cache dir + uses: actions/cache@v2 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + # https://github.com/actions/cache/blob/main/examples.md#node---lerna + - name: Cache node_modules + uses: actions/cache@v2 + with: + path: | + node_modules + */*/node_modules + key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }} + + - run: yarn + - run: yarn build + - run: yarn pretest + - run: yarn test