Skip to content

Commit

Permalink
build: simplify yarn cache
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon committed Jun 2, 2023
1 parent fc37f92 commit 497e8ad
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 92 deletions.
63 changes: 7 additions & 56 deletions .github/actions/install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,21 @@
name: Install
description: Install dependencies

inputs:
prod-context:
required: false
description: drive installation mode
default: "false"

runs:
using: composite
steps:
- name: ⚙️ Enable Corepack
run: corepack enable
shell: bash

- name: Cache prep
id: yarn-config
run: |
echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
echo "node-version="node-$(node --version)"" >> $GITHUB_OUTPUT
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "yarn-cache=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
shell: bash
env:
YARN_ENABLE_GLOBAL_CACHE: 'false'

- name: Restore yarn cache
uses: actions/cache@v3
with:
path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
key: yarn-download-cache-${{ hashFiles('**/yarn.lock', '.yarnrc.yml') }}
restore-keys: |
yarn-download-cache-

- name: Restore node_modules
id: yarn-nm-cache
uses: actions/cache@v3
- uses: actions/cache@v3
with:
path: node_modules
key: yarn-nm-cache-${{ runner.os }}-${{ steps.yarn-config.outputs.node-version }}-${{ github.ref }}-${{ hashFiles('**/yarn.lock', '.yarnrc.yml') }}

- name: Restore yarn install state
id: yarn-install-state-cache
uses: actions/cache@v3
with:
path: .yarn/
key: yarn-install-state-cache-${{ runner.os }}-${{ steps.yarn-config.outputs.node-version }}-${{ github.ref }}-${{ hashFiles('**/yarn.lock', '.yarnrc.yml') }}

- name: Install dependencies in production mode
if: ${{ inputs.prod-context == 'true' }}
run: yarn install --immutable --check-cache --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/install-state.gz' # Might speed up resolution step when node_modules present
# Other environment variables
HUSKY: '0' # By default do not run HUSKY install
path: ${{ steps.yarn-cache-dir-path.outputs.yarn-cache }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

- name: Install dependencies in integration mode
if: ${{ inputs.prod-context == 'false' }}
- name: Install dependencies
run: yarn install --immutable --check-cache
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/install-state.gz' # Might speed up resolution step when node_modules present
# Other environment variables
HUSKY: '0' # By default do not run HUSKY install
1 change: 1 addition & 0 deletions .github/linters/.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"scontrols",
"sfdx",
"sgdignore",
"shellcheck",
"staticresources",
"stefanzweifel",
"struc",
Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# shellcheck disable=SC2086
---
name: CI

Expand Down Expand Up @@ -152,14 +153,20 @@ jobs:
with:
node-version: ${{ matrix.node }}

- name: Install dependencies in production mode
- name: Get yarn cache directory path
working-directory: ./plugin
run: yarn workspaces focus --all --production
id: yarn-cache-dir-path
run: echo "yarn-cache=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
shell: bash

- name: Install build dependencies
- uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.yarn-cache }}
key: ${{ runner.os }}-${{ matrix.node }}-yarn-${{ hashFiles('**/yarn.lock') }}

- name: Install dependencies
working-directory: ./plugin
run: yarn add @salesforce/dev-config typescript
run: yarn install --immutable --check-cache

- name: Build plugin
working-directory: ./plugin
Expand Down
28 changes: 0 additions & 28 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

This file was deleted.

5 changes: 1 addition & 4 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
nodeLinker: node-modules

npmRegistryServer: "https://registry.npmjs.org/"
npmPublishRegistry: "https://registry.npmjs.org/"

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"
npmRegistryServer: "https://registry.npmjs.org/"

yarnPath: .yarn/releases/yarn-3.5.1.cjs

0 comments on commit 497e8ad

Please sign in to comment.