Commit c3a40413 by chunhong.mu

chore(root): update doc and add git-workflow

parent b248f8ae
......@@ -401,7 +401,8 @@ dev ← 总开发分支(release 环境)
dev/official-site-web ← 官网项目开发分支
dev/admin-web ← 管理后台开发分支
hotfix/xxx ← 紧急修复分支
hotfix ← 紧急修复分支(唯一)
refactor ← 重构分支(唯一)
```
### 6.2 分支职责
......@@ -412,73 +413,99 @@ hotfix/xxx ← 紧急修复分支
| `staging` | 预发验证,只接受来自 `dev` 的合并 | 禁止直接提交 | staging |
| `dev` | 总开发分支,所有项目合并入口 | 允许合并 dev/项目名 | release |
| `dev/项目名` | 项目开发分支,日常开发 | 允许直接提交 | - |
| `hotfix/项目名-问题` | 紧急修复 | 无 | - |
| `hotfix` | 紧急修复(唯一分支,所有 hotfix 在此开发) | 无 | - |
| `refactor` | 重构(唯一分支,所有重构在此开发) | 无 | - |
### 6.3 分支命名规范
| 类型 | 命名格式 | 示例 |
|------|---------|------|
| 项目开发分支 | `dev/项目名` | `dev/official-site-web``dev/admin-web` |
| 紧急修复 | `hotfix/项目名-问题` | `hotfix/official-site-web-payment-fail` |
| 重构分支 | `refactor/模块名` | `refactor/auth-module` |
| 紧急修复 | `hotfix`(固定名称) | 所有紧急修复都在此分支 |
| 重构 | `refactor`(固定名称) | 所有重构都在此分支 |
### 6.4 工作流
### 6.4 工作流脚本
**1. 新功能开发**
项目提供 `scripts/git-workflow.js` 脚本,可通过 npm scripts 执行
```bash
# 从 dev 创建项目开发分支
git checkout dev
git pull
git checkout -b dev/official-site-web
# 创建项目开发分支
pnpm git:feature official-site-web
# 合并项目分支到 dev
pnpm git:merge official-site-web
# 发布预发(dev → staging)
pnpm git:release
# 发布生产(staging → release)
pnpm git:publish
# 创建 hotfix 分支
pnpm git:hotfix
# 合并 hotfix 到 release 和 dev
pnpm git:hotfix:merge
# 创建 refactor 分支
pnpm git:refactor
# 合并 refactor 到 dev
pnpm git:refactor:merge
```
### 6.5 工作流说明
**1. 新功能开发**
```bash
pnpm git:feature official-site-web
# 日常开发直接在 dev/official-site-web 提交
# 小 bug 也直接在此分支修复
# 开发完成后合并回 dev
git checkout dev
git merge dev/official-site-web --no-ff
git push origin dev
pnpm git:merge official-site-web # 合并回 dev
```
**2. 测试通过,发布预发**
**2. 发布预发**
```bash
# dev 合并到 staging
git checkout staging
git merge dev --no-ff
git push origin staging
pnpm git:release # dev → staging
```
**3. 预发验证通过,发布生产**
**3. 发布生产**
```bash
# staging 合并到 release,打 tag
git checkout release
git merge staging --no-ff
git tag -a v1.0.0 -m "release v1.0.0"
git push origin release --tags
pnpm git:publish # staging → release,自动打 tag
```
**4. 紧急修复(hotfix)**
**4. 紧急修复**
```bash
# 从 release 创建 hotfix 分支
git checkout release
git checkout -b hotfix/official-site-web-payment-fail
# 修复完成后,同时合并回 release 和 dev
git checkout release
git merge hotfix/official-site-web-payment-fail --no-ff
git checkout dev
git merge hotfix/official-site-web-payment-fail --no-ff
git branch -d hotfix/official-site-web-payment-fail
pnpm git:hotfix # 创建/切换到 hotfix 分支
# 修复...
pnpm git:hotfix:merge # 合并到 release 和 dev
```
### 6.5 提交规范
**5. 重构**
```bash
pnpm git:refactor # 创建/切换到 refactor 分支
# 重构...
pnpm git:refactor:merge # 合并到 dev
```
### 6.6 提交规范
Commit 信息格式:`type(scope): description`
**scope 为子包全名**
| 子包 | scope |
|------|-------|
| `official-site-web` | `official-site-web` |
| `admin-web` | `admin-web` |
| 根目录配置 | `root` |
| type | 说明 |
| ---------- | --------- |
| `feat` | 新功能 |
......@@ -490,3 +517,4 @@ Commit 信息格式:`type(scope): description`
| `test` | 测试 |
示例:`feat(official-site-web): 添加首页 banner 功能`
示例:`chore(root): 更新 ESLint 配置`
......@@ -9,7 +9,15 @@
"build:project": "tsx scripts/build.ts",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prepare": "husky"
"prepare": "husky",
"git:feature": "tsx scripts/git-workflow.ts feature",
"git:merge": "tsx scripts/git-workflow.ts merge",
"git:release": "tsx scripts/git-workflow.ts release",
"git:publish": "tsx scripts/git-workflow.ts publish",
"git:hotfix": "tsx scripts/git-workflow.ts hotfix",
"git:hotfix:merge": "tsx scripts/git-workflow.ts hotfix:merge",
"git:refactor": "tsx scripts/git-workflow.ts refactor",
"git:refactor:merge": "tsx scripts/git-workflow.ts refactor:merge"
},
"devDependencies": {
"@antfu/eslint-config": "^3.9.2",
......
import { execSync } from 'node:child_process'
const command = process.argv[2]
const projectName = process.argv[3]
const commands = {
'feature': () =>
{
if (!projectName)
{
console.error('Usage: pnpm git:feature <project-name>')
console.error('Example: pnpm git:feature official-site-web')
process.exit(1)
}
const branchName = `dev/${projectName}`
console.log(`Creating branch: ${branchName}`)
execSync('git checkout dev', { stdio: 'inherit' })
execSync('git pull', { stdio: 'inherit' })
execSync(`git checkout -b ${branchName}`, { stdio: 'inherit' })
console.log(`Switched to ${branchName}`)
},
'merge': () =>
{
if (!projectName)
{
console.error('Usage: pnpm git:merge <project-name>')
console.error('Example: pnpm git:merge official-site-web')
process.exit(1)
}
const branchName = `dev/${projectName}`
console.log(`Merging ${branchName} into dev`)
execSync('git checkout dev', { stdio: 'inherit' })
execSync(`git merge ${branchName} --no-ff`, { stdio: 'inherit' })
execSync('git push origin dev', { stdio: 'inherit' })
console.log('Merge completed')
},
'release': () =>
{
console.log('Releasing dev to staging...')
execSync('git checkout staging', { stdio: 'inherit' })
execSync('git merge dev --no-ff', { stdio: 'inherit' })
execSync('git push origin staging', { stdio: 'inherit' })
console.log('Released to staging')
},
'publish': () =>
{
console.log('Publishing staging to release...')
const version = process.argv[3] || 'v1.0.0'
execSync('git checkout release', { stdio: 'inherit' })
execSync('git merge staging --no-ff', { stdio: 'inherit' })
execSync(`git tag -a ${version} -m "release ${version}"`, { stdio: 'inherit' })
execSync(`git push origin release --tags`, { stdio: 'inherit' })
console.log(`Published to release with tag ${version}`)
},
'hotfix': () =>
{
console.log('Creating hotfix branch...')
execSync('git checkout release', { stdio: 'inherit' })
execSync('git checkout -b hotfix || git checkout hotfix', { stdio: 'inherit' })
console.log('Switched to hotfix branch')
},
'hotfix:merge': () =>
{
console.log('Merging hotfix to release and dev...')
execSync('git checkout release', { stdio: 'inherit' })
execSync('git merge hotfix --no-ff', { stdio: 'inherit' })
execSync('git push origin release', { stdio: 'inherit' })
execSync('git checkout dev', { stdio: 'inherit' })
execSync('git merge hotfix --no-ff', { stdio: 'inherit' })
execSync('git push origin dev', { stdio: 'inherit' })
console.log('Hotfix merged to release and dev')
},
'refactor': () =>
{
console.log('Creating refactor branch...')
execSync('git checkout dev', { stdio: 'inherit' })
execSync('git checkout -b refactor || git checkout refactor', { stdio: 'inherit' })
console.log('Switched to refactor branch')
},
'refactor:merge': () =>
{
console.log('Merging refactor to dev...')
execSync('git checkout dev', { stdio: 'inherit' })
execSync('git merge refactor --no-ff', { stdio: 'inherit' })
execSync('git push origin dev', { stdio: 'inherit' })
console.log('Refactor merged to dev')
},
}
if (!command || !commands[command])
{
console.log('Git Workflow Commands:')
console.log(' pnpm git:feature <project> - Create dev/<project> branch')
console.log(' pnpm git:merge <project> - Merge dev/<project> into dev')
console.log(' pnpm git:release - Release dev to staging')
console.log(' pnpm git:publish [version] - Publish staging to release')
console.log(' pnpm git:hotfix - Create/switch to hotfix branch')
console.log(' pnpm git:hotfix:merge - Merge hotfix to release and dev')
console.log(' pnpm git:refactor - Create/switch to refactor branch')
console.log(' pnpm git:refactor:merge - Merge refactor to dev')
process.exit(0)
}
commands[command]()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment