From 6490cd068e3f175c8198f993a77ad45e6b73adfe Mon Sep 17 00:00:00 2001 From: kurihada Date: Tue, 3 Mar 2026 16:28:10 +0800 Subject: [PATCH] =?UTF-8?q?CI=20=E6=8F=90=E9=80=9F=EF=BC=9A=E7=BC=93?= =?UTF-8?q?=E5=AD=98=20node=5Fmodules=20=E5=B9=B6=E6=94=B9=E7=94=A8=20git?= =?UTF-8?q?=20archive=20=E4=BC=A0=E8=BE=93=E5=B7=A5=E4=BD=9C=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d9bf2b9..19b04d4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,6 +13,9 @@ pipeline { APP_NAME = 'no-whatever' CI_IMAGE = 'mcr.microsoft.com/playwright:v1.51.1-jammy' NPM_CACHE_VOLUME = 'no-whatever-npm-cache' + NODE_MODULES_VOLUME = 'no-whatever-node-modules' + NPM_LOCK_HASH_FILE = '/npm-cache/no-whatever-package-lock.sha256' + NPM_REGISTRY = 'https://registry.npmmirror.com' } triggers { @@ -62,14 +65,25 @@ pipeline { cid=$(docker create --ipc=host \ -e HOME=/tmp \ -e NPM_CONFIG_CACHE=/npm-cache \ + -e NPM_CONFIG_REGISTRY=${NPM_REGISTRY} \ -v ${NPM_CACHE_VOLUME}:/npm-cache \ + -v ${NODE_MODULES_VOLUME}:/workspace/node_modules \ ${CI_IMAGE} \ - sh -lc "cd /workspace && npm ci --prefer-offline --no-audit --progress=false && npm run lint && npx tsc --noEmit && npm run test:coverage && npm run test:e2e:smoke") + 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'; \ + 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") cleanup() { docker rm -f "$cid" >/dev/null 2>&1 || true } trap cleanup EXIT - docker cp . "$cid":/workspace + git archive --format=tar HEAD | docker cp - "$cid":/workspace set +e docker start -a "$cid" status=$? @@ -137,14 +151,25 @@ pipeline { cid=$(docker create --ipc=host \ -e HOME=/tmp \ -e NPM_CONFIG_CACHE=/npm-cache \ + -e NPM_CONFIG_REGISTRY=${NPM_REGISTRY} \ -v ${NPM_CACHE_VOLUME}:/npm-cache \ + -v ${NODE_MODULES_VOLUME}:/workspace/node_modules \ ${CI_IMAGE} \ - sh -lc "cd /workspace && npm ci --prefer-offline --no-audit --progress=false && npm run test:e2e") + 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'; \ + else \ + npm ci --prefer-offline --no-audit --progress=false && \ + echo \"\$lock_hash\" > ${NPM_LOCK_HASH_FILE}; \ + fi && \ + npm run test:e2e") cleanup() { docker rm -f "$cid" >/dev/null 2>&1 || true } trap cleanup EXIT - docker cp . "$cid":/workspace + git archive --format=tar HEAD | docker cp - "$cid":/workspace set +e docker start -a "$cid" status=$?