docs: 重构命令和技能文档体系,规范化文档格式和内容组织
This commit is contained in:
@@ -1,184 +1,79 @@
|
||||
---
|
||||
description: List all configured Gitea runners and their status
|
||||
description: List all global runners on Gitea server
|
||||
---
|
||||
|
||||
# gitea-list-runners
|
||||
List all global runners registered on the Gitea server.
|
||||
|
||||
列出所有已配置的 Gitea Runners 及其运行状态。
|
||||
## 工作目录
|
||||
|
||||
## Features
|
||||
|
||||
- 显示所有已配置的 runner
|
||||
- 检查 runner 运行状态(运行中/已停止)
|
||||
- 显示 runner 配置信息(labels、capacity 等)
|
||||
- 显示 runner ID 和名称
|
||||
- 提供启动命令
|
||||
|
||||
## Steps
|
||||
|
||||
### 1. Check Configuration
|
||||
|
||||
```bash
|
||||
config_dir="$HOME/.config/gitea"
|
||||
runners_dir="$config_dir/runners"
|
||||
|
||||
if [ ! -d "$runners_dir" ]; then
|
||||
echo "❌ 未找到 runner 目录"
|
||||
echo "请先创建 runner"
|
||||
exit 1
|
||||
fi
|
||||
**macOS / Linux:**
|
||||
```
|
||||
~/.config/gitea/
|
||||
```
|
||||
|
||||
### 2. List All Runners
|
||||
|
||||
```bash
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "Gitea Runners"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
|
||||
runners=$(ls -1 "$runners_dir" 2>/dev/null)
|
||||
|
||||
if [ -z "$runners" ]; then
|
||||
echo "未配置任何 runner"
|
||||
echo ""
|
||||
echo "创建 runner:"
|
||||
echo " /gitea-create-runner"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
runner_count=$(echo "$runners" | wc -l | tr -d ' ')
|
||||
echo "总计: $runner_count 个 runner"
|
||||
echo ""
|
||||
**Windows:**
|
||||
```
|
||||
%USERPROFILE%\.config\gitea\
|
||||
```
|
||||
|
||||
### 3. Display Each Runner's Status
|
||||
Please perform the following:
|
||||
|
||||
1. **Read Gitea configuration:**
|
||||
- Read from config file:
|
||||
- macOS/Linux: `~/.config/gitea/config.env`
|
||||
- Windows: `%USERPROFILE%\.config\gitea\config.env`
|
||||
- Extract:
|
||||
- `GITEA_URL`: Gitea server URL
|
||||
- `GITEA_TOKEN`: API token (admin permission required)
|
||||
- If config not found: prompt user to run `/gitea-reset` first
|
||||
|
||||
2. **Call Gitea API to list runners:**
|
||||
```bash
|
||||
for runner in $runners; do
|
||||
runner_dir="$runners_dir/$runner"
|
||||
config_file="$runner_dir/config.yaml"
|
||||
|
||||
echo "[$runner]"
|
||||
|
||||
# Check if config exists
|
||||
if [ ! -f "$config_file" ]; then
|
||||
echo " ⚠️ 配置文件缺失"
|
||||
echo ""
|
||||
continue
|
||||
fi
|
||||
|
||||
# Check if runner process is running
|
||||
if pgrep -f "act_runner daemon --config $config_file" > /dev/null; then
|
||||
status="🟢 运行中"
|
||||
pid=$(pgrep -f "act_runner daemon --config $config_file")
|
||||
else
|
||||
status="🔴 已停止"
|
||||
pid="-"
|
||||
fi
|
||||
|
||||
echo " 状态: $status"
|
||||
echo " PID: $pid"
|
||||
|
||||
# Display configuration info
|
||||
if command -v yq &> /dev/null; then
|
||||
# Use yq if available
|
||||
capacity=$(yq eval '.runner.capacity' "$config_file" 2>/dev/null)
|
||||
timeout=$(yq eval '.runner.timeout' "$config_file" 2>/dev/null)
|
||||
else
|
||||
# Fallback to grep
|
||||
capacity=$(grep "capacity:" "$config_file" | awk '{print $2}')
|
||||
timeout=$(grep "timeout:" "$config_file" | awk '{print $2}')
|
||||
fi
|
||||
|
||||
echo " 容量: ${capacity:-N/A}"
|
||||
echo " 超时: ${timeout:-N/A}"
|
||||
|
||||
# Display labels
|
||||
labels=$(grep -A 10 "labels:" "$config_file" | grep "^ -" | sed 's/^ - "//' | sed 's/"$//' | tr '\n' ',' | sed 's/,$//')
|
||||
if [ -n "$labels" ]; then
|
||||
echo " Labels: $labels"
|
||||
fi
|
||||
|
||||
# Display runner info from .runner file
|
||||
if [ -f "$runner_dir/.runner" ]; then
|
||||
if command -v jq &> /dev/null; then
|
||||
runner_id=$(jq -r '.id // "N/A"' "$runner_dir/.runner" 2>/dev/null)
|
||||
runner_name=$(jq -r '.name // "N/A"' "$runner_dir/.runner" 2>/dev/null)
|
||||
|
||||
echo " ID: $runner_id"
|
||||
echo " 名称: $runner_name"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo " 路径: $runner_dir"
|
||||
|
||||
# Display start command
|
||||
echo ""
|
||||
echo " 启动命令:"
|
||||
echo " act_runner daemon --config $config_file"
|
||||
|
||||
# Display background start command
|
||||
if [ "$status" = "🔴 已停止" ]; then
|
||||
echo ""
|
||||
echo " 后台启动:"
|
||||
echo " nohup act_runner daemon --config $config_file > $runner_dir/runner.log 2>&1 &"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
done
|
||||
curl -s -H "Authorization: token <token>" \
|
||||
"<server>/api/v1/admin/actions/runners"
|
||||
```
|
||||
|
||||
### 4. Display Summary Commands
|
||||
3. **Parse JSON response and extract information:**
|
||||
- Response structure:
|
||||
```json
|
||||
{
|
||||
"runners": [...],
|
||||
"total_count": 1
|
||||
}
|
||||
```
|
||||
- Use `jq` to parse JSON
|
||||
- For each runner in `runners` array:
|
||||
- `id`: Runner ID
|
||||
- `name`: Runner name
|
||||
- `status`: Runner status ("online"/"offline")
|
||||
- `busy`: Whether runner is currently busy (true/false)
|
||||
- `ephemeral`: Whether runner is ephemeral (true/false)
|
||||
- `labels`: Array of label objects with `name` and `type`
|
||||
|
||||
```bash
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "管理命令"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
echo " 查看配置: /gitea-config"
|
||||
echo " 创建 runner: /gitea-create-runner"
|
||||
echo " 删除 runner: /gitea-delete-runner"
|
||||
echo ""
|
||||
```
|
||||
4. **Determine runner status:**
|
||||
- 🟢 在线 - `status: "online"`
|
||||
- 🔴 离线 - `status: "offline"`
|
||||
- ⚠️ 未知 - Unable to determine
|
||||
|
||||
## Output Example
|
||||
5. **Filter global runners:**
|
||||
- The API endpoint `/api/v1/admin/actions/runners` returns all global runners
|
||||
- These are runners registered at the instance level (not org or repo specific)
|
||||
|
||||
6. **Display summary in Chinese:**
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Gitea Runners
|
||||
Gitea 全局 Runners
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
总计: 2 个 runner
|
||||
服务器: [server_url]
|
||||
总计: N 个全局 runner
|
||||
|
||||
[runner-macbook-pro]
|
||||
状态: 🟢 运行中
|
||||
PID: 12345
|
||||
容量: 2
|
||||
超时: 3h
|
||||
Labels: self-hosted:host,macOS:host,ARM64:host,darwin-arm64:host
|
||||
ID: 42
|
||||
名称: runner-macbook-pro
|
||||
路径: /Users/voson/.config/gitea/runners/runner-macbook-pro
|
||||
|
||||
启动命令:
|
||||
act_runner daemon --config /Users/voson/.config/gitea/runners/runner-macbook-pro/config.yaml
|
||||
|
||||
[runner-mac-mini]
|
||||
状态: 🔴 已停止
|
||||
PID: -
|
||||
容量: 2
|
||||
超时: 3h
|
||||
Labels: self-hosted:host,macOS:host,ARM64:host,darwin-arm64:host
|
||||
ID: 43
|
||||
名称: runner-mac-mini
|
||||
路径: /Users/voson/.config/gitea/runners/runner-mac-mini
|
||||
|
||||
启动命令:
|
||||
act_runner daemon --config /Users/voson/.config/gitea/runners/runner-mac-mini/config.yaml
|
||||
|
||||
后台启动:
|
||||
nohup act_runner daemon --config /Users/voson/.config/gitea/runners/runner-mac-mini/config.yaml > /Users/voson/.config/gitea/runners/runner-mac-mini/runner.log 2>&1 &
|
||||
[runner-name]
|
||||
状态: 🟢/🔴 [在线/离线]
|
||||
ID: [id]
|
||||
忙碌: 是/否
|
||||
临时: 是/否
|
||||
标签: [comma-separated labels]
|
||||
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
管理命令
|
||||
@@ -189,14 +84,11 @@ Gitea Runners
|
||||
删除 runner: /gitea-delete-runner
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- 使用 `pgrep` 检查进程状态
|
||||
- 优先使用 `yq` 解析 YAML,fallback 到 `grep`
|
||||
- 优先使用 `jq` 解析 JSON `.runner` 文件
|
||||
- Runner 状态图标:
|
||||
- 🟢 运行中
|
||||
- 🔴 已停止
|
||||
- ⚠️ 配置异常
|
||||
- 显示启动命令方便用户复制执行
|
||||
- 对已停止的 runner,额外显示后台启动命令
|
||||
**Notes:**
|
||||
- Requires admin API token to list runners
|
||||
- **Correct API endpoint**: `/api/v1/admin/actions/runners` (not `/api/v1/admin/runners`)
|
||||
- Only shows global runners (instance-level runners)
|
||||
- Uses `jq` for JSON parsing
|
||||
- Response includes: `id`, `name`, `status`, `busy`, `ephemeral`, `labels`
|
||||
- If API call fails, show error message and suggest checking token permissions
|
||||
- Tested with Gitea version 1.25.3
|
||||
|
||||
Reference in New Issue
Block a user