Skip to content

Commit b491bc8

Browse files
committed
feat: add pnpm composite install action
1 parent 2c7175d commit b491bc8

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
3+
name: ⚙️ Monorepo install (pnpm)
4+
description: 'Run pnpm install with enabled cache.'
5+
6+
inputs:
7+
cwd:
8+
description: "Changes node's process.cwd() if the project is not located on the root. Default to process.cwd()"
9+
required: false
10+
default: '.'
11+
enable-corepack:
12+
description: 'Enable corepack'
13+
required: false
14+
default: 'false'
15+
cache-prefix:
16+
description: "Add a specific cache-prefix"
17+
required: false
18+
default: 'default'
19+
cache-node-modules:
20+
description: 'Cache node_modules, might speed up link step (invalidated lock/os/node-version/branch)'
21+
required: false
22+
default: 'false'
23+
24+
runs:
25+
using: 'composite'
26+
27+
steps:
28+
- name: ⚙️ Enable Corepack
29+
if: inputs.enable-corepack == 'true'
30+
shell: bash
31+
working-directory: ${{ inputs.cwd }}
32+
run: corepack enable
33+
34+
- name: ⚙️ Install pnpm
35+
if: inputs.enable-corepack == 'false'
36+
uses: pnpm/action-setup@v2
37+
id: pnpm-install
38+
with:
39+
run_install: false
40+
41+
- name: 🌎 Expose pnpm config(s) through "$GITHUB_OUTPUT"
42+
id: pnpm-config
43+
shell: bash
44+
run: |
45+
echo "STORE_PATH=$(pnpm store path | tr -d '\n')" >> $GITHUB_OUTPUT
46+
echo "CURRENT_NODE_VERSION="node-$(node --version)"" >> $GITHUB_OUTPUT
47+
echo "CURRENT_BRANCH=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's,/,-,g')" >> $GITHUB_OUTPUT
48+
49+
- name: ♻️ Cache rotation keys
50+
id: cache-rotation
51+
shell: bash
52+
run: |
53+
echo "YEAR_MONTH=$(/bin/date -u "+%Y%m")" >> $GITHUB_OUTPUT
54+
55+
- name: 🗄️ Setup pnpm cache
56+
uses: actions/cache@v3
57+
id: pnpm-store-cache
58+
with:
59+
path: ${{ steps.pnpm-config.outputs.STORE_PATH }}
60+
key: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ hashFiles('**/pnpm-lock.yaml') }}
61+
restore-keys: |
62+
${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-
63+
64+
- name: ♻️ Restore node_modules
65+
if: inputs.cache-node-modules == 'true'
66+
id: pnpm-nm-cache
67+
uses: actions/cache@v3
68+
with:
69+
path: ${{ inputs.cwd }}/**/node_modules
70+
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') }}
71+
restore-keys: |
72+
pnpm-nm-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.pnpm-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.pnpm-config.outputs.CURRENT_BRANCH }}-
73+
74+
- name: 📦 Install dependencies
75+
shell: bash
76+
run: pnpm install --no-frozen-lockfile --strict-peer-dependencies --prefer-offline
77+
env:
78+
HUSKY: '0'

0 commit comments

Comments
 (0)