|
| 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 |
0 commit comments