Files
calculate-version-action/readme.md
Jeffery 516b5a59f9
All checks were successful
/ CD > 發布專案 (push) Successful in 4s
first commit
2025-09-18 14:32:23 +08:00

98 lines
2.6 KiB
Markdown
Raw Permalink 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.

# Calculate Version Action
這是一個自動計算語義化版本號的 GitHub Action支援自定義版本遞增規則。
## 功能特色
- 🔄 自動從 Gitea releases 獲取最新版本
- 📈 支援自定義版本遞增規則
- 🎯 可配置的版本號上限
- 🔧 完全可重用的 composite action
## 輸入參數
| 參數名稱 | 必要 | 預設值 | 描述 |
|---------|------|--------|------|
| `gitea-server` | ✅ | - | Gitea 伺服器 URL |
| `repository` | ✅ | - | 儲存庫名稱 (格式: owner/repo) |
| `token` | ✅ | - | Gitea API Token |
| `initial-version` | ❌ | `0.0.1` | 初始版本號 |
| `patch-limit` | ❌ | `10` | 小版號上限 (達到時進位中版號) |
| `minor-limit` | ❌ | `10` | 中版號上限 (達到時進位大版號) |
## 輸出參數
| 參數名稱 | 描述 |
|---------|------|
| `version` | 計算出的新版本號 |
| `previous-version` | 上一個版本號 |
## 使用範例
### 基本用法
```yaml
- name: 計算版本號
id: version
uses: ./.gitea/actions/calculate-version
with:
gitea-server: ${{ gitea.server_url }}
repository: ${{ gitea.repository }}
token: ${{ secrets.GITEA_TOKEN }}
```
### 自定義設定
```yaml
- name: 計算版本號
id: version
uses: ./.gitea/actions/calculate-version
with:
gitea-server: ${{ gitea.server_url }}
repository: ${{ gitea.repository }}
token: ${{ secrets.GITEA_TOKEN }}
initial-version: '1.0.0'
patch-limit: '5' # 小版號到 4 時進位
minor-limit: '5' # 中版號到 4 時進位
```
### 使用輸出
```yaml
- name: 顯示版本資訊
run: |
echo "上一版本: ${{ steps.version.outputs.previous-version }}"
echo "新版本: ${{ steps.version.outputs.version }}"
- name: 建立 Release
uses: akkuman/gitea-release-action@v1
with:
name: "My App v${{ steps.version.outputs.version }}"
tag_name: "v${{ steps.version.outputs.version }}"
```
## 版本遞增規則
1. **預設增加小版號 (patch)**:每次執行都會增加小版號
2. **小版號進位**:當小版號 ≥ `patch-limit` 時,重置為 0 並增加中版號
3. **中版號進位**:當中版號 ≥ `minor-limit` 時,重置為 0 並增加大版號
### 範例版本演進 (預設設定)
```
初始0.0.1
第2次0.0.2
...
第10次0.0.9
第11次0.1.0 ← 小版號重置,中版號進位
...
第101次0.9.9
第102次1.0.0 ← 中版號重置,大版號進位
```
## 注意事項
- Action 必須放在 `.gitea/actions/calculate-version/` 目錄下
- 需要有 `GITEA_TOKEN` secret 來存取 API
- 第一次執行時會從 `initial-version` 開始計算