|
| 1 | +name: 'Install yarn' |
| 2 | +description: 'Run yarn install with node_modules linker and cache enabled' |
| 3 | +inputs: |
| 4 | + cwd: |
| 5 | + description: "Changes node's process.cwd() if the project is not located on the root. Default to process.cwd()" |
| 6 | + required: false |
| 7 | + default: '.' |
| 8 | + cache-prefix: |
| 9 | + description: 'Add a specific cache-prefix' |
| 10 | + required: false |
| 11 | + default: 'default' |
| 12 | + cache-npm-cache: |
| 13 | + description: 'Cache npm global cache folder often used by node-gyp, prebuild binaries (invalidated on lock/os/node-version)' |
| 14 | + required: false |
| 15 | + default: 'true' |
| 16 | + enable-corepack: |
| 17 | + description: 'Enable corepack' |
| 18 | + required: false |
| 19 | + default: 'true' |
| 20 | + |
| 21 | +runs: |
| 22 | + using: 'composite' |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: ⚙️ Enable Corepack |
| 26 | + if: inputs.enable-corepack == 'true' |
| 27 | + shell: bash |
| 28 | + working-directory: ${{ inputs.cwd }} |
| 29 | + run: corepack enable |
| 30 | + |
| 31 | + - name: ⚙️ Expose yarn config as "$GITHUB_OUTPUT" |
| 32 | + id: yarn-config |
| 33 | + shell: bash |
| 34 | + working-directory: ${{ inputs.cwd }} |
| 35 | + env: |
| 36 | + YARN_ENABLE_GLOBAL_CACHE: 'false' |
| 37 | + run: | |
| 38 | + echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT |
| 39 | + echo "CURRENT_NODE_VERSION="node-$(node --version)"" >> $GITHUB_OUTPUT |
| 40 | + echo "CURRENT_BRANCH=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's,/,-,g')" >> $GITHUB_OUTPUT |
| 41 | + echo "NPM_GLOBAL_CACHE_FOLDER=$(npm config get cache)" >> $GITHUB_OUTPUT |
| 42 | +
|
| 43 | + - name: ♻️ Restore yarn cache |
| 44 | + uses: actions/cache@v4 |
| 45 | + id: yarn-download-cache |
| 46 | + with: |
| 47 | + path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }} |
| 48 | + key: yarn-download-cache-${{ inputs.cache-prefix }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }} |
| 49 | + restore-keys: | |
| 50 | + yarn-download-cache-${{ inputs.cache-prefix }}- |
| 51 | +
|
| 52 | + - name: ♻️ Restore global npm cache folder |
| 53 | + if: inputs.cache-npm-cache == 'true' |
| 54 | + id: npm-global-cache |
| 55 | + uses: actions/cache@v4 |
| 56 | + with: |
| 57 | + path: ${{ steps.yarn-config.outputs.NPM_GLOBAL_CACHE_FOLDER }} |
| 58 | + 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)) }} |
| 59 | + |
| 60 | + - name: 📥 Install dependencies |
| 61 | + shell: bash |
| 62 | + working-directory: ${{ inputs.cwd }} |
| 63 | + run: yarn install --immutable --inline-builds |
| 64 | + env: |
| 65 | + # Overrides/align yarnrc.yml options (v3, v4) for a CI context |
| 66 | + YARN_ENABLE_GLOBAL_CACHE: 'false' # Use local cache folder to keep downloaded archives |
| 67 | + YARN_ENABLE_MIRROR: 'false' # Prevent populating global cache for caches misses (local cache only) |
| 68 | + YARN_NM_MODE: 'hardlinks-local' # Reduce node_modules size |
| 69 | + YARN_INSTALL_STATE_PATH: '.yarn/ci-cache/install-state.gz' # Might speed up resolution step when node_modules present |
| 70 | + # Other environment variables |
0 commit comments