|
78 | 78 | with: |
79 | 79 | path: | |
80 | 80 | node_modules |
| 81 | + apps/**/node_modules |
| 82 | + packages/**/node_modules |
81 | 83 | ~/.cache/yarn |
82 | 84 | key: ${{ runner.os }}-${{ runner.arch }}-yarn-${{ hashFiles('**/yarn.lock', '**/package.json') }} |
83 | 85 | restore-keys: | |
@@ -126,6 +128,8 @@ runs: |
126 | 128 | if: ${{ !env.ACT }} |
127 | 129 | shell: bash |
128 | 130 | run: | |
| 131 | + set +e # Don't exit on error - we want to check all conditions |
| 132 | + |
129 | 133 | # Determine if we need to run yarn install even when cache hits. |
130 | 134 | # |
131 | 135 | # Why this matters: |
@@ -180,14 +184,22 @@ runs: |
180 | 184 | |
181 | 185 | # Check for monorepo configurations that need install |
182 | 186 | 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. |
186 | 191 | 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 |
191 | 203 | fi |
192 | 204 | |
193 | 205 | # 2. Lerna monorepo: Need lerna bootstrap (usually in postinstall hook) |
|
0 commit comments