From 1726ac9828f2568c9177a85b47648ab5c95a4708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=80=E6=A2=A6?= <3501646051@qq.com> Date: Mon, 15 Dec 2025 17:50:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20=E6=9B=B4=E6=96=B0=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=B9=B6=E4=BF=AE=E5=A4=8Dumami=E5=88=86?= =?UTF-8?q?=E6=9E=90=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新构建发布脚本以增强可靠性和清理逻辑 将umami分析ID和域名更新为最新配置 --- docs/.vuepress/config.ts | 4 +- script/build-and-publish.bat | 188 +++++++++++++++++++---------------- 2 files changed, 104 insertions(+), 88 deletions(-) diff --git a/docs/.vuepress/config.ts b/docs/.vuepress/config.ts index bc1daeb..8ff1bb7 100644 --- a/docs/.vuepress/config.ts +++ b/docs/.vuepress/config.ts @@ -85,9 +85,9 @@ export default defineUserConfig({ requiredMeta: ['nick'] }), umamiAnalyticsPlugin({ - id: 'a4f0ca65-2da6-4e6b-a01b-f3b3157d05a3', + id: '2114ab32-5543-4be1-b5e8-c4f2c9269d0d', link: 'https://umami.simengweb.com/script.js', - domains: ['notes.simengweb.com'], + domains: ['www.simengweb.com'], cache: true }), ], diff --git a/script/build-and-publish.bat b/script/build-and-publish.bat index fcfd5a4..f76f69b 100644 --- a/script/build-and-publish.bat +++ b/script/build-and-publish.bat @@ -1,69 +1,103 @@ @echo off -setlocal EnableExtensions +setlocal EnableExtensions EnableDelayedExpansion +REM ========================================== +REM Configuration +REM ========================================== chcp 65001 >nul -REM Paths and settings +REM Move to project root cd /d "%~dp0.." set "PROJECT_DIR=%CD%\" + set "DIST_DIR=%PROJECT_DIR%docs\.vuepress\dist" +set "CACHE_DIR=%PROJECT_DIR%docs\.vuepress\.cache" +set "TEMP_DIR=%PROJECT_DIR%docs\.vuepress\.temp" set "PUBLISH_DIR=%PROJECT_DIR%_publish" set "REMOTE_URL=https://gitea.simengweb.com/si-meng-spec/build_notes_simengweb.git" set "BRANCH=main" +REM High memory limit for better performance/stability (8GB) +set "NODE_OPTIONS=--max-old-space-size=8192" + REM Args -set "LIGHT_FLAG=%~1" -set "COMMIT_MSG=%~2" +set "COMMIT_MSG=%~1" +if "%COMMIT_MSG%"=="" set "COMMIT_MSG=Build: %DATE% %TIME%" -echo [Info] Working dir: %PROJECT_DIR% +echo ========================================== +echo Start Build and Publish +echo Project Dir: %PROJECT_DIR% +echo Memory Limit: 8192 MB +echo ========================================== -REM Pre-checks -where npm >nul 2>&1 -if errorlevel 1 goto :npm_missing -where git >nul 2>&1 -if errorlevel 1 goto :git_missing +REM ========================================== +REM 1. Cleanup +REM ========================================== +echo [1/5] Cleaning up old artifacts... -REM Install deps on first run -if not exist "%PROJECT_DIR%node_modules" ( - echo [Info] Installing deps ^(npm ci^)... - call npm ci - if errorlevel 1 goto :fail -) else ( - echo [Info] node_modules exists, skip install. +if exist "%DIST_DIR%" ( + echo - Removing %DIST_DIR% + rd /s /q "%DIST_DIR%" +) +if exist "%CACHE_DIR%" ( + echo - Removing %CACHE_DIR% + rd /s /q "%CACHE_DIR%" +) +if exist "%TEMP_DIR%" ( + echo - Removing %TEMP_DIR% + rd /s /q "%TEMP_DIR%" +) +REM Clean node_modules for a fresh install every time (Ensures clean state) +if exist "%PROJECT_DIR%node_modules" ( + echo - Removing node_modules (Fresh Install Mode) + rd /s /q "%PROJECT_DIR%node_modules" ) -REM Light build mode -if /I "%LIGHT_FLAG%"=="light" ( - set "LIGHT_BUILD=1" - echo [Info] LIGHT_BUILD=1 enabled +REM ========================================== +REM 2. Install Dependencies +REM ========================================== +echo [2/5] Installing dependencies (npm ci)... +call npm ci +if %ERRORLEVEL% NEQ 0 ( + echo [Error] npm ci failed. + exit /b 1 ) -set "NODE_OPTIONS=--max-old-space-size=4096" - -echo [Info] Building docs... +REM ========================================== +REM 3. Build +REM ========================================== +echo [3/5] Building docs... call npm run docs:build -if errorlevel 1 goto :fail - -if not exist "%DIST_DIR%" goto :no_dist - -REM Prepare publish repo -if not exist "%PUBLISH_DIR%\.git" ( - echo [Info] Cloning publish repo... - git clone "%REMOTE_URL%" "%PUBLISH_DIR%" - if errorlevel 1 goto :fail -) else ( - echo [Info] Updating publish repo... - pushd "%PUBLISH_DIR%" - git fetch --all - if errorlevel 1 goto :gitfail - git checkout "%BRANCH%" - if errorlevel 1 goto :gitfail - git reset --hard "origin/%BRANCH%" - if errorlevel 1 goto :gitfail - popd +if %ERRORLEVEL% NEQ 0 ( + echo [Error] Build failed. + exit /b 1 ) -echo [Info] Cleaning publish directory ^(keep .git^)... +if not exist "%DIST_DIR%" ( + echo [Error] Dist directory not found after build. + exit /b 1 +) + +REM ========================================== +REM 4. Prepare Publish Directory +REM ========================================== +echo [4/5] Preparing publish directory... + +if not exist "%PUBLISH_DIR%\.git" ( + echo - Cloning publish repo... + if exist "%PUBLISH_DIR%" rd /s /q "%PUBLISH_DIR%" + git clone "%REMOTE_URL%" "%PUBLISH_DIR%" + if !ERRORLEVEL! NEQ 0 exit /b 1 +) else ( + echo - Updating publish repo... + pushd "%PUBLISH_DIR%" + git fetch --all + git checkout "%BRANCH%" + git reset --hard "origin/%BRANCH%" + popd +) + +echo - Cleaning publish directory content (preserving .git)... pushd "%PUBLISH_DIR%" for /f "delims=" %%F in ('dir /a /b') do ( if /I not "%%F"==".git" ( @@ -76,58 +110,40 @@ for /f "delims=" %%F in ('dir /a /b') do ( ) popd -echo [Info] Copying dist to publish... +echo - Copying new build artifacts... robocopy "%DIST_DIR%" "%PUBLISH_DIR%" *.* /E /NFL /NDL /NP /NJH /NJS >nul -if errorlevel 8 goto :fail +if %ERRORLEVEL% GEQ 8 ( + echo [Error] Robocopy failed. + exit /b 1 +) +REM ========================================== +REM 5. Push to Remote +REM ========================================== +echo [5/5] Pushing changes... pushd "%PUBLISH_DIR%" + if defined GIT_USERNAME git config user.name "%GIT_USERNAME%" if defined GIT_EMAIL git config user.email "%GIT_EMAIL%" git add -A - -if "%COMMIT_MSG%"=="" set "COMMIT_MSG=Build: %DATE% %TIME%" - -set "HAS_CHANGES=1" git diff --cached --quiet -if not errorlevel 1 set "HAS_CHANGES=0" - -if "%HAS_CHANGES%"=="0" ( - echo [Info] No changes to commit; skipping push. +if %ERRORLEVEL% EQU 0 ( + echo [Info] No changes to commit. ) else ( - git commit -m "%COMMIT_MSG%" - if errorlevel 1 ( - popd - goto :fail - ) - git push origin "%BRANCH%" - if errorlevel 1 ( - popd - goto :fail - ) - echo [Info] Pushed to %REMOTE_URL% ^(branch %BRANCH%^). + git commit -m "%COMMIT_MSG%" + echo - Pushing to %BRANCH%... + git push origin "%BRANCH%" + if !ERRORLEVEL! NEQ 0 ( + echo [Error] Git push failed. + popd + exit /b 1 + ) + echo [Success] Pushed successfully. ) popd -echo [Success] Build and publish done. +echo ========================================== +echo All Done! +echo ========================================== exit /b 0 - -:npm_missing -echo [ERROR] npm not found. Please install Node.js. -goto :fail - -:git_missing -echo [ERROR] git not found. Please install Git. -goto :fail - -:no_dist -echo [ERROR] Dist directory not found: %DIST_DIR% -goto :fail - -:gitfail -echo [ERROR] Git operation failed. -popd -goto :fail - -:fail -exit /b 1 \ No newline at end of file