From 4bfd63afef3b4139bb797ca6e5a9895138092417 Mon Sep 17 00:00:00 2001 From: zomars Date: Mon, 20 Feb 2023 14:51:46 -0700 Subject: [PATCH] DRY --- .github/actions/yarn-install/action.yml | 26 +++++++++++++++++++++++++ .github/workflows/pr.yml | 5 ++--- .github/workflows/yarn-install.yml | 19 ++---------------- 3 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 .github/actions/yarn-install/action.yml diff --git a/.github/actions/yarn-install/action.yml b/.github/actions/yarn-install/action.yml new file mode 100644 index 0000000000..92dff9f81b --- /dev/null +++ b/.github/actions/yarn-install/action.yml @@ -0,0 +1,26 @@ +name: Yarn install +description: "Install all NPM dependencies, caches them and restores if necessary" +inputs: + node_version: + required: true + description: "The node_version used to run this" +runs: + using: "composite" + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.node_version }} + - name: node_modules cache + id: node-modules-cache + uses: actions/cache@v3 + env: + cache-name: node-modules-yarn + cache-key: ${{ inputs.node_version }}-${{ hashFiles('yarn.lock') }} + with: + path: node_modules + key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.cache-key }} + restore-keys: ${{ runner.os }}-${{ env.cache-name }}- + - name: Yarn install + if: steps.node-modules-cache.outputs.cache-hit != 'true' + run: yarn install --prefer-offline --frozen-lockfile diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 7d17ab24a2..7a7c7cdbe1 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -50,10 +50,9 @@ jobs: # change this if your nextjs app does not live at the root of the repo working-directory: ./apps/web/ steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: ./.github/actions/yarn-install with: - node-version: ${{ env.node_version }} + node_version: ${{ env.node_version }} - name: Restore node_modules from cache uses: actions/cache@v3 env: diff --git a/.github/workflows/yarn-install.yml b/.github/workflows/yarn-install.yml index f01ca72297..00c0074e2c 100644 --- a/.github/workflows/yarn-install.yml +++ b/.github/workflows/yarn-install.yml @@ -14,21 +14,6 @@ jobs: group: yarn-install-${{ github.sha }} timeout-minutes: 10 steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: ./.github/actions/yarn-install with: - node-version: ${{ secrets.NODE_VERSION }} - # node_module cache helps to avoid 1 minute copying from yarn cache on every job run - - name: node_modules cache - id: node-modules-cache - uses: actions/cache@v3 - env: - cache-name: node-modules-yarn - cache-key: ${{ secrets.NODE_VERSION }}-${{ hashFiles('yarn.lock') }} - with: - path: node_modules - key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.cache-key }} - restore-keys: ${{ runner.os }}-${{ env.cache-name }}- - - name: Yarn install - if: steps.node-modules-cache.outputs.cache-hit != 'true' - run: yarn install --prefer-offline --frozen-lockfile + node_version: ${{ secrets.node_version }}