chore: 添加powerShell脚本构建提交
This commit is contained in:
@@ -43,11 +43,23 @@
|
||||
|
||||
### 方式一:使用自动化脚本(推荐)
|
||||
|
||||
**Windows PowerShell 用户**:
|
||||
```powershell
|
||||
# 在项目根目录执行
|
||||
.\scripts\deploy\build-and-push.ps1
|
||||
```
|
||||
|
||||
**Linux/Mac 用户**:
|
||||
```bash
|
||||
# 在项目根目录执行
|
||||
./scripts/deploy/build-and-push.sh
|
||||
```
|
||||
|
||||
**或者使用 Git Bash(Windows)**:
|
||||
```bash
|
||||
bash scripts/deploy/build-and-push.sh
|
||||
```
|
||||
|
||||
脚本会自动:
|
||||
- 清理旧的构建产物
|
||||
- 安装依赖(如果需要)
|
||||
@@ -73,7 +85,8 @@ git push origin master
|
||||
## 文件说明
|
||||
|
||||
- `Dockerfile.deploy`: 仅用于部署的 Dockerfile,不进行构建,只复制构建产物
|
||||
- `build-and-push.sh`: 本地构建和推送脚本
|
||||
- `build-and-push.sh`: 本地构建和推送脚本(Linux/Mac/Git Bash)
|
||||
- `build-and-push.ps1`: 本地构建和推送脚本(Windows PowerShell)
|
||||
- `.gitea/workflows/deploy-web.yaml`: CI/CD 工作流配置(已修改为仅部署模式)
|
||||
|
||||
## CI/CD 触发条件
|
||||
@@ -132,6 +145,20 @@ git ls-files apps/web-antd/dist
|
||||
### 4. 工作流程建议
|
||||
|
||||
**推荐流程**:
|
||||
|
||||
**Windows PowerShell**:
|
||||
```powershell
|
||||
# 1. 开发阶段:修改源码(不会触发 CI/CD)
|
||||
# 使用你喜欢的编辑器修改 apps/web-antd/src/xxx.vue
|
||||
|
||||
# 2. 测试阶段:本地预览
|
||||
pnpm dev:antd
|
||||
|
||||
# 3. 构建和部署:一键完成
|
||||
.\scripts\deploy\build-and-push.ps1
|
||||
```
|
||||
|
||||
**Linux/Mac/Git Bash**:
|
||||
```bash
|
||||
# 1. 开发阶段:修改源码(不会触发 CI/CD)
|
||||
vim apps/web-antd/src/xxx.vue
|
||||
@@ -139,10 +166,7 @@ vim apps/web-antd/src/xxx.vue
|
||||
# 2. 测试阶段:本地预览
|
||||
pnpm dev:antd
|
||||
|
||||
# 3. 构建阶段:生成构建产物
|
||||
pnpm build:antd
|
||||
|
||||
# 4. 部署阶段:推送构建产物(触发 CI/CD)
|
||||
# 3. 构建和部署:一键完成
|
||||
./scripts/deploy/build-and-push.sh
|
||||
```
|
||||
|
||||
|
||||
68
scripts/deploy/build-and-push.ps1
Normal file
68
scripts/deploy/build-and-push.ps1
Normal file
@@ -0,0 +1,68 @@
|
||||
# 本地构建并推送到仓库的 PowerShell 脚本
|
||||
# 使用方法: .\scripts\deploy\build-and-push.ps1
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
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
|
||||
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"
|
||||
}
|
||||
|
||||
# 3. 安装依赖(如果需要)
|
||||
if (-not (Test-Path "node_modules")) {
|
||||
Write-Host "📥 Installing dependencies..." -ForegroundColor Yellow
|
||||
pnpm install
|
||||
}
|
||||
|
||||
# 4. 构建项目
|
||||
Write-Host "🔨 Building project..." -ForegroundColor Yellow
|
||||
pnpm build:antd
|
||||
|
||||
# 5. 检查构建结果
|
||||
if (-not (Test-Path "apps\web-antd\dist") -or ((Get-ChildItem "apps\web-antd\dist" -ErrorAction SilentlyContinue).Count -eq 0)) {
|
||||
Write-Host "❌ Error: Build failed, dist directory is empty" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
# 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
|
||||
git add apps/web-antd/dist
|
||||
git add -A # 添加其他更改
|
||||
|
||||
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
|
||||
git push origin master
|
||||
|
||||
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
|
||||
}
|
||||
} else {
|
||||
Write-Host "ℹ️ Skipping git push. You can manually commit and push later." -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
Write-Host "✨ Done!" -ForegroundColor Green
|
||||
|
||||
Reference in New Issue
Block a user