Agile and Trunk-based Development
===
---
* Overview Trunk-based Development
* Pair Programming
* Continuous Integration
* Feature Toggle
* Agile
---
## Trunk-based Development
* commit into "main" branch
* only release branch
參考:[TBD 是什麼](https://nedwu13.blogspot.com/2014/01/tbd-what-is-trunk-based-development.html)
---
Git Flow
```mermaid
%%{init: { 'theme': 'neutral' } }%%
gitGraph
commit
branch feat/WRS-29
commit
commit
checkout main
branch feat/WRS-31
commit
commit
commit
checkout main
merge feat/WRS-29
branch release/1.0
commit tag: "1.0.0"
commit
branch hotfix/WRS-33
commit
checkout release/1.0
merge hotfix/WRS-33 tag: "1.0.1"
checkout main
merge release/1.0
merge feat/WRS-31
```
---
Trunk-based
```mermaid
%%{init: { 'theme': 'neutral' } }%%
gitGraph
commit
commit
commit tag:"1.0.0"
branch release/1.0
checkout main
commit
commit id: "hotfix/1.0.1" type: REVERSE
checkout release/1.0
cherry-pick id: "hotfix/1.0.1"
checkout main
commit
commit tag: "2.0.0"
branch release/2.0
checkout main
commit
commit
commit id: "hotfix/2.0.1" type: REVERSE
checkout release/2.0
cherry-pick id: "hotfix/2.0.1"
checkout main
commit
commit
```
---
```bash=
git pull origin main --rebase
# Resolve Conflict
git push origin main
```
---
## Code Review
Trunk-based Development 沒有 Pull Request 該怎麼做 Code Review?
---
Q: Pull Request 目的?
---
Q: 誰有 Commit 的權限?
---
Q: Pair Programming 的好處?
---
## Continuous Integration
持續整合在 Trunk-based Development 扮演的角色
---
```mermaid
%%{init: { 'theme': 'neutral' } }%%
gitGraph
commit
commit
commit id: "BUG" type: REVERSE
commit
commit
```
---
```mermaid
%%{init: { 'theme': 'neutral' } }%%
gitGraph
commit
commit
commit id: "BUG" type: REVERSE
commit id: "FIX" type: HIGHLIGHT
commit
```
---
Q: 什麼時候 Conflict 的處理會變複雜?
---
Q: 如何加快 Bug 修正的速度?
---
## 安燈機制
https://zh.wikipedia.org/zh-tw/%E5%AE%89%E7%81%AF%E7%B3%BB%E7%BB%9F
---
## Feature Toggle
跟 Trunk-based Developer 搭配對未釋出功能的保護
---
```mermaid
%%{init: { 'theme': 'neutral' } }%%
gitGraph
commit
commit
commit id: "Feature-1"
commit
commit tag: "1.0.0"
commit id: "Feature-2" type: HIGHLIGHT
commit
commit id: "BUG" type: REVERSE
commit id: "FIX"
commit tag: "1.0.1"
commit
commit
```
未釋出的 `Feature-2` 因為 Bugfix 被部署
---
Q: 我們需要幾個 Feature Toggle 改善這件事情?
---
A: 1 個
```go=
if (os.Getenv("UNRELEASE_ENABLED") == "yes") {
// 新功能
} else {
// 舊功能
}
```
---
變體
```go=
// type Release struct { ... }
if (release.Phase("sandbox")) {
// sandbox 之前的 alpha / beta / dev 都會啟用
} else {
// production 維持舊版
}
```
---
這是利用 Feature Toggle 機制來實現未釋出功能控制的技巧,實務上可能有更多的 Feature Flag 對不同客戶做控管等等
---
## Trunk-based Developer 對敏捷開發的意義
---
Q: 大家對敏捷是怎麼理解的?
---
交付價值(Delivery Value)
---
* 解決問題
* 可以使用
---
```mermaid
%%{init: { 'theme': 'neutral' } }%%
gitGraph
commit id: "CI-Ready"
commit id: "CD-Ready"
commit id: "Mock API"
commit id: "controller json renderer"
commit id: "model schema"
commit id: "database migration"
commit
commit
```
追求 Done 而不是 Finished
如:Mock API 可以直接靠 Swagger 文件生成
---
Trunk-based Development 在這方面的好處是讓功能在「可用」的階段就能被使用到,就能持續提供價值
---
Trunk-based Development 更適合產品開發
* 快速迭代
* 持續整合
* 持續交付
{"metaMigratedAt":"2023-06-18T03:05:40.428Z","metaMigratedFrom":"YAML","title":"Agile and Trunk-based Development","breaks":true,"contributors":"[{\"id\":\"f37d49bd-d692-405a-b768-5e0a6d63c524\",\"add\":3463,\"del\":121}]"}