From bed839c0968ee10cdfa5af050449f50757de5ab6 Mon Sep 17 00:00:00 2001 From: devthejo Date: Sun, 24 Dec 2023 09:49:51 +0100 Subject: [PATCH] feat: yarn-install action --- yarn-install/action.yml | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 yarn-install/action.yml diff --git a/yarn-install/action.yml b/yarn-install/action.yml new file mode 100644 index 0000000..2ddf178 --- /dev/null +++ b/yarn-install/action.yml @@ -0,0 +1,48 @@ +# based on https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a +name: 'Monorepo install (yarn)' +description: 'Run yarn install with node_modules linker and cache enabled' +inputs: + cwd: + description: "Changes node's process.cwd() if the project is not located on the root. Default to process.cwd()" + required: false + default: '.' + cache-prefix: + description: 'Add a specific cache-prefix' + required: false + default: 'default' + +runs: + using: 'composite' + steps: + - name: ⚙️ Expose yarn config as "$GITHUB_OUTPUT" + id: yarn-config + shell: bash + working-directory: ${{ inputs.cwd }} + env: + YARN_ENABLE_GLOBAL_CACHE: 'false' + run: | + echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT + echo "CURRENT_NODE_VERSION="node-$(node --version)"" >> $GITHUB_OUTPUT + echo "CURRENT_BRANCH=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's,/,-,g')" >> $GITHUB_OUTPUT + + - name: ♻️ Restore yarn cache + uses: actions/cache@v3 + id: yarn-download-cache + with: + path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }} + key: yarn-download-cache-${{ inputs.cache-prefix }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }} + restore-keys: | + yarn-download-cache-${{ inputs.cache-prefix }}- + + - name: 📥 Install dependencies + shell: bash + working-directory: ${{ inputs.cwd }} + run: yarn install --immutable --inline-builds + env: + # Overrides/align yarnrc.yml options (v3, v4) for a CI context + YARN_ENABLE_GLOBAL_CACHE: 'false' # Use local cache folder to keep downloaded archives + YARN_ENABLE_MIRROR: 'false' # Prevent populating global cache for caches misses (local cache only) + YARN_NM_MODE: 'hardlinks-local' # Reduce node_modules size + YARN_INSTALL_STATE_PATH: '.yarn/ci-cache/install-state.gz' # Might speed up resolution step when node_modules present + # Other environment variables + HUSKY: '0' # By default do not run HUSKY install \ No newline at end of file