fix(ci): 更新构建脚本并修复umami分析配置
更新构建发布脚本以增强可靠性和清理逻辑 将umami分析ID和域名更新为最新配置
This commit is contained in:
@@ -85,9 +85,9 @@ export default defineUserConfig({
|
|||||||
requiredMeta: ['nick']
|
requiredMeta: ['nick']
|
||||||
}),
|
}),
|
||||||
umamiAnalyticsPlugin({
|
umamiAnalyticsPlugin({
|
||||||
id: 'a4f0ca65-2da6-4e6b-a01b-f3b3157d05a3',
|
id: '2114ab32-5543-4be1-b5e8-c4f2c9269d0d',
|
||||||
link: 'https://umami.simengweb.com/script.js',
|
link: 'https://umami.simengweb.com/script.js',
|
||||||
domains: ['notes.simengweb.com'],
|
domains: ['www.simengweb.com'],
|
||||||
cache: true
|
cache: true
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,69 +1,103 @@
|
|||||||
@echo off
|
@echo off
|
||||||
setlocal EnableExtensions
|
setlocal EnableExtensions EnableDelayedExpansion
|
||||||
|
|
||||||
|
REM ==========================================
|
||||||
|
REM Configuration
|
||||||
|
REM ==========================================
|
||||||
chcp 65001 >nul
|
chcp 65001 >nul
|
||||||
|
|
||||||
REM Paths and settings
|
REM Move to project root
|
||||||
cd /d "%~dp0.."
|
cd /d "%~dp0.."
|
||||||
set "PROJECT_DIR=%CD%\"
|
set "PROJECT_DIR=%CD%\"
|
||||||
|
|
||||||
set "DIST_DIR=%PROJECT_DIR%docs\.vuepress\dist"
|
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 "PUBLISH_DIR=%PROJECT_DIR%_publish"
|
||||||
set "REMOTE_URL=https://gitea.simengweb.com/si-meng-spec/build_notes_simengweb.git"
|
set "REMOTE_URL=https://gitea.simengweb.com/si-meng-spec/build_notes_simengweb.git"
|
||||||
set "BRANCH=main"
|
set "BRANCH=main"
|
||||||
|
|
||||||
|
REM High memory limit for better performance/stability (8GB)
|
||||||
|
set "NODE_OPTIONS=--max-old-space-size=8192"
|
||||||
|
|
||||||
REM Args
|
REM Args
|
||||||
set "LIGHT_FLAG=%~1"
|
set "COMMIT_MSG=%~1"
|
||||||
set "COMMIT_MSG=%~2"
|
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
|
REM ==========================================
|
||||||
where npm >nul 2>&1
|
REM 1. Cleanup
|
||||||
if errorlevel 1 goto :npm_missing
|
REM ==========================================
|
||||||
where git >nul 2>&1
|
echo [1/5] Cleaning up old artifacts...
|
||||||
if errorlevel 1 goto :git_missing
|
|
||||||
|
|
||||||
REM Install deps on first run
|
if exist "%DIST_DIR%" (
|
||||||
if not exist "%PROJECT_DIR%node_modules" (
|
echo - Removing %DIST_DIR%
|
||||||
echo [Info] Installing deps ^(npm ci^)...
|
rd /s /q "%DIST_DIR%"
|
||||||
call npm ci
|
)
|
||||||
if errorlevel 1 goto :fail
|
if exist "%CACHE_DIR%" (
|
||||||
) else (
|
echo - Removing %CACHE_DIR%
|
||||||
echo [Info] node_modules exists, skip install.
|
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
|
REM ==========================================
|
||||||
if /I "%LIGHT_FLAG%"=="light" (
|
REM 2. Install Dependencies
|
||||||
set "LIGHT_BUILD=1"
|
REM ==========================================
|
||||||
echo [Info] LIGHT_BUILD=1 enabled
|
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"
|
REM ==========================================
|
||||||
|
REM 3. Build
|
||||||
echo [Info] Building docs...
|
REM ==========================================
|
||||||
|
echo [3/5] Building docs...
|
||||||
call npm run docs:build
|
call npm run docs:build
|
||||||
if errorlevel 1 goto :fail
|
if %ERRORLEVEL% NEQ 0 (
|
||||||
|
echo [Error] Build failed.
|
||||||
if not exist "%DIST_DIR%" goto :no_dist
|
exit /b 1
|
||||||
|
|
||||||
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
|
|
||||||
)
|
)
|
||||||
|
|
||||||
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%"
|
pushd "%PUBLISH_DIR%"
|
||||||
for /f "delims=" %%F in ('dir /a /b') do (
|
for /f "delims=" %%F in ('dir /a /b') do (
|
||||||
if /I not "%%F"==".git" (
|
if /I not "%%F"==".git" (
|
||||||
@@ -76,58 +110,40 @@ for /f "delims=" %%F in ('dir /a /b') do (
|
|||||||
)
|
)
|
||||||
popd
|
popd
|
||||||
|
|
||||||
echo [Info] Copying dist to publish...
|
echo - Copying new build artifacts...
|
||||||
robocopy "%DIST_DIR%" "%PUBLISH_DIR%" *.* /E /NFL /NDL /NP /NJH /NJS >nul
|
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%"
|
pushd "%PUBLISH_DIR%"
|
||||||
|
|
||||||
if defined GIT_USERNAME git config user.name "%GIT_USERNAME%"
|
if defined GIT_USERNAME git config user.name "%GIT_USERNAME%"
|
||||||
if defined GIT_EMAIL git config user.email "%GIT_EMAIL%"
|
if defined GIT_EMAIL git config user.email "%GIT_EMAIL%"
|
||||||
|
|
||||||
git add -A
|
git add -A
|
||||||
|
|
||||||
if "%COMMIT_MSG%"=="" set "COMMIT_MSG=Build: %DATE% %TIME%"
|
|
||||||
|
|
||||||
set "HAS_CHANGES=1"
|
|
||||||
git diff --cached --quiet
|
git diff --cached --quiet
|
||||||
if not errorlevel 1 set "HAS_CHANGES=0"
|
if %ERRORLEVEL% EQU 0 (
|
||||||
|
echo [Info] No changes to commit.
|
||||||
if "%HAS_CHANGES%"=="0" (
|
|
||||||
echo [Info] No changes to commit; skipping push.
|
|
||||||
) else (
|
) else (
|
||||||
git commit -m "%COMMIT_MSG%"
|
git commit -m "%COMMIT_MSG%"
|
||||||
if errorlevel 1 (
|
echo - Pushing to %BRANCH%...
|
||||||
popd
|
git push origin "%BRANCH%"
|
||||||
goto :fail
|
if !ERRORLEVEL! NEQ 0 (
|
||||||
)
|
echo [Error] Git push failed.
|
||||||
git push origin "%BRANCH%"
|
popd
|
||||||
if errorlevel 1 (
|
exit /b 1
|
||||||
popd
|
)
|
||||||
goto :fail
|
echo [Success] Pushed successfully.
|
||||||
)
|
|
||||||
echo [Info] Pushed to %REMOTE_URL% ^(branch %BRANCH%^).
|
|
||||||
)
|
)
|
||||||
popd
|
popd
|
||||||
|
|
||||||
echo [Success] Build and publish done.
|
echo ==========================================
|
||||||
|
echo All Done!
|
||||||
|
echo ==========================================
|
||||||
exit /b 0
|
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
|
|
||||||
Reference in New Issue
Block a user