Skip to content

Commit

Permalink
ci: improve yarn cache handling
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon committed May 11, 2023
1 parent fa248bf commit d14cc7c
Show file tree
Hide file tree
Showing 6 changed files with 940 additions and 11 deletions.
54 changes: 47 additions & 7 deletions .github/actions/install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,67 @@ inputs:
required: false
description: drive installation mode
default: "false"
node-version:
required: true
description: node version

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
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
with:
path: node_modules
key: yarn-nm-cache-${{ runner.os }}-${{ inputs.node-version }}-${{ github.ref }}-${{ hashFiles('**/yarn.lock', '.yarnrc.yml') }}

- name: Cache yarn
- 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: .yarn/ci-cache
key: yarn-install-state-cache-${{ runner.os }}-${{ inputs.node-version }}-${{ github.ref }}-${{ hashFiles('**/yarn.lock', '.yarnrc.yml') }}

- name: Install dependencies in production mode
if: ${{ inputs.prod-context == 'true' }}
run: yarn install --immutable --immutable-cache --check-cache --frozen-lockfile --prod
run: yarn install --immutable --immutable-cache --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/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
run: yarn install --immutable --immutable-cache --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/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
4 changes: 4 additions & 0 deletions .github/linters/.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
"Cherfaoui",
"Colladon",
"Commitlint",
"Corepack",
"corepack",
"FORCEIGNORE",
"FORCEINCLUDE",
"FULLNAME",
"Flexi",
"hardlinks",
"Iframe",
"METAFILE",
"Mehdi",
Expand Down Expand Up @@ -141,6 +144,7 @@
"weblinks",
"wlens",
"xmlbuilder",
"yarnrc",
"\u00c0gain"
]
}
13 changes: 11 additions & 2 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ jobs:
fetch-depth: 0

- name: Setup node
uses: ./.github/actions/install
uses: actions/setup-node@v3
with:
node-version: 16

- name: Lint commits
uses: wagoid/commitlint-github-action@v5
Expand All @@ -52,6 +54,11 @@ jobs:
with:
node-version: 16
registry-url: https://registry.npmjs.org/

- name: Setup dependencies, cache and install
uses: ./.github/actions/install
with:
node-version: 16

- name: Check outdated dependencies
run: yarn outdated
Expand Down Expand Up @@ -103,6 +110,8 @@ jobs:

- name: Setup dependencies, cache and install
uses: ./.github/actions/install
with:
node-version: 16

- name: Build plugin
run: yarn pack
Expand Down Expand Up @@ -146,7 +155,7 @@ jobs:

- name: Install dependencies in production mode
working-directory: ./plugin
run: yarn install --immutable --immutable-cache --check-cache --frozen-lockfile --prod
run: yarn install --immutable --immutable-cache --check-cache --prod
shell: bash

- name: Install build dependencies
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:

- name: Setup dependencies, cache and install
uses: ./.github/actions/install
with:
node-version: 16

- name: Build plugin
run: yarn pack
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/node_modules
/reports
/lib
/.yarn
/.nyc_output
/.yarn/cache
install-state.gz
*-debug.log
*-error.log
sfdx-git-delta-*.tgz
/.nyc_output
stderr*.txt
stdout*.txt
# stryker temp files
Expand Down
873 changes: 873 additions & 0 deletions .yarn/releases/yarn-3.5.1.cjs

Large diffs are not rendered by default.

0 comments on commit d14cc7c

Please sign in to comment.