From 8b2e5f14a4c64cb5150678d51f55da937e902836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Colladon?= Date: Thu, 11 May 2023 12:04:02 +0200 Subject: [PATCH] ci: improve yarn cache handling --- .github/actions/install/action.yml | 46 ++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/.github/actions/install/action.yml b/.github/actions/install/action.yml index 02972a98..a4d2ea86 100644 --- a/.github/actions/install/action.yml +++ b/.github/actions/install/action.yml @@ -11,23 +11,59 @@ inputs: runs: using: composite steps: + - name: ⚙️ Enable Corepack + run: corepack enable + shell: bash + - name: Cache prep - id: yarn-cache-dir-path - run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT + id: yarn-config + run: | + echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT + echo "CURRENT_BRANCH=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's,/,-,g')" >> $GITHUB_OUTPUT shell: bash + env: + YARN_ENABLE_GLOBAL_CACHE: 'false' - - name: Cache yarn + - name: Restore yarn cache + uses: actions/cache@v3 + with: + path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }} + key: yarn-download-cache-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }} + restore-keys: | + yarn-download-cache- + + - name: Restore node_modules + id: yarn-nm-cache + uses: actions/cache@v3 + with: + path: ${{ inputs.cwd }}/**/node_modules + key: yarn-nm-cache-${{ runner.os }}-${{ inputs.node-version }}-${{ steps.yarn-config.outputs.CURRENT_BRANCH }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }} + + - name: Restore yarn install state + id: yarn-install-state-cache uses: actions/cache@v3 with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: cache-${{ inputs.node-version }}-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }} + path: ${{ inputs.cwd }}/.yarn/ci-cache + key: yarn-install-state-cache-${{ runner.os }}-${{ inputs.node-version }}-${{ steps.yarn-config.outputs.CURRENT_BRANCH }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }} - name: Install dependencies in production mode if: ${{ inputs.prod-context == 'true' }} run: yarn install --immutable --immutable-cache --check-cache --frozen-lockfile --prod shell: bash + env: + # Overrides/align yarnrc.yml options (v3, v4) for a CI context + YARN_ENABLE_GLOBAL_CACHE: 'false' # Use local cache folder to keep downloaded archives + YARN_NM_MODE: 'hardlinks-local' # Reduce node_modules size + YARN_INSTALL_STATE_PATH: '.yarn/ci-cache/install-state.gz' # Might speed up resolution step when node_modules present + # Other environment variables + HUSKY: '0' # By default do not run HUSKY install - name: Install dependencies in integration mode if: ${{ inputs.prod-context == 'false' }} run: yarn install --immutable --immutable-cache --check-cache --frozen-lockfile shell: bash + env: + # Overrides/align yarnrc.yml options (v3, v4) for a CI context + YARN_ENABLE_GLOBAL_CACHE: 'false' # Use local cache folder to keep downloaded archives + YARN_NM_MODE: 'hardlinks-local' # Reduce node_modules size + YARN_INSTALL_STATE_PATH: '.yarn/ci-cache/install-state.gz' # Might speed up resolution step when node_modules present