Skip to content

Commit d8befc8

Browse files
committed
Update GitHub Actions
Use node-modules linker for yarn
1 parent 2dedd1b commit d8befc8

File tree

5 files changed

+73
-13
lines changed

5 files changed

+73
-13
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
########################################################################################
2+
# "yarn install" composite action for yarn 2/3/4+ and "nodeLinker: node-modules" #
3+
#--------------------------------------------------------------------------------------#
4+
# Cache: #
5+
# - Downloaded zip archive (multi-arch, preserved across yarn.lock changes) #
6+
# - Yarn install state (discarded on yarn.lock changes) #
7+
# References: #
8+
# - bench: https://gist.github.com/belgattitude/0ecd26155b47e7be1be6163ecfbb0f0b #
9+
# - vs @setup/node: https://github.com/actions/setup-node/issues/325 #
10+
########################################################################################
11+
12+
name: 'Yarn install'
13+
description: 'Run yarn install with node_modules linker and cache enabled'
14+
15+
runs:
16+
using: 'composite'
17+
steps:
18+
- name: Expose yarn config as "$GITHUB_OUTPUT"
19+
id: yarn-config
20+
shell: bash
21+
run: |
22+
echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
23+
24+
# Yarn rotates the downloaded cache archives, @see https://github.com/actions/setup-node/issues/325
25+
# Yarn cache is also reusable between arch and os.
26+
- name: Restore yarn cache
27+
uses: actions/cache@v3
28+
id: yarn-download-cache
29+
with:
30+
path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
31+
key: yarn-download-cache-${{ hashFiles('yarn.lock') }}
32+
restore-keys: |
33+
yarn-download-cache-
34+
35+
# Invalidated on yarn.lock changes
36+
- name: Restore yarn install state
37+
id: yarn-install-state-cache
38+
uses: actions/cache@v3
39+
with:
40+
path: .yarn/ci-cache/
41+
key: ${{ runner.os }}-yarn-install-state-cache-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}
42+
43+
- name: Install dependencies
44+
shell: bash
45+
run: |
46+
yarn install --immutable --inline-builds
47+
env:
48+
# CI optimizations. Overrides yarnrc.yml options (or their defaults) in the CI action.
49+
YARN_ENABLE_GLOBAL_CACHE: 'false' # Use local cache folder to keep downloaded archives
50+
YARN_NM_MODE: 'hardlinks-local' # Hardlinks-(local|global) reduces io / node_modules size
51+
YARN_INSTALL_STATE_PATH: .yarn/ci-cache/install-state.gz # Very small speedup when lock does not change
52+
# Other environment variables
53+
HUSKY: '0' # By default do not run HUSKY install

.github/workflows/lint.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ jobs:
2929
- name: Setup Node
3030
uses: actions/setup-node@v3
3131
with:
32-
cache: yarn
33-
cache-dependency-path: yarn.lock
32+
node-version: 16
33+
34+
- name: Install yarn v3
35+
run: corepack enable && corepack prepare yarn@stable --activate
3436

3537
- name: Install Node packages
36-
run: yarn install --frozen-lockfile
38+
uses: ./.github/actions/yarn-nm-install
3739

3840
- name: Run Prettier
3941
run: yarn prettier --check .
@@ -48,11 +50,13 @@ jobs:
4850
- name: Setup Node
4951
uses: actions/setup-node@v3
5052
with:
51-
cache: yarn
52-
cache-dependency-path: yarn.lock
53+
node-version: 16
54+
55+
- name: Install yarn v3
56+
run: corepack enable && corepack prepare yarn@stable --activate
5357

5458
- name: Install Node packages
55-
run: yarn install --frozen-lockfile
59+
uses: ./.github/actions/yarn-nm-install
5660

5761
- name: Run ESLint
5862
run: yarn eslint web/js/
@@ -67,11 +71,13 @@ jobs:
6771
- name: Setup Node
6872
uses: actions/setup-node@v3
6973
with:
70-
cache: yarn
71-
cache-dependency-path: yarn.lock
74+
node-version: 16
75+
76+
- name: Install yarn v3
77+
run: corepack enable && corepack prepare yarn@stable --activate
7278

7379
- name: Install Node packages
74-
run: yarn install --frozen-lockfile
80+
uses: ./.github/actions/yarn-nm-install
7581

7682
- name: Run Stylelint
7783
run: yarn stylelint web/css/src/themes/*.css

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
.env
2020
composer.phar
2121
test/vendor/
22-
test/node_modules/
22+
**/node_modules/
2323
web/src/vendor/filp
2424
web/src/vendor/psr
2525
web/src/vendor/composer/installed.json

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Manual changes might be lost - proceed with caution!
33

44
__metadata:
5-
version: 5
5+
version: 6
66
cacheKey: 8
77

88
"@babel/code-frame@npm:^7.0.0":
@@ -1599,7 +1599,7 @@ __metadata:
15991599

16001600
"fsevents@patch:fsevents@~2.3.2#~builtin<compat/fsevents>":
16011601
version: 2.3.2
1602-
resolution: "fsevents@patch:fsevents@npm%3A2.3.2#~builtin<compat/fsevents>::version=2.3.2&hash=18f3a7"
1602+
resolution: "fsevents@patch:fsevents@npm%3A2.3.2#~builtin<compat/fsevents>::version=2.3.2&hash=df0bf1"
16031603
dependencies:
16041604
node-gyp: latest
16051605
conditions: os=darwin
@@ -3924,7 +3924,7 @@ __metadata:
39243924

39253925
"resolve@patch:resolve@^1.1.7#~builtin<compat/resolve>, resolve@patch:resolve@^1.10.0#~builtin<compat/resolve>":
39263926
version: 1.22.1
3927-
resolution: "resolve@patch:resolve@npm%3A1.22.1#~builtin<compat/resolve>::version=1.22.1&hash=07638b"
3927+
resolution: "resolve@patch:resolve@npm%3A1.22.1#~builtin<compat/resolve>::version=1.22.1&hash=c3c19d"
39283928
dependencies:
39293929
is-core-module: ^2.9.0
39303930
path-parse: ^1.0.7

0 commit comments

Comments
 (0)