chore: build and deploy web-antd [skip ci]

This commit is contained in:
lzh
2025-12-23 13:56:38 +08:00
parent 3c206a831e
commit 7a9142673d
1905 changed files with 12910 additions and 42 deletions

View File

@@ -2,14 +2,15 @@
## 📋 快速参考
| 操作 | 是否触发 CI/CD | 说明 |
|------|---------------|------|
| 修改源码 | ❌ 否 | 需要先本地构建,再推送 dist |
| 推送 dist 目录 | ✅ 是 | 自动触发部署 |
| 修改 nginx.conf | ✅ 是 | 自动触发部署 |
| 修改 Dockerfile.deploy | ✅ 是 | 自动触发部署 |
| 操作 | 是否触发 CI/CD | 说明 |
| ---------------------- | -------------- | --------------------------- |
| 修改源码 | ❌ 否 | 需要先本地构建,再推送 dist |
| 推送 dist 目录 | ✅ 是 | 自动触发部署 |
| 修改 nginx.conf | ✅ 是 | 自动触发部署 |
| 修改 Dockerfile.deploy | ✅ 是 | 自动触发部署 |
**快速部署命令**
```bash
./scripts/deploy/build-and-push.sh
```
@@ -19,6 +20,7 @@
本方案采用**本地构建 + 服务器部署**的方式,避免在服务器上进行资源密集的构建过程,从而解决服务器资源占用问题。
**重要提示**
-**修改源码不会触发 CI/CD**:只有推送 `dist` 目录时才会触发部署
-**必须先本地构建**:在推送前需要在本地执行构建命令
-**服务器零构建压力**:服务器只负责轻量级的 Docker 镜像打包,不进行构建
@@ -33,6 +35,7 @@
```
详细步骤:
1. **本地开发**:修改源码(`apps/web-antd/src/**`),此时不会触发 CI/CD
2. **本地构建**:在本地执行构建命令,生成 `apps/web-antd/dist` 目录
3. **推送构建产物**:将 `dist` 目录提交并推送到 Git 仓库
@@ -44,23 +47,27 @@
### 方式一:使用自动化脚本(推荐)
**Windows PowerShell 用户**
```powershell
# 在项目根目录执行
.\scripts\deploy\build-and-push.ps1
```
**Linux/Mac 用户**
```bash
# 在项目根目录执行
./scripts/deploy/build-and-push.sh
```
**或者使用 Git BashWindows**
```bash
bash scripts/deploy/build-and-push.sh
```
脚本会自动:
- 清理旧的构建产物
- 安装依赖(如果需要)
- 执行构建
@@ -94,6 +101,7 @@ git push origin master
### ✅ 会触发部署的情况
当以下文件变化时会触发自动部署:
- `apps/web-antd/dist/**` - **构建产物目录(主要触发条件)**
- `apps/web-antd/nginx.conf` - Nginx 配置
- `Dockerfile.deploy` - 部署用 Dockerfile
@@ -102,6 +110,7 @@ git push origin master
### ❌ 不会触发部署的情况
以下情况**不会**触发 CI/CD
- 修改源码(`apps/web-antd/src/**`
- 修改依赖包(`packages/**`
- 修改 `package.json``pnpm-lock.yaml`
@@ -117,16 +126,19 @@ git push origin master
**重要**`apps/web-antd/dist` 目录在 `.gitignore` 中被忽略,但我们需要将其提交到 Git 才能触发 CI/CD。
**脚本会自动处理**
- 构建脚本(`build-and-push.sh``build-and-push.ps1`)会自动使用 `git add -f` 强制添加 dist 目录
- 你不需要手动修改 `.gitignore` 文件
**手动添加方法**(如果使用脚本):
```bash
# 强制添加被忽略的 dist 目录
git add -f apps/web-antd/dist
```
**检查方法**
```bash
# 检查 dist 是否被 Git 跟踪
git ls-files apps/web-antd/dist
@@ -137,6 +149,7 @@ git ls-files apps/web-antd/dist
### 2. 修改源码后必须重新构建
**重要**修改源码后CI/CD **不会自动触发**,需要:
1. 本地执行构建:`pnpm build:antd`
2. 推送构建产物:`git add apps/web-antd/dist && git push`
@@ -151,6 +164,7 @@ git ls-files apps/web-antd/dist
**推荐流程**
**Windows PowerShell**
```powershell
# 1. 开发阶段:修改源码(不会触发 CI/CD
# 使用你喜欢的编辑器修改 apps/web-antd/src/xxx.vue
@@ -163,6 +177,7 @@ pnpm dev:antd
```
**Linux/Mac/Git Bash**
```bash
# 1. 开发阶段:修改源码(不会触发 CI/CD
vim apps/web-antd/src/xxx.vue
@@ -187,6 +202,7 @@ pnpm dev:antd
### 问题CI/CD 提示构建产物不存在
**解决方案**
1. 检查本地是否成功构建:`ls -la apps/web-antd/dist`
2. 检查 dist 目录是否被 Git 跟踪:`git ls-files apps/web-antd/dist`
3. 如果 dist 在 .gitignore 中,使用强制添加:`git add -f apps/web-antd/dist`
@@ -194,6 +210,7 @@ pnpm dev:antd
### 问题:构建失败
**解决方案**
1. 检查 Node.js 版本:`node --version`(需要 >= 20.12.0
2. 检查 pnpm 版本:`pnpm --version`(需要 >= 10.14.0
3. 清理并重新安装依赖:`pnpm clean && pnpm install`
@@ -202,14 +219,16 @@ pnpm dev:antd
### 问题:推送后 CI/CD 未触发
**可能原因**
1. **只推送了源码,没有推送 dist**:修改源码不会触发 CI/CD
- 解决:先执行 `pnpm build:antd`,然后推送 `dist` 目录
2. **dist 目录未被 Git 跟踪**
```bash
# 检查 dist 是否被跟踪
git ls-files apps/web-antd/dist
# 如果为空,强制添加
git add -f apps/web-antd/dist
git commit -m "chore: add build artifacts"
@@ -230,6 +249,7 @@ pnpm dev:antd
### 问题:修改源码后如何部署
**解决方案**
1. 本地构建:`pnpm build:antd`
2. 检查构建结果:`ls -la apps/web-antd/dist`
3. 推送构建产物:
@@ -239,4 +259,3 @@ pnpm dev:antd
git push origin master
```
4. 或者使用自动化脚本:`./scripts/deploy/build-and-push.sh`

View File

@@ -1,76 +1,72 @@
# 本地构建并推送到仓库的 PowerShell 脚本
# 使用方法: .\scripts\deploy\build-and-push.ps1
# Local build and push script
# Usage: .\scripts\deploy\build-and-push.ps1
$ErrorActionPreference = "Stop"
Write-Host "🚀 Starting local build and push process..." -ForegroundColor Cyan
Write-Host "Starting local build and push process..." -ForegroundColor Cyan
# 1. 检查是否在项目根目录
if (-not (Test-Path "package.json")) {
Write-Host "Error: Please run this script from project root" -ForegroundColor Red
Write-Host "Error: Please run this script from project root" -ForegroundColor Red
exit 1
}
# 2. 清理旧的构建产物
Write-Host "📦 Cleaning old build artifacts..." -ForegroundColor Yellow
if (Test-Path "apps\web-antd\dist") {
Remove-Item -Recurse -Force "apps\web-antd\dist"
Write-Host "Cleaning old build artifacts..." -ForegroundColor Yellow
$distPath = "apps\web-antd\dist"
if (Test-Path $distPath) {
Remove-Item -Recurse -Force $distPath
}
# 3. 安装依赖(如果需要)
if (-not (Test-Path "node_modules")) {
Write-Host "📥 Installing dependencies..." -ForegroundColor Yellow
Write-Host "Installing dependencies..." -ForegroundColor Yellow
pnpm install
}
# 4. 构建项目
Write-Host "🔨 Building project..." -ForegroundColor Yellow
Write-Host "Building project..." -ForegroundColor Yellow
pnpm build:antd
# 5. 检查构建结果
$distPath = "apps\web-antd\dist"
if (-not (Test-Path $distPath)) {
Write-Host "Error: Build failed, dist directory not found" -ForegroundColor Red
Write-Host "Error: Build failed, dist directory not found" -ForegroundColor Red
exit 1
}
$distItems = Get-ChildItem $distPath -ErrorAction SilentlyContinue
if ($null -eq $distItems -or $distItems.Count -eq 0) {
Write-Host "Error: Build failed, dist directory is empty" -ForegroundColor Red
if ($null -eq $distItems) {
Write-Host "Error: Build failed, dist directory is empty" -ForegroundColor Red
exit 1
}
if ($distItems.Count -eq 0) {
Write-Host "Error: Build failed, dist directory is empty" -ForegroundColor Red
exit 1
}
Write-Host "Build successful!" -ForegroundColor Green
Write-Host "Build successful!" -ForegroundColor Green
# 6. 显示构建产物大小
$buildSize = (Get-ChildItem "apps\web-antd\dist" -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB
Write-Host "📊 Build size: $([math]::Round($buildSize, 2)) MB" -ForegroundColor Cyan
$buildSize = (Get-ChildItem $distPath -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB
$buildSizeRounded = [math]::Round($buildSize, 2)
Write-Host "Build size: $buildSizeRounded MB" -ForegroundColor Cyan
# 7. 提交并推送(可选)
$response = Read-Host "Do you want to commit and push to repository? (y/n)"
if ($response -eq "y" -or $response -eq "Y") {
# 检查是否有未提交的更改
$gitStatus = git status --porcelain
if ($gitStatus) {
Write-Host "📝 Staging build artifacts..." -ForegroundColor Yellow
# 使用 -f 强制添加被 .gitignore 忽略的 dist 目录
Write-Host "Staging build artifacts..." -ForegroundColor Yellow
git add -f apps/web-antd/dist
git add -A # 添加其他更改
git add -A
Write-Host "💾 Committing changes..." -ForegroundColor Yellow
Write-Host "Committing changes..." -ForegroundColor Yellow
git commit -m "chore: build and deploy web-antd [skip ci]" 2>&1 | Out-Null
Write-Host "📤 Pushing to repository..." -ForegroundColor Yellow
Write-Host "Pushing to repository..." -ForegroundColor Yellow
git push origin master
Write-Host "Build artifacts pushed successfully!" -ForegroundColor Green
Write-Host "Waiting for CI/CD to deploy..." -ForegroundColor Cyan
Write-Host "Build artifacts pushed successfully!" -ForegroundColor Green
Write-Host "Waiting for CI/CD to deploy..." -ForegroundColor Cyan
} else {
Write-Host " No changes to commit" -ForegroundColor Yellow
Write-Host "No changes to commit" -ForegroundColor Yellow
}
} else {
Write-Host " Skipping git push. You can manually commit and push later." -ForegroundColor Yellow
Write-Host "Skipping git push. You can manually commit and push later." -ForegroundColor Yellow
}
Write-Host "Done!" -ForegroundColor Green
Write-Host "Done!" -ForegroundColor Green