项目结构调整

This commit is contained in:
CaiXiang
2025-11-15 14:31:47 +08:00
parent a77ae6fac1
commit ec1d6f0cee
12 changed files with 2242 additions and 110 deletions

229
scripts/archive_bug_fix.sh Normal file
View File

@@ -0,0 +1,229 @@
#!/bin/bash
# Bug修复归档脚本
# 用途: 自动创建Bug修复归档目录结构并生成文档模板
set -e
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 打印带颜色的信息
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# 检查是否在项目根目录
check_project_root() {
if [ ! -f "FILE_ORGANIZATION.md" ]; then
print_error "请在项目根目录运行此脚本"
exit 1
fi
}
# 显示使用说明
show_usage() {
echo "使用方法: $0 <bug名称> [作者名称]"
echo ""
echo "示例:"
echo " $0 path_tracking_error \"张三\""
echo " $0 csv_load_issue"
echo ""
echo "说明:"
echo " - bug名称使用英文和下划线如: path_tracking_error"
echo " - 作者名称可选默认从git config获取"
exit 1
}
# 获取当前日期
get_date() {
date +%Y%m%d
}
# 获取作者名称
get_author() {
if [ -n "$1" ]; then
echo "$1"
else
git config user.name || echo "Unknown"
fi
}
# 获取最新的commit信息
get_latest_commit() {
if git rev-parse --git-dir > /dev/null 2>&1; then
echo "$(git rev-parse --short HEAD)"
else
echo "N/A"
fi
}
# 创建归档目录
create_archive_dirs() {
local date=$1
local bug_name=$2
local archive_path="archives/bug_fixes/${date}_${bug_name}"
print_info "创建归档目录: ${archive_path}"
mkdir -p "${archive_path}/code"
mkdir -p "${archive_path}/docs"
mkdir -p "${archive_path}/tests"
mkdir -p "docs/fixes"
print_success "目录创建完成"
echo "${archive_path}"
}
# 生成文档
create_document() {
local date=$1
local bug_name=$2
local author=$3
local commit_hash=$4
local archive_path=$5
local doc_name="BUG_${bug_name}_${date}.md"
local doc_path="${archive_path}/docs/${doc_name}"
local template_path=".claude/templates/bug_fix_template.md"
print_info "生成文档: ${doc_name}"
# 如果模板存在,使用模板;否则创建基本文档
if [ -f "${template_path}" ]; then
cp "${template_path}" "${doc_path}"
# 替换模板变量
sed -i "s/{{BUG_DESCRIPTION}}/${bug_name}/g" "${doc_path}"
sed -i "s/{{DATE}}/${date}/g" "${doc_path}"
sed -i "s/{{AUTHOR}}/${author}/g" "${doc_path}"
sed -i "s/{{COMMIT_HASH}}/${commit_hash}/g" "${doc_path}"
sed -i "s/{{DATE}}_{{BUG_NAME}}/${date}_${bug_name}/g" "${doc_path}"
else
# 创建基本文档
cat > "${doc_path}" << EOF
# Bug修复: ${bug_name}
**日期**: ${date}
**修复者**: ${author}
**Git Commit**: ${commit_hash}
---
## Bug描述
[详细描述bug的表现]
## 复现步骤
1. [步骤1]
2. [步骤2]
3. [观察到的错误]
## 根本原因
[分析bug的根本原因]
## 修复方案
[描述修复方案]
## 修改文件清单
- \`file1.cpp\` - [修改说明]
## 测试验证
[测试结果]
## Git提交信息
\`\`\`
Commit ID: ${commit_hash}
\`\`\`
---
**归档位置**: \`archives/bug_fixes/${date}_${bug_name}/\`
EOF
fi
# 复制到快速查阅目录
cp "${doc_path}" "docs/fixes/${doc_name}"
print_success "文档生成完成"
echo "${doc_path}"
}
# 显示下一步操作
show_next_steps() {
local doc_path=$1
local archive_path=$2
echo ""
print_success "Bug修复归档创建完成!"
echo ""
echo "📁 归档目录: ${archive_path}"
echo "📄 文档位置: ${doc_path}"
echo "📋 快速查阅: docs/fixes/"
echo ""
print_info "下一步操作:"
echo " 1. 编辑文档: vim ${doc_path}"
echo " 2. 复制修复的代码到: ${archive_path}/code/"
echo " 3. 添加测试文件到: ${archive_path}/tests/"
echo " 4. 提交git: git add . && git commit -m \"archive: Bug修复 - ${bug_name}\""
echo ""
}
# 主函数
main() {
# 检查参数
if [ $# -lt 1 ]; then
show_usage
fi
local bug_name=$1
local author=$(get_author "$2")
# 检查项目根目录
check_project_root
# 获取信息
local date=$(get_date)
local commit_hash=$(get_latest_commit)
print_info "开始创建Bug修复归档"
print_info "Bug名称: ${bug_name}"
print_info "日期: ${date}"
print_info "作者: ${author}"
print_info "Commit: ${commit_hash}"
echo ""
# 创建目录
local archive_path=$(create_archive_dirs "${date}" "${bug_name}")
# 生成文档
local doc_path=$(create_document "${date}" "${bug_name}" "${author}" "${commit_hash}" "${archive_path}")
# 显示下一步操作
show_next_steps "${doc_path}" "${archive_path}"
}
# 运行主函数
main "$@"

251
scripts/archive_feature.sh Normal file
View File

@@ -0,0 +1,251 @@
#!/bin/bash
# 功能更新归档脚本
# 用途: 自动创建功能更新归档目录结构,并生成文档模板
set -e
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 打印带颜色的信息
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# 检查是否在项目根目录
check_project_root() {
if [ ! -f "FILE_ORGANIZATION.md" ]; then
print_error "请在项目根目录运行此脚本"
exit 1
fi
}
# 显示使用说明
show_usage() {
echo "使用方法: $0 <功能名称> [开发者名称]"
echo ""
echo "示例:"
echo " $0 adaptive_lookahead \"李四\""
echo " $0 dynamic_obstacle_avoidance"
echo ""
echo "说明:"
echo " - 功能名称使用英文和下划线,如: adaptive_lookahead"
echo " - 开发者名称可选默认从git config获取"
exit 1
}
# 获取当前日期
get_date() {
date +%Y%m%d
}
# 获取开发者名称
get_developer() {
if [ -n "$1" ]; then
echo "$1"
else
git config user.name || echo "Unknown"
fi
}
# 获取最新的commit信息
get_latest_commit() {
if git rev-parse --git-dir > /dev/null 2>&1; then
echo "$(git rev-parse --short HEAD)"
else
echo "N/A"
fi
}
# 创建归档目录
create_archive_dirs() {
local date=$1
local feature_name=$2
local archive_path="archives/updates/${date}_${feature_name}"
print_info "创建归档目录: ${archive_path}"
mkdir -p "${archive_path}/code"
mkdir -p "${archive_path}/docs"
mkdir -p "${archive_path}/tests"
mkdir -p "docs/updates"
print_success "目录创建完成"
echo "${archive_path}"
}
# 生成文档
create_document() {
local date=$1
local feature_name=$2
local developer=$3
local commit_hash=$4
local archive_path=$5
local doc_name="UPDATE_${feature_name}_${date}.md"
local doc_path="${archive_path}/docs/${doc_name}"
local template_path=".claude/templates/feature_update_template.md"
print_info "生成文档: ${doc_name}"
# 如果模板存在,使用模板;否则创建基本文档
if [ -f "${template_path}" ]; then
cp "${template_path}" "${doc_path}"
# 替换模板变量
sed -i "s/{{FEATURE_NAME}}/${feature_name}/g" "${doc_path}"
sed -i "s/{{DATE}}/${date}/g" "${doc_path}"
sed -i "s/{{AUTHOR}}/${developer}/g" "${doc_path}"
sed -i "s/{{COMMIT_HASH}}/${commit_hash}/g" "${doc_path}"
sed -i "s/{{DATE}}_{{FEATURE_NAME}}/${date}_${feature_name}/g" "${doc_path}"
else
# 创建基本文档
cat > "${doc_path}" << EOF
# 功能更新: ${feature_name}
**日期**: ${date}
**开发者**: ${developer}
**Git Commit**: ${commit_hash}
---
## 功能概述
[简要描述新功能的目的和价值]
## 需求背景
[详细描述需求背景和使用场景]
## 设计方案
[技术设计方案描述]
### 架构设计
[架构设计说明]
### API设计
\`\`\`cpp
// 接口定义
\`\`\`
## 实现细节
### 新增文件
- \`file1.cpp\` - [文件说明]
### 修改文件
- \`file2.cpp\` - [修改说明]
## 使用方法
\`\`\`cpp
// 使用示例
\`\`\`
## 测试验证
[测试结果]
## Git提交信息
\`\`\`
Commit ID: ${commit_hash}
\`\`\`
## 后续计划
- [ ] [待完善项1]
- [ ] [待完善项2]
---
**归档位置**: \`archives/updates/${date}_${feature_name}/\`
EOF
fi
# 复制到快速查阅目录
cp "${doc_path}" "docs/updates/${doc_name}"
print_success "文档生成完成"
echo "${doc_path}"
}
# 显示下一步操作
show_next_steps() {
local doc_path=$1
local archive_path=$2
echo ""
print_success "功能更新归档创建完成!"
echo ""
echo "📁 归档目录: ${archive_path}"
echo "📄 文档位置: ${doc_path}"
echo "📋 快速查阅: docs/updates/"
echo ""
print_info "下一步操作:"
echo " 1. 编辑文档: vim ${doc_path}"
echo " 2. 复制新增/修改的代码到: ${archive_path}/code/"
echo " 3. 添加测试文件到: ${archive_path}/tests/"
echo " 4. 更新使用示例到: examples/"
echo " 5. 提交git: git add . && git commit -m \"feature: ${feature_name}\""
echo ""
}
# 主函数
main() {
# 检查参数
if [ $# -lt 1 ]; then
show_usage
fi
local feature_name=$1
local developer=$(get_developer "$2")
# 检查项目根目录
check_project_root
# 获取信息
local date=$(get_date)
local commit_hash=$(get_latest_commit)
print_info "开始创建功能更新归档"
print_info "功能名称: ${feature_name}"
print_info "日期: ${date}"
print_info "开发者: ${developer}"
print_info "Commit: ${commit_hash}"
echo ""
# 创建目录
local archive_path=$(create_archive_dirs "${date}" "${feature_name}")
# 生成文档
local doc_path=$(create_document "${date}" "${feature_name}" "${developer}" "${commit_hash}" "${archive_path}")
# 显示下一步操作
show_next_steps "${doc_path}" "${archive_path}"
}
# 运行主函数
main "$@"

373
scripts/create_release.sh Normal file
View File

@@ -0,0 +1,373 @@
#!/bin/bash
# 版本发布脚本
# 用途: 创建版本发布归档生成release notes创建git tag
set -e
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 打印带颜色的信息
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# 检查是否在项目根目录
check_project_root() {
if [ ! -f "FILE_ORGANIZATION.md" ]; then
print_error "请在项目根目录运行此脚本"
exit 1
fi
}
# 检查是否在git仓库中
check_git_repo() {
if ! git rev-parse --git-dir > /dev/null 2>&1; then
print_error "不在git仓库中"
exit 1
fi
}
# 显示使用说明
show_usage() {
echo "使用方法: $0 <版本号> [发布类型]"
echo ""
echo "参数:"
echo " 版本号 格式: X.Y.Z (如: 1.2.0)"
echo " 发布类型 Major | Minor | Patch (可选,默认根据版本号判断)"
echo ""
echo "示例:"
echo " $0 1.2.0"
echo " $0 1.2.0 Minor"
echo " $0 2.0.0 Major"
echo ""
echo "说明:"
echo " - Major: 重大版本更新可能包含不兼容的API变更"
echo " - Minor: 次要版本更新,新增功能但向后兼容"
echo " - Patch: 补丁版本仅包含bug修复"
exit 1
}
# 验证版本号格式
validate_version() {
local version=$1
if ! [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
print_error "版本号格式错误,应为 X.Y.Z"
exit 1
fi
}
# 判断发布类型
determine_release_type() {
local version=$1
local provided_type=$2
if [ -n "$provided_type" ]; then
echo "$provided_type"
return
fi
# 自动判断
local last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
local last_version=${last_tag#v}
IFS='.' read -r -a curr_parts <<< "$version"
IFS='.' read -r -a last_parts <<< "$last_version"
if [ "${curr_parts[0]}" -gt "${last_parts[0]}" ]; then
echo "Major"
elif [ "${curr_parts[1]}" -gt "${last_parts[1]}" ]; then
echo "Minor"
else
echo "Patch"
fi
}
# 获取当前日期
get_date() {
date +%Y-%m-%d
}
# 创建版本归档目录
create_version_dirs() {
local version=$1
local version_path="archives/versions/v${version}"
print_info "创建版本归档目录: ${version_path}"
mkdir -p "${version_path}/backup"
print_success "目录创建完成"
echo "${version_path}"
}
# 获取commit统计
get_commit_stats() {
local last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$last_tag" ]; then
# 如果没有tag统计所有commit
git rev-list --count HEAD
else
# 统计从上个tag到现在的commit
git rev-list --count ${last_tag}..HEAD
fi
}
# 获取变更的文件数
get_changed_files() {
local last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$last_tag" ]; then
git diff --name-only --diff-filter=ACMR | wc -l
else
git diff --name-only --diff-filter=ACMR ${last_tag}..HEAD | wc -l
fi
}
# 生成release notes
create_release_notes() {
local version=$1
local release_type=$2
local release_date=$3
local version_path=$4
local notes_path="${version_path}/release_notes.md"
local template_path=".claude/templates/release_notes_template.md"
print_info "生成Release Notes: ${notes_path}"
local commit_count=$(get_commit_stats)
local file_count=$(get_changed_files)
local last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
local last_version=${last_tag#v}
# 如果模板存在,使用模板
if [ -f "${template_path}" ]; then
cp "${template_path}" "${notes_path}"
# 替换模板变量
sed -i "s/{{VERSION}}/${version}/g" "${notes_path}"
sed -i "s/{{RELEASE_DATE}}/${release_date}/g" "${notes_path}"
sed -i "s/{{RELEASE_TYPE}}/${release_type}/g" "${notes_path}"
sed -i "s/{{COMMIT_COUNT}}/${commit_count}/g" "${notes_path}"
sed -i "s/{{FILE_COUNT}}/${file_count}/g" "${notes_path}"
sed -i "s/{{OLD_VERSION}}/${last_version}/g" "${notes_path}"
sed -i "s/{{PREVIOUS_VERSION}}/${last_version}/g" "${notes_path}"
else
# 创建基本release notes
cat > "${notes_path}" << EOF
# Release Notes - v${version}
**发布日期**: ${release_date}
**版本号**: ${version}
**发布类型**: ${release_type}
---
## 版本概述
[简要描述本版本的主要更新内容]
## 重要变更 ⚠️
[列出所有重大变更]
## 新增功能 ✨
- [功能1]
- [功能2]
## Bug修复 🐛
- [Bug修复1]
- [Bug修复2]
## 性能优化 🚀
- [优化项1]
- [优化项2]
## 统计数据
- **总提交数**: ${commit_count}
- **修改文件数**: ${file_count}
- **上一版本**: ${last_version}
## 升级指南
### 从 v${last_version} 升级
1. 备份当前版本
2. 更新代码
3. 重新编译
4. 测试验证
## 获取此版本
\`\`\`bash
git clone <repo_url>
git checkout v${version}
\`\`\`
---
**归档位置**: \`archives/versions/v${version}/\`
EOF
fi
print_success "Release Notes生成完成"
echo "${notes_path}"
}
# 创建git tag
create_git_tag() {
local version=$1
local tag_name="v${version}"
print_info "检查是否已存在tag: ${tag_name}"
if git rev-parse "${tag_name}" >/dev/null 2>&1; then
print_warning "Tag ${tag_name} 已存在"
read -p "是否删除并重新创建? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
git tag -d "${tag_name}"
print_info "已删除旧tag"
else
print_info "跳过创建tag"
return
fi
fi
print_info "创建git tag: ${tag_name}"
git tag -a "${tag_name}" -m "Release version ${version}"
print_success "Git tag创建完成"
echo ""
print_info "推送tag到远程仓库:"
echo " git push origin ${tag_name}"
}
# 可选:备份代码
backup_code() {
local version_path=$1
echo ""
read -p "是否备份完整代码到归档目录? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
print_info "创建代码备份..."
local backup_file="${version_path}/backup/source_code.tar.gz"
tar -czf "${backup_file}" \
--exclude='.git' \
--exclude='build' \
--exclude='archives' \
--exclude='*.o' \
--exclude='*.so' \
--exclude='*.dll' \
src/ include/ examples/ CMakeLists.txt
print_success "代码备份完成: ${backup_file}"
else
print_info "跳过代码备份"
fi
}
# 显示下一步操作
show_next_steps() {
local version=$1
local notes_path=$2
local version_path=$3
echo ""
print_success "版本发布归档创建完成!"
echo ""
echo "📁 版本目录: ${version_path}"
echo "📄 Release Notes: ${notes_path}"
echo "🏷️ Git Tag: v${version}"
echo ""
print_info "下一步操作:"
echo " 1. 编辑Release Notes: vim ${notes_path}"
echo " 2. 检查并补充版本信息"
echo " 3. 提交归档: git add archives/versions/ && git commit -m \"release: v${version}\""
echo " 4. 推送tag: git push origin v${version}"
echo " 5. 在GitHub/GitLab创建Release"
echo ""
}
# 主函数
main() {
# 检查参数
if [ $# -lt 1 ]; then
show_usage
fi
local version=$1
local release_type=$2
# 验证版本号
validate_version "${version}"
# 检查环境
check_project_root
check_git_repo
# 确定发布类型
release_type=$(determine_release_type "${version}" "${release_type}")
# 获取日期
local release_date=$(get_date)
print_info "开始创建版本发布"
print_info "版本号: ${version}"
print_info "发布类型: ${release_type}"
print_info "发布日期: ${release_date}"
echo ""
# 确认
read -p "确认创建版本 v${version}? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_info "取消操作"
exit 0
fi
# 创建版本目录
local version_path=$(create_version_dirs "${version}")
# 生成Release Notes
local notes_path=$(create_release_notes "${version}" "${release_type}" "${release_date}" "${version_path}")
# 创建Git Tag
create_git_tag "${version}"
# 可选备份
backup_code "${version_path}"
# 显示下一步操作
show_next_steps "${version}" "${notes_path}" "${version_path}"
}
# 运行主函数
main "$@"