Просмотр исходного кода

Update GitHub Actions
Use node-modules linker for yarn

Jakob Bouchard 3 лет назад
Родитель
Сommit
d8befc8477
5 измененных файлов с 73 добавлено и 13 удалено
  1. 53 0
      .github/actions/yarn-nm-install/action.yml
  2. 15 9
      .github/workflows/lint.yml
  3. 1 1
      .gitignore
  4. 1 0
      .yarnrc.yml
  5. 3 3
      yarn.lock

+ 53 - 0
.github/actions/yarn-nm-install/action.yml

@@ -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

+ 15 - 9
.github/workflows/lint.yml

@@ -29,11 +29,13 @@ jobs:
       - name: Setup Node
         uses: actions/setup-node@v3
         with:
-          cache: yarn
-          cache-dependency-path: yarn.lock
+          node-version: 16
+
+      - name: Install yarn v3
+        run: corepack enable && corepack prepare yarn@stable --activate
 
       - name: Install Node packages
-        run: yarn install --frozen-lockfile
+        uses: ./.github/actions/yarn-nm-install
 
       - name: Run Prettier
         run: yarn prettier --check .
@@ -48,11 +50,13 @@ jobs:
       - name: Setup Node
         uses: actions/setup-node@v3
         with:
-          cache: yarn
-          cache-dependency-path: yarn.lock
+          node-version: 16
+
+      - name: Install yarn v3
+        run: corepack enable && corepack prepare yarn@stable --activate
 
       - name: Install Node packages
-        run: yarn install --frozen-lockfile
+        uses: ./.github/actions/yarn-nm-install
 
       - name: Run ESLint
         run: yarn eslint web/js/
@@ -67,11 +71,13 @@ jobs:
       - name: Setup Node
         uses: actions/setup-node@v3
         with:
-          cache: yarn
-          cache-dependency-path: yarn.lock
+          node-version: 16
+
+      - name: Install yarn v3
+        run: corepack enable && corepack prepare yarn@stable --activate
 
       - name: Install Node packages
-        run: yarn install --frozen-lockfile
+        uses: ./.github/actions/yarn-nm-install
 
       - name: Run Stylelint
         run: yarn stylelint web/css/src/themes/*.css

+ 1 - 1
.gitignore

@@ -19,7 +19,7 @@
 .env
 composer.phar
 test/vendor/
-test/node_modules/
+**/node_modules/
 web/src/vendor/filp
 web/src/vendor/psr
 web/src/vendor/composer/installed.json

+ 1 - 0
.yarnrc.yml

@@ -0,0 +1 @@
+nodeLinker: node-modules

+ 3 - 3
yarn.lock

@@ -2,7 +2,7 @@
 # Manual changes might be lost - proceed with caution!
 
 __metadata:
-  version: 5
+  version: 6
   cacheKey: 8
 
 "@babel/code-frame@npm:^7.0.0":
@@ -1599,7 +1599,7 @@ __metadata:
 
 "fsevents@patch:fsevents@~2.3.2#~builtin<compat/fsevents>":
   version: 2.3.2
-  resolution: "fsevents@patch:fsevents@npm%3A2.3.2#~builtin<compat/fsevents>::version=2.3.2&hash=18f3a7"
+  resolution: "fsevents@patch:fsevents@npm%3A2.3.2#~builtin<compat/fsevents>::version=2.3.2&hash=df0bf1"
   dependencies:
     node-gyp: latest
   conditions: os=darwin
@@ -3924,7 +3924,7 @@ __metadata:
 
 "resolve@patch:resolve@^1.1.7#~builtin<compat/resolve>, resolve@patch:resolve@^1.10.0#~builtin<compat/resolve>":
   version: 1.22.1
-  resolution: "resolve@patch:resolve@npm%3A1.22.1#~builtin<compat/resolve>::version=1.22.1&hash=07638b"
+  resolution: "resolve@patch:resolve@npm%3A1.22.1#~builtin<compat/resolve>::version=1.22.1&hash=c3c19d"
   dependencies:
     is-core-module: ^2.9.0
     path-parse: ^1.0.7