Files
note2any/scripts/create_milestone.sh
2025-10-08 09:18:20 +08:00

195 lines
5.8 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# create_milestone.sh - 自动创建项目里程碑版本
# 使用方法: ./create_milestone.sh v1.3.0 "里程碑版本描述"
set -e # 遇到错误立即退出
VERSION=$1
DESCRIPTION=${2:-"里程碑版本"}
if [ -z "$VERSION" ]; then
echo "❌ 错误: 请提供版本号"
echo "使用方法: $0 <version> [description]"
echo "示例: $0 v1.3.0 '批量发布系统完成'"
exit 1
fi
# 版本号格式验证
if [[ ! $VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "❌ 版本号格式错误,应为 vX.X.X 格式 (如: v1.3.0)"
exit 1
fi
# 检查版本是否已存在
if git tag | grep -q "^$VERSION$"; then
echo "❌ 版本 $VERSION 已存在"
exit 1
fi
echo "🚀 开始创建里程碑版本: $VERSION"
# 1. 检查工作目录状态
echo "📋 检查Git状态..."
if ! git diff-index --quiet HEAD --; then
echo "⚠️ 发现未提交的更改,正在自动提交..."
git add .
git commit -m "feat: $DESCRIPTION
版本: $VERSION (里程碑版本)"
fi
# 2. 创建Git标签
echo "🏷️ 创建Git标签..."
git tag -a "$VERSION" -m "$DESCRIPTION
此版本为稳定的里程碑版本,用于后续大规模修改前的对比和回滚基准。
创建时间: $(date '+%Y-%m-%d %H:%M:%S')
Git提交: $(git rev-parse HEAD)"
# 3. 创建发布分支
echo "🌿 创建发布分支..."
git checkout -b "release/$VERSION"
# 4. 构建项目
echo "🔨 构建项目..."
if [ -f package.json ]; then
npm run build
else
echo "⚠️ 未找到package.json跳过构建步骤"
fi
# 5. 创建归档目录
echo "📁 创建归档目录..."
mkdir -p "archives/$VERSION"
# 6. 复制关键文件
echo "📋 复制构建文件..."
for file in main.js manifest.json styles.css package.json; do
if [ -f "$file" ]; then
cp "$file" "archives/$VERSION/"
echo " ✅ 复制 $file"
else
echo " ⚠️ $file 不存在,跳过"
fi
done
echo "📄 复制文档文件..."
for file in README.md CHANGELOG.md detaildesign.md diagrams.md; do
if [ -f "$file" ]; then
cp "$file" "archives/$VERSION/"
echo " ✅ 复制 $file"
else
echo " ⚠️ $file 不存在,跳过"
fi
done
# 7. 创建源码快照
echo "📦 创建源码快照..."
PROJECT_NAME=$(basename "$(pwd)")
cd .. && tar -czf "$PROJECT_NAME/archives/$VERSION/source-snapshot-$VERSION.tar.gz" \
--exclude='node_modules' \
--exclude='.git' \
--exclude='archives' \
"$PROJECT_NAME/"
cd "$PROJECT_NAME"
# 8. 创建版本信息文档
echo "📋 创建版本信息文档..."
cat > "archives/$VERSION/VERSION_INFO.md" << EOF
# 里程碑版本 $VERSION
## 版本信息
- **版本号**: $VERSION
- **发布日期**: $(date +%Y年%m月%d日)
- **Git Tag**: $VERSION
- **Git Branch**: release/$VERSION
- **Git Commit**: $(git rev-parse HEAD)
- **描述**: $DESCRIPTION
## 主要内容
$(if [ -f "archives/$VERSION/main.js" ]; then echo "- 构建文件: main.js ($(du -h "archives/$VERSION/main.js" | cut -f1))"; fi)
$(if [ -f "archives/$VERSION/manifest.json" ]; then echo "- 插件清单: manifest.json"; fi)
$(if [ -f "archives/$VERSION/styles.css" ]; then echo "- 样式文件: styles.css"; fi)
$(if [ -f "archives/$VERSION/README.md" ]; then echo "- 项目文档: README.md"; fi)
$(if [ -f "archives/$VERSION/CHANGELOG.md" ]; then echo "- 变更日志: CHANGELOG.md"; fi)
$(if [ -f "archives/$VERSION/detaildesign.md" ]; then echo "- 设计文档: detaildesign.md"; fi)
$(if [ -f "archives/$VERSION/diagrams.md" ]; then echo "- 架构图表: diagrams.md"; fi)
- 源码快照: source-snapshot-$VERSION.tar.gz ($(du -h "archives/$VERSION/source-snapshot-$VERSION.tar.gz" | cut -f1))
## 回滚说明
如需回滚到此版本:
### 方法1: 使用Git Tag回滚
\`\`\`bash
git checkout $VERSION
git checkout -b rollback-to-$VERSION
\`\`\`
### 方法2: 使用发布分支
\`\`\`bash
git checkout release/$VERSION
\`\`\`
### 方法3: 使用源代码快照
\`\`\`bash
tar -xzf archives/$VERSION/source-snapshot-$VERSION.tar.gz
\`\`\`
### 方法4: 使用构建文件
\`\`\`bash
$(if [ -f "archives/$VERSION/main.js" ]; then echo "cp archives/$VERSION/main.js ./"; fi)
$(if [ -f "archives/$VERSION/manifest.json" ]; then echo "cp archives/$VERSION/manifest.json ./"; fi)
$(if [ -f "archives/$VERSION/styles.css" ]; then echo "cp archives/$VERSION/styles.css ./"; fi)
\`\`\`
## 版本对比
此版本可作为后续重大修改的对比基准,主要用于:
- 功能回归测试
- 性能对比分析
- 代码架构变更评估
- 稳定性基准对比
---
*此版本为稳定的里程碑版本,建议在进行大规模代码修改前保存此状态。*
*创建脚本: scripts/create_milestone.sh*
EOF
# 9. 切换回主分支
echo "🔄 切换回主分支..."
git checkout main
# 10. 推送到远程
echo "☁️ 推送到远程仓库..."
if git remote | grep -q origin; then
echo " 推送主分支和标签..."
git push origin main --tags
echo " 推送发布分支..."
git push origin "release/$VERSION"
echo "✅ 已推送到远程仓库"
else
echo "⚠️ 无远程仓库配置,跳过推送"
fi
# 11. 验证创建结果
echo ""
echo "🔍 验证里程碑创建结果..."
echo "📁 归档目录内容:"
ls -la "archives/$VERSION/" | while read line; do echo " $line"; done
echo ""
echo "🎯 里程碑版本 $VERSION 创建完成!"
echo ""
echo "📋 创建内容:"
echo " - Git标签: $VERSION"
echo " - 发布分支: release/$VERSION"
echo " - 归档目录: archives/$VERSION/"
echo " - 源码快照: source-snapshot-$VERSION.tar.gz"
echo " - 版本文档: VERSION_INFO.md"
echo ""
echo "🔄 快速回滚命令:"
echo " git checkout $VERSION # 使用标签"
echo " git checkout release/$VERSION # 使用分支"
echo " tar -xzf archives/$VERSION/source-snapshot-$VERSION.tar.gz # 使用快照"
echo ""
echo "📖 详细信息请查看: archives/$VERSION/VERSION_INFO.md"