Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Commit

Permalink
ci: optimized caching for yarn 3
Browse files Browse the repository at this point in the history
temporary workaround as actions/setup-node@v3 does not support yarn berry

see https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a
and actions/setup-node#488 (comment)
  • Loading branch information
nlm-pro committed Dec 4, 2022
1 parent cefe1e1 commit f9920ac
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 45 deletions.
53 changes: 53 additions & 0 deletions .github/actions/yarn-nm-install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
########################################################################################
# "yarn install" composite action for yarn 2/3/4+ and "nodeLinker: node-modules" #
#--------------------------------------------------------------------------------------#
# Cache: #
# - Downloaded zip archive (multi-arch, preserved across yarn.lock changes) #
# - Yarn install state (discarded on yarn.lock changes) #
# References: #
# - bench: https://gist.github.com/belgattitude/0ecd26155b47e7be1be6163ecfbb0f0b #
# - vs @setup/node: https://github.com/actions/setup-node/issues/325 #
########################################################################################

name: "Yarn install"
description: "Run yarn install with node_modules linker and cache enabled"

runs:
using: "composite"
steps:
- name: Expose yarn config as "$GITHUB_OUTPUT"
id: yarn-config
shell: bash
run: |
echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
# Yarn rotates the downloaded cache archives, @see https://github.com/actions/setup-node/issues/325
# Yarn cache is also reusable between arch and os.
- name: Restore yarn cache
uses: actions/cache@v3
id: yarn-download-cache
with:
path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
key: yarn-download-cache-${{ hashFiles('yarn.lock') }}
restore-keys: |
yarn-download-cache-
# Invalidated on yarn.lock changes
- name: Restore yarn install state
id: yarn-install-state-cache
uses: actions/cache@v3
with:
path: .yarn/ci-cache/
key: ${{ runner.os }}-yarn-install-state-cache-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}

- name: Install dependencies
shell: bash
run: |
yarn install --immutable --inline-builds
env:
# CI optimizations. Overrides yarnrc.yml options (or their defaults) in the CI action.
YARN_ENABLE_GLOBAL_CACHE: "false" # Use local cache folder to keep downloaded archives
YARN_NM_MODE: "hardlinks-local" # Hardlinks-(local|global) reduces io / node_modules size
YARN_INSTALL_STATE_PATH: .yarn/ci-cache/install-state.gz # Very small speedup when lock does not change
# Other environment variables
HUSKY: "0" # By default do not run HUSKY install
11 changes: 2 additions & 9 deletions .github/workflows/audit-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,12 @@ jobs:
python-version: "3.x"

- name: Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: "16.18.1"
cache: "yarn"

- name: Setup Yarn
run: |
corepack enable
yarn plugin import workspace-tools
yarn --version

- name: Install dependencies
run: yarn install
uses: ./.github/actions/yarn-nm-install

- name: Build
run: |
Expand Down
11 changes: 2 additions & 9 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,12 @@ jobs:
python-version: "3.x"

- name: Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: "16.18.1"
cache: "yarn"

- name: Setup Yarn
run: |
corepack enable
yarn plugin import workspace-tools
yarn --version

- name: Install dependencies
run: yarn install
uses: ./.github/actions/yarn-nm-install

- name: Build
run: |
Expand Down
11 changes: 2 additions & 9 deletions .github/workflows/deploy-to-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,12 @@ jobs:
python-version: "3.x"

- name: Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: "16.18.1"
cache: "yarn"

- name: Setup Yarn
run: |
corepack enable
yarn plugin import workspace-tools
yarn --version

- name: Install dependencies
run: yarn install
uses: ./.github/actions/yarn-nm-install

- name: Build
run: |
Expand Down
11 changes: 2 additions & 9 deletions .github/workflows/firebase-hosting-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,12 @@ jobs:
python-version: "3.x"

- name: Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: "16.18.1"
cache: "yarn"

- name: Setup Yarn
run: |
corepack enable
yarn plugin import workspace-tools
yarn --version

- name: Install dependencies
run: yarn install
uses: ./.github/actions/yarn-nm-install

- name: Build
run: yarn run build
Expand Down
11 changes: 2 additions & 9 deletions .github/workflows/subtrees.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,12 @@ jobs:
uses: actions/checkout@v1

- name: Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: "16.18.1"
cache: "yarn"

- name: Setup Yarn
run: |
corepack enable
yarn --version

- name: Install dependencies
# FIXME: only install root dependencies and don't run postinstall
run: yarn install
uses: ./.github/actions/yarn-nm-install

- uses: webfactory/ssh-agent@v0.4.1
with:
Expand Down

0 comments on commit f9920ac

Please sign in to comment.