From 6c47d0639c4080ec53fd46f71af263930a11ecd1 Mon Sep 17 00:00:00 2001 From: sophie Date: Thu, 15 Oct 2026 15:13:10 +0800 Subject: [PATCH] =?UTF-8?q?build:=20=E4=BF=AE=E6=94=B9frontend=20lint?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 17 ++++++++++++----- scripts/ci_frontend_lint.sh | 11 ++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e0402622..3d0dc725 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -360,11 +360,18 @@ pipeline { steps { echo '[Frontend Lint] FRONTEND_CHANGED=true,执行 npm run lint(Element 规则当前为 off)' sh ''' - set -e - docker run --rm \ - -v "${WORKSPACE}:/repo" \ - -w /repo \ - node:22-alpine sh -c "chmod +x scripts/ci_frontend_lint.sh && ./scripts/ci_frontend_lint.sh" + set -eu + test -f "${WORKSPACE}/scripts/ci_frontend_lint.sh" + test -f "${WORKSPACE}/frontend/package.json" + # 不用 -v 挂载工作区:Jenkins 在容器里时,宿主机 Docker 看不到 /var/jenkins_home。 + # 把前端源码和脚本打进容器再检查。node_modules 由容器内 npm ci 安装。 + tar -C "${WORKSPACE}" \ + --exclude=frontend/node_modules \ + --exclude=frontend/dist \ + -cf - \ + frontend scripts/ci_frontend_lint.sh \ + | docker run --rm -i node:22-alpine \ + sh -c 'mkdir -p /repo && tar -xf - -C /repo && sh /repo/scripts/ci_frontend_lint.sh' ''' } } diff --git a/scripts/ci_frontend_lint.sh b/scripts/ci_frontend_lint.sh index 40a3df65..ed7351c1 100644 --- a/scripts/ci_frontend_lint.sh +++ b/scripts/ci_frontend_lint.sh @@ -1,13 +1,14 @@ -#!/usr/bin/env bash +#!/bin/sh # Jenkins 前端风格检查。只跑 npm run lint,不跑 build。 +# 用 /bin/sh,因为 node:22-alpine 里没有 bash。 # Element 规则当前是 off,本脚本应通过。启用方式见 docs/ui/ELEMENT_MIGRATION.md §9.2。 -set -euo pipefail +set -eu -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" +SCRIPT_DIR="$(CDPATH= cd -- "$(dirname "$0")" && pwd)" +ROOT_DIR="$(CDPATH= cd -- "${SCRIPT_DIR}/.." && pwd)" FRONTEND_DIR="${ROOT_DIR}/frontend" -if [[ ! -f "${FRONTEND_DIR}/package.json" ]]; then +if [ ! -f "${FRONTEND_DIR}/package.json" ]; then echo "[ci-frontend-lint] missing ${FRONTEND_DIR}/package.json" exit 1 fi