Skip to content

Commit 9941a6e

Browse files
author
echoVic
committed
feat(release): 增强发布脚本并迁移存档目录
- 重构发布脚本以支持自动生成变更日志内容 - 将存档目录从项目内 `.bar/` 迁移到用户主目录 `~/.bar/projects/` - 更新相关文档以反映新的目录结构
1 parent 2e2f504 commit 9941a6e

5 files changed

Lines changed: 139 additions & 45 deletions

File tree

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.0.15] - 2026-02-04
9+
10+
### Changed
11+
- **存档目录迁移**: 从项目内 `.bar/` 迁移到用户主目录 `~/.bar/projects/<project>-<hash4>/`
12+
- 发布脚本增强:支持 `patch/minor/major` 语义化版本命令
13+
14+
### Added
15+
- `internal/util/path/path_test.go` 单元测试
16+
- `CHANGELOG.md` 变更日志
17+
18+
### Removed
19+
- `checkGitignore()` 函数
20+
21+
## [0.0.14] - 2026-02-04
22+
23+
### Changed
24+
- **存档目录迁移**: 从项目内 `.bar/` 迁移到用户主目录 `~/.bar/projects/<project>-<hash4>/`
25+
26+
### Added
27+
- `internal/util/path/path_test.go` 单元测试
28+
29+
### Removed
30+
- `checkGitignore()` 函数
31+
832
## [0.0.13] - 2026-02-01
933

1034
### Changed

