Skip to content

Commit 7bfcf02

Browse files
authored
feat(PLT-2545): bob the builder support (#176)
Improve handling of Yarn workspaces by checking for cached node_modules before deciding to run yarn install. Added detailed logging for workspace detection and symlink preservation to aid in troubleshooting during the rollout of centralized GitHub Actions across frontend projects.
1 parent 583af47 commit 7bfcf02

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

shared-actions/setup-node-with-cache/action.yml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ runs:
7878
with:
7979
path: |
8080
node_modules
81+
apps/**/node_modules
82+
packages/**/node_modules
8183
~/.cache/yarn
8284
key: ${{ runner.os }}-${{ runner.arch }}-yarn-${{ hashFiles('**/yarn.lock', '**/package.json') }}
8385
restore-keys: |
@@ -126,6 +128,8 @@ runs:
126128
if: ${{ !env.ACT }}
127129
shell: bash
128130
run: |
131+
set +e # Don't exit on error - we want to check all conditions
132+
129133
# Determine if we need to run yarn install even when cache hits.
130134
#
131135
# Why this matters:
@@ -180,14 +184,22 @@ runs:
180184
181185
# Check for monorepo configurations that need install
182186
if [ "$NEEDS_INSTALL" == "false" ]; then
183-
# 1. Yarn workspaces: ALWAYS need symlink creation between workspace packages
184-
# CRITICAL: Workspace symlinks are NOT preserved in GitHub Actions cache!
185-
# Even Turbo monorepos need this - Turbo handles build caching, not workspace linking.
187+
# 1. Yarn workspaces: Check if workspace node_modules are cached
188+
# If we cache workspace node_modules explicitly (apps/**/node_modules, packages/**/node_modules),
189+
# then symlinks work correctly and we don't need to run yarn install.
190+
# If workspace node_modules are missing, we must run yarn install to populate them.
186191
if grep -q '"workspaces"' package.json 2>/dev/null; then
187-
echo "📦 Detected Yarn workspaces - install needed for workspace linking"
188-
echo " ⚠️ Workspace symlinks are not preserved in cache"
189-
echo " ⚠️ Skipping install will cause 'module not found' errors"
190-
NEEDS_INSTALL=true
192+
# Check if workspace node_modules directories exist (were cached)
193+
WORKSPACE_MODULES=$(find packages/*/node_modules apps/*/node_modules -maxdepth 0 -type d 2>/dev/null | wc -l | tr -d ' ')
194+
if [ "$WORKSPACE_MODULES" -gt 0 ]; then
195+
echo "✅ Yarn workspaces detected with cached node_modules ($WORKSPACE_MODULES workspaces)"
196+
echo " ✅ Workspace symlinks preserved - install NOT needed"
197+
NEEDS_INSTALL=false
198+
else
199+
echo "⚠️ Yarn workspaces detected but workspace node_modules missing"
200+
echo " ⚠️ Install needed to populate workspace directories"
201+
NEEDS_INSTALL=true
202+
fi
191203
fi
192204
193205
# 2. Lerna monorepo: Need lerna bootstrap (usually in postinstall hook)

0 commit comments

Comments
 (0)