Skip to content

Commit

Permalink
feat: add pnpm composite install action
Browse files Browse the repository at this point in the history
  • Loading branch information
lotyp committed Jul 15, 2023
1 parent 2c7175d commit b491bc8
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/actions/pnpm-install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---

name: ⚙️ Monorepo install (pnpm)
description: 'Run pnpm install with enabled cache.'

inputs:
cwd:
description: "Changes node's process.cwd() if the project is not located on the root. Default to process.cwd()"
required: false
default: '.'
enable-corepack:
description: 'Enable corepack'
required: false
default: 'false'
cache-prefix:
description: "Add a specific cache-prefix"
required: false
default: 'default'
cache-node-modules:
description: 'Cache node_modules, might speed up link step (invalidated lock/os/node-version/branch)'
required: false
default: 'false'

runs:
using: 'composite'

steps:
- name: ⚙️ Enable Corepack
if: inputs.enable-corepack == 'true'
shell: bash
working-directory: ${{ inputs.cwd }}
run: corepack enable

- name: ⚙️ Install pnpm
if: inputs.enable-corepack == 'false'
uses: pnpm/action-setup@v2
id: pnpm-install
with:
run_install: false

- name: 🌎 Expose pnpm config(s) through "$GITHUB_OUTPUT"
id: pnpm-config
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path | tr -d '\n')" >> $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: ♻️ Cache rotation keys
id: cache-rotation
shell: bash
run: |
echo "YEAR_MONTH=$(/bin/date -u "+%Y%m")" >> $GITHUB_OUTPUT
- name: 🗄️ Setup pnpm cache
uses: actions/cache@v3
id: pnpm-store-cache
with:
path: ${{ steps.pnpm-config.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-
- name: ♻️ Restore node_modules
if: inputs.cache-node-modules == 'true'
id: pnpm-nm-cache
uses: actions/cache@v3
with:
path: ${{ inputs.cwd }}/**/node_modules
key: pnpm-nm-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.pnpm-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.pnpm-config.outputs.CURRENT_BRANCH }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
pnpm-nm-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.pnpm-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.pnpm-config.outputs.CURRENT_BRANCH }}-
- name: 📦 Install dependencies
shell: bash
run: pnpm install --no-frozen-lockfile --strict-peer-dependencies --prefer-offline
env:
HUSKY: '0'

0 comments on commit b491bc8

Please sign in to comment.