Skip to content

Commit 8769d41

Browse files
committed
chore: use different install
1 parent beb4b3e commit 8769d41

File tree

2 files changed

+121
-21
lines changed

2 files changed

+121
-21
lines changed

.github/actions/setup/action.yml

Lines changed: 116 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,125 @@
1-
name: Setup
2-
description: Setup Node.js and install dependencies
1+
# https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a
2+
3+
########################################################################################
4+
# "yarn install" composite action for yarn 3/4+ and "nodeLinker: node-modules" #
5+
#--------------------------------------------------------------------------------------#
6+
# Requirement: @setup/node should be run before #
7+
# #
8+
# Usage in workflows steps: #
9+
# #
10+
# - name: 📥 Monorepo install #
11+
# uses: ./.github/actions/yarn-nm-install #
12+
# with: #
13+
# enable-corepack: false # (default = 'false') #
14+
# cwd: ${{ github.workspace }}/apps/my-app # (default = '.') #
15+
# cache-prefix: add cache key prefix # (default = 'default') #
16+
# cache-node-modules: false # (default = 'false') #
17+
# cache-install-state: false # (default = 'false') #
18+
# #
19+
# Reference: #
20+
# - latest: https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a #
21+
# #
22+
# Versions: #
23+
# - 1.1.0 - 22-07-2023 - Option to enable npm global cache folder. #
24+
# - 1.0.4 - 15-07-2023 - Fix corepack was always enabled. #
25+
# - 1.0.3 - 05-07-2023 - YARN_ENABLE_MIRROR to false (speed up cold start) #
26+
# - 1.0.2 - 02-06-2023 - install-state default to false #
27+
# - 1.0.1 - 29-05-2023 - cache-prefix doc #
28+
# - 1.0.0 - 27-05-2023 - new input: cache-prefix #
29+
########################################################################################
30+
31+
name: 'Monorepo install (yarn)'
32+
description: 'Run yarn install with node_modules linker and cache enabled'
33+
inputs:
34+
cwd:
35+
description: "Changes node's process.cwd() if the project is not located on the root. Default to process.cwd()"
36+
required: false
37+
default: '.'
38+
cache-prefix:
39+
description: 'Add a specific cache-prefix'
40+
required: false
41+
default: 'default'
42+
cache-npm-cache:
43+
description: 'Cache npm global cache folder often used by node-gyp, prebuild binaries (invalidated on lock/os/node-version)'
44+
required: false
45+
default: 'true'
46+
cache-node-modules:
47+
description: 'Cache node_modules, might speed up link step (invalidated lock/os/node-version/branch)'
48+
required: false
49+
default: 'false'
50+
cache-install-state:
51+
description: 'Cache yarn install state, might speed up resolution step when node-modules cache is activated (invalidated lock/os/node-version/branch)'
52+
required: false
53+
default: 'false'
54+
enable-corepack:
55+
description: 'Enable corepack'
56+
required: false
57+
default: 'true'
358

459
runs:
5-
using: composite
60+
using: 'composite'
61+
662
steps:
7-
- name: Setup Node.js
8-
uses: actions/setup-node@v3
9-
with:
10-
node-version-file: .nvmrc
63+
- name: ⚙️ Enable Corepack
64+
if: inputs.enable-corepack == 'true'
65+
shell: bash
66+
working-directory: ${{ inputs.cwd }}
67+
run: corepack enable
68+
69+
- name: ⚙️ Expose yarn config as "$GITHUB_OUTPUT"
70+
id: yarn-config
71+
shell: bash
72+
working-directory: ${{ inputs.cwd }}
73+
env:
74+
YARN_ENABLE_GLOBAL_CACHE: 'false'
75+
run: |
76+
echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
77+
echo "CURRENT_NODE_VERSION="node-$(node --version)"" >> $GITHUB_OUTPUT
78+
echo "CURRENT_BRANCH=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's,/,-,g')" >> $GITHUB_OUTPUT
79+
echo "NPM_GLOBAL_CACHE_FOLDER=$(npm config get cache)" >> $GITHUB_OUTPUT
1180
12-
- name: Cache dependencies
13-
id: yarn-cache
81+
- name: ♻️ Restore yarn cache
1482
uses: actions/cache@v3
83+
id: yarn-download-cache
1584
with:
16-
path: |
17-
**/node_modules
18-
.yarn/install-state.gz
19-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/package.json') }}
85+
path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
86+
key: yarn-download-cache-${{ inputs.cache-prefix }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}
2087
restore-keys: |
21-
${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
22-
${{ runner.os }}-yarn-
88+
yarn-download-cache-${{ inputs.cache-prefix }}-
89+
90+
- name: ♻️ Restore node_modules
91+
if: inputs.cache-node-modules == 'true'
92+
id: yarn-nm-cache
93+
uses: actions/cache@v3
94+
with:
95+
path: ${{ inputs.cwd }}/**/node_modules
96+
key: yarn-nm-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.yarn-config.outputs.CURRENT_BRANCH }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}
97+
98+
- name: ♻️ Restore global npm cache folder
99+
if: inputs.cache-npm-cache == 'true'
100+
id: npm-global-cache
101+
uses: actions/cache@v3
102+
with:
103+
path: ${{ steps.yarn-config.outputs.NPM_GLOBAL_CACHE_FOLDER }}
104+
key: npm-global-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}
105+
106+
- name: ♻️ Restore yarn install state
107+
if: inputs.cache-install-state == 'true' && inputs.cache-node-modules == 'true'
108+
id: yarn-install-state-cache
109+
uses: actions/cache@v3
110+
with:
111+
path: ${{ inputs.cwd }}/.yarn/ci-cache
112+
key: yarn-install-state-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.yarn-config.outputs.CURRENT_BRANCH }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}
23113

24-
- name: Install dependencies
25-
if: steps.yarn-cache.outputs.cache-hit != 'true'
26-
run: yarn install --immutable
114+
- name: 📥 Install dependencies
27115
shell: bash
116+
working-directory: ${{ inputs.cwd }}
117+
run: yarn install --immutable --inline-builds
118+
env:
119+
# Overrides/align yarnrc.yml options (v3, v4) for a CI context
120+
YARN_ENABLE_GLOBAL_CACHE: 'false' # Use local cache folder to keep downloaded archives
121+
YARN_ENABLE_MIRROR: 'false' # Prevent populating global cache for caches misses (local cache only)
122+
YARN_NM_MODE: 'hardlinks-local' # Reduce node_modules size
123+
YARN_INSTALL_STATE_PATH: '.yarn/ci-cache/install-state.gz' # Might speed up resolution step when node_modules present
124+
# Other environment variables
125+
HUSKY: '0' # By default do not run HUSKY install

.github/workflows/comment-diffs.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ jobs:
2828
with:
2929
node-version-file: .nvmrc
3030

31-
- name: Install dependencies
32-
run: yarn install --immutable
33-
shell: bash
31+
- name: 📥 Monorepo install
32+
uses: ./.github/actions/setup
33+
with:
34+
cache-node-modules: true
35+
cache-install-state: true
3436

3537
- name: Build crnl
3638
run: |

0 commit comments

Comments
 (0)