From a61081fca9703f59e49ea0b4d34387c69c9ebca3 Mon Sep 17 00:00:00 2001 From: kurihada Date: Tue, 3 Mar 2026 16:38:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20CI=20=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=8F=98=E9=87=8F=E5=B1=95=E5=BC=80=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=B9=B6=E6=81=A2=E5=A4=8D=20node=5Fmodules=20?= =?UTF-8?q?=E5=91=BD=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 19b04d4..8f232d6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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 }