feat(gitea): 增强 runner 标签,添加设备配置和 IP 信息

- Host 模式默认添加 ubuntu-latest 标签,兼容 GitHub Actions workflow
- 自动检测并添加设备配置标签(如 4c3g 表示 4核3G内存)
- 自动检测并添加 IP 地址标签(如 ip-172-20-0-81)
- 支持 Linux 和 macOS 的配置检测
- 添加标签说明文档,帮助用户在 workflow 中使用配置标签
- 完整标签示例:ubuntu-latest, ubuntu, self-hosted, x64, linux-x86_64, 4c3g, ip-172-20-0-81
This commit is contained in:
voson
2026-01-30 10:56:15 +08:00
parent 3cb55db864
commit bb93a6bc6c

View File

@@ -16,6 +16,49 @@ agent: general
原因Gitea Actions 的缓存服务运行在 runner 本地job 容器需要通过网络访问 runner 的缓存端口。只有在 host 网络模式下job 容器才能访问到 runner 的缓存服务。
## 📋 Runner 标签说明
### Host 模式标签
Runner 会自动检测系统配置并生成以下标签:
**标准标签**
- `ubuntu-latest:host` - 兼容 GitHub Actions仅 Linux
- `ubuntu:host` / `macOS:host` - 操作系统
- `self-hosted:host` - 自托管标识
- `x64:host` / `ARM64:host` - CPU 架构
- `linux-x86_64:host` / `darwin-arm64:host` - 系统-架构组合
**设备配置标签**(自动检测):
- `4c8g:host` - CPU核心数 + 内存大小(如 4核8G
- `ip-172-20-0-81:host` - 服务器 IP 地址
**示例**
```
ubuntu-latest:host, ubuntu:host, self-hosted:host, x64:host,
linux-x86_64:host, 4c8g:host, ip-172-20-0-81:host
```
**在 Workflow 中使用**
```yaml
# 使用标准标签
runs-on: ubuntu-latest
# 使用配置标签筛选特定配置的 runner
runs-on: [self-hosted, 4c8g]
# 使用 IP 标签指定特定服务器
runs-on: [self-hosted, ip-172-20-0-81]
```
### Docker 模式标签
Docker 模式使用预定义的镜像映射:
- `ubuntu-latest:docker://catthehacker/ubuntu:act-latest`
- `ubuntu-22.04:docker://catthehacker/ubuntu:act-22.04`
- `ubuntu-20.04:docker://catthehacker/ubuntu:act-20.04`
- `linux:docker://catthehacker/ubuntu:act-latest`
## 📦 快速使用
### 方法一:直接执行(推荐)
@@ -635,8 +678,30 @@ create_runner() {
*) arch_label="unknown" ;;
esac
# 检测设备配置
cpu_cores=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo "unknown")
mem_gb=$(free -g 2>/dev/null | awk '/^Mem:/{print $2}' || sysctl -n hw.memsize 2>/dev/null | awk '{print int($1/1024/1024/1024)}' || echo "unknown")
ip_addr=$(hostname -I 2>/dev/null | awk '{print $1}' || ipconfig getifaddr en0 2>/dev/null || echo "unknown")
ip_label=$(echo "$ip_addr" | tr '.' '-')
combined=$(echo "${OS}-${ARCH}" | tr '[:upper:]' '[:lower:]')
labels="self-hosted:host,${os_label}:host,${arch_label}:host,${combined}:host"
# 添加 ubuntu-latest 以兼容 GitHub Actions workflow
if [ "$os_label" = "ubuntu" ]; then
labels="ubuntu-latest:host,ubuntu:host,self-hosted:host,${arch_label}:host,${combined}:host"
else
labels="self-hosted:host,${os_label}:host,${arch_label}:host,${combined}:host"
fi
# 添加设备配置标签
if [ "$cpu_cores" != "unknown" ] && [ "$mem_gb" != "unknown" ]; then
labels="${labels},${cpu_cores}c${mem_gb}g:host"
fi
# 添加 IP 标签
if [ "$ip_addr" != "unknown" ]; then
labels="${labels},ip-${ip_label}:host"
fi
else
# Docker mode uses standard labels mapping to images