fix(ci): 修复Frontend Lint缓存脏数据导致npm ci失败 #345

Merged
xiaoxia merged 1 commits from fix/frontend-lint-cache-fix into develop 2026-07-15 10:04:55 +08:00
Owner

问题

PR #341 合并后,Frontend Lint出现间歇性失败:

ENOTEMPTY: directory not empty, rmdir 'node_modules/@types/node'

根因

PR #341 引入的npm缓存机制只通过 package-lock.json 的hash判断是否跳过 npm ci,但未验证缓存的 node_modules 是否完整可用:

  1. 缓存脏数据:docker volume是跨run共享的,上一次异常中断的job可能留下半成品目录
  2. hash假阳性:hash文件存在 + 匹配,但 node_modules 实际不完整/不干净
  3. 回退失败:缓存miss走 npm ci 时,遇到残留的脏目录导致 rmdir 失败

修复

  1. 完整性校验:缓存命中时额外检查 node_modules/.bin/eslint 是否存在且可执行
  2. 失败自动重试npm ci 失败时自动 rm -rf node_modules 清理后重试一次
  3. 更健壮的判断逻辑:用 CACHE_VALID 标志位替代 if/else 结构,便于扩展校验条件

影响范围

  • 仅修改 Frontend Lint 的 Install dependencies 步骤
  • 不影响其他job
  • 不改变缓存命中逻辑,只增加安全性

验证

CI三门禁全绿即为通过。预期Lint耗时稳定在1-2min。

## 问题 PR #341 合并后,Frontend Lint出现间歇性失败: ``` ENOTEMPTY: directory not empty, rmdir 'node_modules/@types/node' ``` ## 根因 PR #341 引入的npm缓存机制只通过 `package-lock.json` 的hash判断是否跳过 `npm ci`,但未验证缓存的 `node_modules` 是否完整可用: 1. **缓存脏数据**:docker volume是跨run共享的,上一次异常中断的job可能留下半成品目录 2. **hash假阳性**:hash文件存在 + 匹配,但 `node_modules` 实际不完整/不干净 3. **回退失败**:缓存miss走 `npm ci` 时,遇到残留的脏目录导致 `rmdir` 失败 ## 修复 1. **完整性校验**:缓存命中时额外检查 `node_modules/.bin/eslint` 是否存在且可执行 2. **失败自动重试**:`npm ci` 失败时自动 `rm -rf node_modules` 清理后重试一次 3. **更健壮的判断逻辑**:用 `CACHE_VALID` 标志位替代 if/else 结构,便于扩展校验条件 ## 影响范围 - 仅修改 Frontend Lint 的 Install dependencies 步骤 - 不影响其他job - 不改变缓存命中逻辑,只增加安全性 ## 验证 CI三门禁全绿即为通过。预期Lint耗时稳定在1-2min。
xiaoxia added 1 commit 2026-07-15 09:34:29 +08:00
fix(ci): 修复Frontend Lint缓存脏数据导致npm ci失败的问题
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m2s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 1m30s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 1m33s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m6s
e84f0531d8
auto-approve-bot approved these changes 2026-07-15 10:03:00 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
xiaoxia merged commit 9c155d0561 into develop 2026-07-15 10:04:55 +08:00
xiaoxia deleted branch fix/frontend-lint-cache-fix 2026-07-15 10:04:55 +08:00
Sign in to join this conversation.