2025-12-23 13:43:32 +08:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
|
|
# 本地构建并推送到仓库的脚本
|
|
|
|
|
|
# 使用方法: ./scripts/deploy/build-and-push.sh
|
|
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
|
|
echo "🚀 Starting local build and push process..."
|
|
|
|
|
|
|
|
|
|
|
|
# 1. 检查是否在项目根目录
|
|
|
|
|
|
if [ ! -f "package.json" ]; then
|
|
|
|
|
|
echo "❌ Error: Please run this script from project root"
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# 2. 清理旧的构建产物
|
|
|
|
|
|
echo "📦 Cleaning old build artifacts..."
|
|
|
|
|
|
rm -rf apps/web-antd/dist
|
|
|
|
|
|
|
|
|
|
|
|
# 3. 安装依赖(如果需要)
|
|
|
|
|
|
if [ ! -d "node_modules" ]; then
|
|
|
|
|
|
echo "📥 Installing dependencies..."
|
|
|
|
|
|
pnpm install
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# 4. 构建项目
|
|
|
|
|
|
echo "🔨 Building project..."
|
2025-12-23 14:05:04 +08:00
|
|
|
|
# 确保使用生产环境模式构建,避免使用开发环境配置
|
|
|
|
|
|
export NODE_ENV=production
|
2025-12-23 13:43:32 +08:00
|
|
|
|
pnpm build:antd
|
|
|
|
|
|
|
|
|
|
|
|
# 5. 检查构建结果
|
|
|
|
|
|
if [ ! -d "apps/web-antd/dist" ] || [ -z "$(ls -A apps/web-antd/dist)" ]; then
|
|
|
|
|
|
echo "❌ Error: Build failed, dist directory is empty"
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
echo "✅ Build successful!"
|
|
|
|
|
|
|
|
|
|
|
|
# 6. 显示构建产物大小
|
|
|
|
|
|
BUILD_SIZE=$(du -sh apps/web-antd/dist | cut -f1)
|
|
|
|
|
|
echo "📊 Build size: $BUILD_SIZE"
|
|
|
|
|
|
|
|
|
|
|
|
# 7. 提交并推送(可选)
|
|
|
|
|
|
read -p "Do you want to commit and push to repository? (y/n) " -n 1 -r
|
|
|
|
|
|
echo
|
|
|
|
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
|
|
|
|
# 检查是否有未提交的更改
|
|
|
|
|
|
if [ -n "$(git status --porcelain)" ]; then
|
|
|
|
|
|
echo "📝 Staging build artifacts..."
|
2025-12-23 13:53:31 +08:00
|
|
|
|
# 使用 -f 强制添加被 .gitignore 忽略的 dist 目录
|
|
|
|
|
|
git add -f apps/web-antd/dist
|
2025-12-23 13:43:32 +08:00
|
|
|
|
git add -A # 添加其他更改
|
|
|
|
|
|
|
|
|
|
|
|
echo "💾 Committing changes..."
|
2025-12-23 14:05:04 +08:00
|
|
|
|
# 使用 --no-verify 跳过 pre-commit hooks,避免检查大量构建产物文件
|
2025-12-23 14:09:26 +08:00
|
|
|
|
# 注意:不要使用 [skip ci],否则 CI/CD 不会触发
|
|
|
|
|
|
git commit --no-verify -m "chore: build and deploy web-antd" || true
|
2025-12-23 13:43:32 +08:00
|
|
|
|
|
|
|
|
|
|
echo "📤 Pushing to repository..."
|
|
|
|
|
|
git push origin master
|
|
|
|
|
|
|
|
|
|
|
|
echo "✅ Build artifacts pushed successfully!"
|
|
|
|
|
|
echo "⏳ Waiting for CI/CD to deploy..."
|
|
|
|
|
|
else
|
|
|
|
|
|
echo "ℹ️ No changes to commit"
|
|
|
|
|
|
fi
|
|
|
|
|
|
else
|
|
|
|
|
|
echo "ℹ️ Skipping git push. You can manually commit and push later."
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
echo "✨ Done!"
|
|
|
|
|
|
|