docs/architecture.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
3535
┌─────────────────────────────────────────────────────────────────┐
3636
│ Storage Layer │
37-
│ .bar/ │
37+
│ ~/.bar/projects/<project>-<hash4>/ │
38+
│ ├── state.json # 全局状态 │
39+
│ ├── config.yaml # 配置文件 │
3840
│ ├── tasks/<task_id>/ │
3941
│ │ ├── task.json # Task 元信息 │
4042
│ │ ├── ledger.jsonl # Step 日志(追加写入) │
@@ -93,7 +95,7 @@ type WorkspaceManager interface {
9395
**实现细节**
9496
- 使用 `git worktree add` 创建隔离工作区
9597
- 分支命名:`bar/<task-name>-<short-id>`
96-
- Worktree 路径:`.bar/workspaces/<task_id>`
98+
- Worktree 路径:`~/.bar/projects/<project>-<hash4>/workspaces/<task_id>`
9799

98100
### 3. Ledger Manager (`internal/core/ledger`)
99101

@@ -288,7 +290,7 @@ const (
288290

289291
### 1. 自定义 Policy
290292

291-
用户可以在 `.bar/policy.yaml` 中定义自己的规则。
293+
用户可以在项目根目录的 `.bar/policy.yaml` 中定义自己的规则。
292294

293295
### 2. 自定义 Hooks
294296

docs/cli.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ bar init [flags]
4141

4242
**行为:**
4343
1. 检查当前目录是否是 git 仓库
44-
2. 创建 `.bar/` 目录结构
45-
3. 创建默认配置文件 `.bar/config.yaml`
46-
4. 添加 `.bar/workspaces/``.gitignore`
44+
2.`~/.bar/projects/<project>-<hash4>/` 创建目录结构
45+
3. 创建默认配置文件
4746

4847
**示例:**
4948
```bash
5049
cd my-project
5150
bar init
52-
# Output: Initialized BAR in /path/to/my-project/.bar/
51+
# Output: Initialized BAR in ~/.bar/projects/my-project-a3f2/
5352
```
5453

5554
**错误情况:**
@@ -81,7 +80,7 @@ bar task start <name> [flags]
8180
8281
**行为:**
8382
1. 生成唯一的 task ID(nanoid,8 字符)
84-
2. 创建 git worktree`.bar/workspaces/<task_id>`
83+
2. 创建 git worktree
8584
3. 创建分支:`bar/<name>-<short_id>`
8685
4. 初始化 task.json 和 ledger.jsonl
8786
5. 设置为当前 active task
@@ -91,14 +90,12 @@ bar task start <name> [flags]
9190
bar task start fix-null-pointer
9291
# Output:
9392
# Created task: fix-null-pointer (id: abc123)
94-
# Workspace: .bar/workspaces/abc123
9593
# Branch: bar/fix-null-pointer-abc123
9694
# Switched to task: fix-null-pointer
9795

9896
bar task start experiment --base develop --no-switch
9997
# Output:
10098
# Created task: experiment (id: def456)
101-
# Workspace: .bar/workspaces/def456
10299
# Branch: bar/experiment-def456
103100
```
104101

@@ -461,7 +458,7 @@ bar log --format markdown --output report.md
461458

462459
| 变量 | 说明 | 默认值 |
463460
|------|------|--------|
464-
| `BAR_HOME` | BAR 数据目录 | .bar |
465-
| `BAR_CONFIG` | 配置文件路径 | .bar/config.yaml |
461+
| `BAR_HOME` | BAR 数据目录 | ~/.bar |
462+
| `BAR_CONFIG` | 配置文件路径 | ~/.bar/projects/<project>/config.yaml |
466463
| `BAR_VERBOSE` | 详细输出 | false |
467464
| `BAR_NO_COLOR` | 禁用颜色输出 | false |

docs/data-model.md

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,35 @@
22

33
## 目录结构
44

5+
存档目录位于用户主目录 `~/.bar/`,按项目组织:
6+
57
```
6-
your-repo/
7-
── .bar/ # BAR 数据根目录
8-
── config.yaml # 全局配置
9-
├── state.json # 全局状态(当前 active task)
10-
├── tasks/ # 任务数据
11-
── <task_id>/
12-
── task.json # 任务元信息
13-
│ ├── ledger.jsonl # 操作日志(JSONL 格式)
14-
└── artifacts/ # 产物文件
15-
── 0001.patch # Step 1 的 diff
16-
│ ├── 0001.output # Step 1 的输出
17-
│ ├── 0002.patch
18-
│ ├── 0002.output
19-
── ...
20-
└── workspaces/ # Git Worktree 目录
21-
└── <task_id>/ # 每个 task 一个 worktree
22-
└── ... (your code)
8+
~/.bar/
9+
── projects/
10+
── <project_name>-<hash4>/ # 如 my-project-a3f2
11+
├── config.yaml # 项目配置
12+
├── state.json # 全局状态(当前 active task)
13+
── tasks/ # 任务数据
14+
│ └── <task_id>/
15+
│ ├── task.json # 任务元信息
16+
├── ledger.jsonl # 操作日志(JSONL 格式)
17+
── artifacts/ # 产物文件
18+
│ ├── 0001.patch # Step 1 的 diff
19+
│ ├── 0001.output # Step 1 的输出
20+
│ ├── 0002.patch
21+
── 0002.output
22+
└── ...
23+
└── workspaces/ # Git Worktree 目录
24+
└── <task_id>/ # 每个 task 一个 worktree
2325
```
2426

2527
---
2628

2729
## 配置文件
2830

29-
### `.bar/config.yaml`
31+
### `config.yaml`
3032

31-
全局配置文件`bar init` 时创建。
33+
项目配置文件`bar init` 时创建,位于 `~/.bar/projects/<project>-<hash4>/config.yaml`
3234

3335
```yaml
3436
version: 1
@@ -66,9 +68,9 @@ output:
6668

6769
---
6870

69-
### `.bar/state.json`
71+
### `state.json`
7072

71-
全局状态文件,记录当前 active task。
73+
项目状态文件,记录当前 active task,位于 `~/.bar/projects/<project>-<hash4>/state.json`
7274

7375
```json
7476
{
@@ -385,7 +387,9 @@ Warning: deprecated API usage in utils.go
385387

386388
## Policy 文件
387389

388-
### `.bar/policy.yaml`
390+
### `policy.yaml`
391+
392+
Policy 文件位于项目根目录 `.bar/policy.yaml`(注意:这是项目内的配置,不在 `~/.bar` 中)。
389393

390394
```yaml
391395
version: 1

scripts/release.sh

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,57 @@ update_version() {
6868
sed -i '' "s/currentVersion = \".*\"/currentVersion = \"$version\"/" "$VERSION_FILE"
6969
}
7070

71+
generate_changelog_content() {
72+
local last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
73+
local range=""
74+
75+
if [ -n "$last_tag" ]; then
76+
range="$last_tag..HEAD"
77+
else
78+
range="HEAD"
79+
fi
80+
81+
local added="" changed="" fixed="" removed=""
82+
83+
while IFS= read -r line; do
84+
local type=$(echo "$line" | sed -n 's/^\([a-z]*\):.*/\1/p')
85+
local msg=$(echo "$line" | sed 's/^[a-z]*: //')
86+
87+
case "$type" in
88+
feat)
89+
added="$added\n- $msg"
90+
;;
91+
fix)
92+
fixed="$fixed\n- $msg"
93+
;;
94+
refactor|perf|style)
95+
changed="$changed\n- $msg"
96+
;;
97+
*)
98+
if [[ "$line" != chore:* && "$line" != docs:* && "$line" != test:* ]]; then
99+
changed="$changed\n- $line"
100+
fi
101+
;;
102+
esac
103+
done < <(git log --pretty=format:"%s" $range 2>/dev/null)
104+
105+
local content=""
106+
if [ -n "$added" ]; then
107+
content="$content\n### Added$added\n"
108+
fi
109+
if [ -n "$changed" ]; then
110+
content="$content\n### Changed$changed\n"
111+
fi
112+
if [ -n "$fixed" ]; then
113+
content="$content\n### Fixed$fixed\n"
114+
fi
115+
if [ -n "$removed" ]; then
116+
content="$content\n### Removed$removed\n"
117+
fi
118+
119+
echo -e "$content"
120+
}
121+
71122
update_changelog() {
72123
local version="$1"
73124
local date=$(date +%Y-%m-%d)
@@ -77,27 +128,43 @@ update_changelog() {
77128
return 0
78129
fi
79130

80-
echo "==> Updating CHANGELOG for $version"
131+
echo "==> Generating CHANGELOG for $version"
132+
133+
local changelog_content=$(generate_changelog_content)
134+
135+
if [ -z "$changelog_content" ] || [ "$changelog_content" = $'\n' ]; then
136+
echo "Warning: No commits found for changelog, using placeholder"
137+
changelog_content="\n### Changed\n- Version bump\n"
138+
fi
81139

82140
local temp_file=$(mktemp)
83-
local in_unreleased=0
84-
local unreleased_content=""
141+
local header_done=0
85142

86143
while IFS= read -r line; do
144+
echo "$line" >> "$temp_file"
87145
if [[ "$line" == "## [Unreleased]" ]]; then
88-
in_unreleased=1
89-
echo "$line" >> "$temp_file"
90146
echo "" >> "$temp_file"
91147
echo "## [$version] - $date" >> "$temp_file"
92-
elif [[ "$line" =~ ^##\ \[.*\] && "$in_unreleased" -eq 1 ]]; then
93-
in_unreleased=0
94-
echo "$line" >> "$temp_file"
95-
else
96-
echo "$line" >> "$temp_file"
148+
echo -e "$changelog_content" >> "$temp_file"
149+
header_done=1
97150
fi
98151
done < "$CHANGELOG_FILE"
99152

100-
mv "$temp_file" "$CHANGELOG_FILE"
153+
if [ "$header_done" -eq 0 ]; then
154+
echo "Warning: No [Unreleased] section found, prepending to file"
155+
local new_temp=$(mktemp)
156+
head -n 6 "$CHANGELOG_FILE" > "$new_temp"
157+
echo "" >> "$new_temp"
158+
echo "## [Unreleased]" >> "$new_temp"
159+
echo "" >> "$new_temp"
160+
echo "## [$version] - $date" >> "$new_temp"
161+
echo -e "$changelog_content" >> "$new_temp"
162+
tail -n +7 "$CHANGELOG_FILE" >> "$new_temp"
163+
mv "$new_temp" "$CHANGELOG_FILE"
164+
rm -f "$temp_file"
165+
else
166+
mv "$temp_file" "$CHANGELOG_FILE"
167+
fi
101168
}
102169

103170
prepare_release() {

0 commit comments

Comments
 (0)