修复 CI 缓存脚本变量展开错误并恢复 node_modules 命中

This commit is contained in:
2026-03-03 16:38:31 +08:00
parent 6490cd068e
commit a61081fca9
Vendored
+20 -18
View File
@@ -66,19 +66,20 @@ pipeline {
-e HOME=/tmp \
-e NPM_CONFIG_CACHE=/npm-cache \
-e NPM_CONFIG_REGISTRY=${NPM_REGISTRY} \
-e NPM_LOCK_HASH_FILE=${NPM_LOCK_HASH_FILE} \
-v ${NPM_CACHE_VOLUME}:/npm-cache \
-v ${NODE_MODULES_VOLUME}:/workspace/node_modules \
${CI_IMAGE} \
sh -lc "cd /workspace && \
lock_hash=\$(sha256sum package-lock.json | cut -d ' ' -f1) && \
cached_hash=\$(cat ${NPM_LOCK_HASH_FILE} 2>/dev/null || true) && \
if [ \"\$lock_hash\" = \"\$cached_hash\" ] && [ -d node_modules ] && [ \"\$(ls -A node_modules 2>/dev/null)\" ]; then \
echo 'node_modules cache hit, skip npm ci'; \
sh -lc 'set -e; cd /workspace; \
lock_hash=$(sha256sum package-lock.json | cut -d " " -f1); \
cached_hash=$(cat "$NPM_LOCK_HASH_FILE" 2>/dev/null || true); \
if [ "$lock_hash" = "$cached_hash" ] && [ -d node_modules ] && [ "$(ls -A node_modules 2>/dev/null)" ]; then \
echo "node_modules cache hit, skip npm ci"; \
else \
npm ci --prefer-offline --no-audit --progress=false && \
echo \"\$lock_hash\" > ${NPM_LOCK_HASH_FILE}; \
fi && \
npm run lint && npx tsc --noEmit && npm run test:coverage && npm run test:e2e:smoke")
npm ci --prefer-offline --no-audit --progress=false; \
printf "%s" "$lock_hash" > "$NPM_LOCK_HASH_FILE"; \
fi; \
npm run lint; npx tsc --noEmit; npm run test:coverage; npm run test:e2e:smoke')
cleanup() {
docker rm -f "$cid" >/dev/null 2>&1 || true
}
@@ -152,19 +153,20 @@ pipeline {
-e HOME=/tmp \
-e NPM_CONFIG_CACHE=/npm-cache \
-e NPM_CONFIG_REGISTRY=${NPM_REGISTRY} \
-e NPM_LOCK_HASH_FILE=${NPM_LOCK_HASH_FILE} \
-v ${NPM_CACHE_VOLUME}:/npm-cache \
-v ${NODE_MODULES_VOLUME}:/workspace/node_modules \
${CI_IMAGE} \
sh -lc "cd /workspace && \
lock_hash=\$(sha256sum package-lock.json | cut -d ' ' -f1) && \
cached_hash=\$(cat ${NPM_LOCK_HASH_FILE} 2>/dev/null || true) && \
if [ \"\$lock_hash\" = \"\$cached_hash\" ] && [ -d node_modules ] && [ \"\$(ls -A node_modules 2>/dev/null)\" ]; then \
echo 'node_modules cache hit, skip npm ci'; \
sh -lc 'set -e; cd /workspace; \
lock_hash=$(sha256sum package-lock.json | cut -d " " -f1); \
cached_hash=$(cat "$NPM_LOCK_HASH_FILE" 2>/dev/null || true); \
if [ "$lock_hash" = "$cached_hash" ] && [ -d node_modules ] && [ "$(ls -A node_modules 2>/dev/null)" ]; then \
echo "node_modules cache hit, skip npm ci"; \
else \
npm ci --prefer-offline --no-audit --progress=false && \
echo \"\$lock_hash\" > ${NPM_LOCK_HASH_FILE}; \
fi && \
npm run test:e2e")
npm ci --prefer-offline --no-audit --progress=false; \
printf "%s" "$lock_hash" > "$NPM_LOCK_HASH_FILE"; \
fi; \
npm run test:e2e')
cleanup() {
docker rm -f "$cid" >/dev/null 2>&1 || true
}