From a21790d58d5e7bdf609c545b4df89298a599b143 Mon Sep 17 00:00:00 2001 From: pqhuy1987 Date: Wed, 29 Apr 2026 18:34:04 +0700 Subject: [PATCH] =?UTF-8?q?[CLAUDE]=20CICD:=20rollback=20npm=20junction=20?= =?UTF-8?q?cache=20(gi=E1=BB=AF=20path=20filter),=20fix=20#111=20fail=20ts?= =?UTF-8?q?c=20not=20found?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Run #111 (commit 29eb5d9) FAIL với `'tsc' is not recognized` ở step Build fe-admin. Symptoms confusing: - VPS check: cache dir C:\npm-cache-erp\ chưa có (cold) - Log: KHÔNG có Write-Host "cache MISS" hay "added 239 packages" - Timing: 1.6s từ end-of-BE-build → start-of-fe-admin-build (impossible cho npm install 49s) - Test gate (Domain 54 + Infra 17) PASS nên không phải code regression Khả năng cao: junction Move-Item disrupted node_modules .bin/ structure HOẶC act_runner PowerShell stream capture có quirk với cache MISS branch. Cần debug riêng — không nên block deploy chính. Decision: - Rollback npm cache logic về fresh install như cũ (49s + 33s) - GIỮ path filter on:push:paths-ignore (đây mới là win lớn nhất — 100% saving cho MD-only commit) - Document gotcha cho session sau (sẽ thử robocopy thay vì junction, hoặc dùng act_runner cache server local) Path filter behavior (giữ lại): - Commit chỉ docs/MD/skill/gitignore → SKIP CI hoàn toàn (~196s/commit saved) - Commit code OR cùng commit có code+docs → vẫn trigger (đúng) Verify dotnet test local: 71 pass / 1s (BE không thay đổi). Co-Authored-By: Claude Opus 4.7 (1M context) --- .gitea/workflows/deploy.yml | 119 +++++------------------------------- 1 file changed, 16 insertions(+), 103 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 292dbff..6126c47 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -101,114 +101,27 @@ jobs: --runtime win-x64 ` --self-contained false - # ============== FE BUILD WITH NPM CACHE ============== - # Cache `node_modules` ở `C:\npm-cache-erp\\\` ngoài workspace. - # Cache key = SHA256(package.json) 16-char prefix → đổi deps = fresh install. - # Junction từ workspace → cache (instant, không file copy). - # Lần đầu (cold cache): 49s + 33s. Lần sau (warm cache): 1-2s mỗi app. - # Vite 8 rolldown native binding match platform — install trên runner Windows - # (gotcha #20 từ Phase 5) → cache install này dùng được lần sau. - - name: Build fe-admin (with npm junction cache) + # FE build — npm install fresh mỗi run (Vite 8 rolldown gotcha #20). + # NOTE: Junction-based npm cache đã thử ở commit 29eb5d9 nhưng FAIL — `tsc not found`, + # script không hiện Write-Host log. Cần debug riêng (xem gotcha #39 mới). + # Tạm dùng fresh install như cũ (49s + 33s = 82s/run). Path filter ở trên đã + # save 100% time cho commit MD-only — đó là win lớn nhất. + - name: Build fe-admin shell: powershell + working-directory: fe-admin run: | - $ErrorActionPreference = 'Stop' - $hash = (Get-FileHash 'fe-admin/package.json' -Algorithm SHA256).Hash.Substring(0, 16) - $cacheDir = "C:\npm-cache-erp\fe-admin\$hash" - $cacheNm = "$cacheDir\node_modules" - $nmTarget = 'fe-admin\node_modules' + # Vite 8 rolldown native binding must match platform; fresh resolve on Windows + Remove-Item node_modules, package-lock.json -Recurse -Force -ErrorAction SilentlyContinue + & 'C:\Program Files\nodejs\npm.cmd' install --no-audit --no-fund + & 'C:\Program Files\nodejs\npm.cmd' run build - # Clean junction/dir cũ trong workspace nếu còn (act_runner thường clean nhưng phòng hờ) - if (Test-Path $nmTarget) { cmd /c rmdir /s /q $nmTarget } - - if (Test-Path $cacheNm) { - Write-Host "✓ npm cache HIT fe-admin (key: $hash)" - cmd /c mklink /J $nmTarget $cacheNm | Out-Null - } else { - Write-Host "✗ npm cache MISS fe-admin (key: $hash) — fresh install" - Push-Location fe-admin - try { - Remove-Item package-lock.json -Force -ErrorAction SilentlyContinue - & 'C:\Program Files\nodejs\npm.cmd' install --no-audit --no-fund - if ($LASTEXITCODE -ne 0) { throw "npm install failed: $LASTEXITCODE" } - } finally { Pop-Location } - New-Item -ItemType Directory -Force $cacheDir | Out-Null - Move-Item $nmTarget $cacheNm -Force - cmd /c mklink /J $nmTarget $cacheNm | Out-Null - } - - Push-Location fe-admin - try { - & 'C:\Program Files\nodejs\npm.cmd' run build - if ($LASTEXITCODE -ne 0) { throw "npm build failed: $LASTEXITCODE" } - } finally { Pop-Location } - - - name: Build fe-user (with npm junction cache) + - name: Build fe-user shell: powershell + working-directory: fe-user run: | - $ErrorActionPreference = 'Stop' - $hash = (Get-FileHash 'fe-user/package.json' -Algorithm SHA256).Hash.Substring(0, 16) - $cacheDir = "C:\npm-cache-erp\fe-user\$hash" - $cacheNm = "$cacheDir\node_modules" - $nmTarget = 'fe-user\node_modules' - - if (Test-Path $nmTarget) { cmd /c rmdir /s /q $nmTarget } - - if (Test-Path $cacheNm) { - Write-Host "✓ npm cache HIT fe-user (key: $hash)" - cmd /c mklink /J $nmTarget $cacheNm | Out-Null - } else { - Write-Host "✗ npm cache MISS fe-user (key: $hash) — fresh install" - Push-Location fe-user - try { - Remove-Item package-lock.json -Force -ErrorAction SilentlyContinue - & 'C:\Program Files\nodejs\npm.cmd' install --no-audit --no-fund - if ($LASTEXITCODE -ne 0) { throw "npm install failed: $LASTEXITCODE" } - } finally { Pop-Location } - New-Item -ItemType Directory -Force $cacheDir | Out-Null - Move-Item $nmTarget $cacheNm -Force - cmd /c mklink /J $nmTarget $cacheNm | Out-Null - } - - Push-Location fe-user - try { - & 'C:\Program Files\nodejs\npm.cmd' run build - if ($LASTEXITCODE -ne 0) { throw "npm build failed: $LASTEXITCODE" } - } finally { Pop-Location } - - # Safety: convert junction → nothing trước khi act_runner có thể cleanup workspace. - # `cmd /c rmdir /q` chỉ remove junction reference, KHÔNG recurse vào target. - # Tránh trường hợp Remove-Item -Recurse từ runner cleanup follow junction + - # delete cache contents. - - name: Remove FE node_modules junctions (preserve cache) - if: always() - shell: powershell - run: | - foreach ($app in @('fe-admin', 'fe-user')) { - $junction = "$app\node_modules" - if (Test-Path $junction) { - cmd /c rmdir /q $junction 2>$null - Write-Host "Removed junction: $junction" - } - } - - # Cache cleanup — keep top 5 most recent per app (FIFO eviction). - # Mỗi cache ~250MB. 5 versions × 2 app × 250MB = 2.5 GB max disk usage. - - name: Prune old npm caches - if: always() - shell: powershell - run: | - foreach ($app in @('fe-admin', 'fe-user')) { - $root = "C:\npm-cache-erp\$app" - if (Test-Path $root) { - $stale = Get-ChildItem $root -Directory | - Sort-Object LastWriteTime -Descending | - Select-Object -Skip 5 - foreach ($d in $stale) { - Write-Host "Pruning stale cache: $($d.FullName)" - Remove-Item $d.FullName -Recurse -Force -ErrorAction SilentlyContinue - } - } - } + Remove-Item node_modules, package-lock.json -Recurse -Force -ErrorAction SilentlyContinue + & 'C:\Program Files\nodejs\npm.cmd' install --no-audit --no-fund + & 'C:\Program Files\nodejs\npm.cmd' run build - name: Deploy to IIS (local) if: github.ref == 'refs/heads/main'