Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions shared-actions/setup-node-with-cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ runs:
with:
path: |
node_modules
apps/**/node_modules
packages/**/node_modules
~/.cache/yarn
key: ${{ runner.os }}-${{ runner.arch }}-yarn-${{ hashFiles('**/yarn.lock', '**/package.json') }}
restore-keys: |
Expand Down Expand Up @@ -126,6 +128,8 @@ runs:
if: ${{ !env.ACT }}
shell: bash
run: |
set +e # Don't exit on error - we want to check all conditions

# Determine if we need to run yarn install even when cache hits.
#
# Why this matters:
Expand Down Expand Up @@ -180,14 +184,22 @@ runs:

# Check for monorepo configurations that need install
if [ "$NEEDS_INSTALL" == "false" ]; then
# 1. Yarn workspaces: ALWAYS need symlink creation between workspace packages
# CRITICAL: Workspace symlinks are NOT preserved in GitHub Actions cache!
# Even Turbo monorepos need this - Turbo handles build caching, not workspace linking.
# 1. Yarn workspaces: Check if workspace node_modules are cached
# If we cache workspace node_modules explicitly (apps/**/node_modules, packages/**/node_modules),
# then symlinks work correctly and we don't need to run yarn install.
# If workspace node_modules are missing, we must run yarn install to populate them.
if grep -q '"workspaces"' package.json 2>/dev/null; then
echo "📦 Detected Yarn workspaces - install needed for workspace linking"
echo " ⚠️ Workspace symlinks are not preserved in cache"
echo " ⚠️ Skipping install will cause 'module not found' errors"
NEEDS_INSTALL=true
# Check if workspace node_modules directories exist (were cached)
WORKSPACE_MODULES=$(find packages/*/node_modules apps/*/node_modules -maxdepth 0 -type d 2>/dev/null | wc -l | tr -d ' ')
if [ "$WORKSPACE_MODULES" -gt 0 ]; then
echo "✅ Yarn workspaces detected with cached node_modules ($WORKSPACE_MODULES workspaces)"
echo " ✅ Workspace symlinks preserved - install NOT needed"
NEEDS_INSTALL=false
else
echo "⚠️ Yarn workspaces detected but workspace node_modules missing"
echo " ⚠️ Install needed to populate workspace directories"
NEEDS_INSTALL=true
fi
fi

# 2. Lerna monorepo: Need lerna bootstrap (usually in postinstall hook)
Expand Down