refactor(gitea): 优化 runner 标签系统
**标签简化**: - 移除所有标签的 :host 后缀重复,统一添加单个 host 标签 - 删除私网 IP 标签(不适用于实际场景) **发行版检测增强**: - 自动检测 Linux 发行版(debian, ubuntu, centos 等) - 添加发行版版本标签(如 debian-12, ubuntu-22) - 保留 ubuntu-latest 作为兼容标签,适用于所有 Linux 系统 **新的标签结构**: - 基础标签:host, ubuntu-latest, self-hosted, x64, linux-x86_64 - 发行版标签:debian, debian-12, linux(实际系统信息) - 配置标签:4c3g(保留,用于资源调度) **标签示例(Debian 12)**: host, ubuntu-latest, self-hosted, x64, linux-x86_64, debian, debian-12, linux, 4c3g **优势**: - 更简洁的标签结构 - 精确的系统信息(实际发行版) - 保持 GitHub Actions 兼容性(ubuntu-latest) - 支持多种匹配策略(兼容模式、精确模式、配置筛选)
This commit is contained in:
@@ -22,33 +22,62 @@ agent: general
|
|||||||
|
|
||||||
Runner 会自动检测系统配置并生成以下标签:
|
Runner 会自动检测系统配置并生成以下标签:
|
||||||
|
|
||||||
**标准标签**:
|
**基础标签**:
|
||||||
- `ubuntu-latest:host` - 兼容 GitHub Actions(仅 Linux)
|
- `host` - 运行模式标识
|
||||||
- `ubuntu:host` / `macOS:host` - 操作系统
|
- `self-hosted` - 自托管标识
|
||||||
- `self-hosted:host` - 自托管标识
|
- `ubuntu-latest` - GitHub Actions 兼容标签(所有 Linux 系统)
|
||||||
- `x64:host` / `ARM64:host` - CPU 架构
|
- `x64` / `ARM64` - CPU 架构
|
||||||
- `linux-x86_64:host` / `darwin-arm64:host` - 系统-架构组合
|
- `linux-x86_64` / `darwin-arm64` - 系统-架构组合
|
||||||
|
|
||||||
|
**发行版标签**(自动检测):
|
||||||
|
- `debian` - Debian 系统
|
||||||
|
- `debian-12` - Debian 12 版本
|
||||||
|
- `ubuntu` - Ubuntu 系统
|
||||||
|
- `ubuntu-22` - Ubuntu 22.04 版本
|
||||||
|
- `centos` - CentOS 系统
|
||||||
|
- `macOS` - macOS 系统
|
||||||
|
- `linux` - 通用 Linux 标签
|
||||||
|
|
||||||
**设备配置标签**(自动检测):
|
**设备配置标签**(自动检测):
|
||||||
- `4c8g:host` - CPU核心数 + 内存大小(如 4核8G)
|
- `4c8g` - CPU 核心数 + 内存大小(如 4核8G内存)
|
||||||
- `ip-172-20-0-81:host` - 服务器 IP 地址
|
|
||||||
|
|
||||||
**示例**:
|
**标签示例(Debian 12 系统)**:
|
||||||
```
|
```
|
||||||
ubuntu-latest:host, ubuntu:host, self-hosted:host, x64:host,
|
host, ubuntu-latest, self-hosted, x64, linux-x86_64,
|
||||||
linux-x86_64:host, 4c8g:host, ip-172-20-0-81:host
|
debian, debian-12, linux, 4c3g
|
||||||
|
```
|
||||||
|
|
||||||
|
**标签示例(Ubuntu 22.04 系统)**:
|
||||||
|
```
|
||||||
|
host, ubuntu-latest, self-hosted, x64, linux-x86_64,
|
||||||
|
ubuntu, ubuntu-22, linux, 8c16g
|
||||||
|
```
|
||||||
|
|
||||||
|
**标签示例(macOS ARM64 系统)**:
|
||||||
|
```
|
||||||
|
host, ubuntu-latest, self-hosted, ARM64, darwin-arm64,
|
||||||
|
macOS, 8c16g
|
||||||
```
|
```
|
||||||
|
|
||||||
**在 Workflow 中使用**:
|
**在 Workflow 中使用**:
|
||||||
```yaml
|
```yaml
|
||||||
# 使用标准标签
|
# 兼容模式 - 匹配所有 Linux Host Runner
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
# 使用配置标签筛选特定配置的 runner
|
# 精确匹配 - 只在 Debian 系统上运行
|
||||||
runs-on: [self-hosted, 4c8g]
|
runs-on: [self-hosted, debian]
|
||||||
|
|
||||||
# 使用 IP 标签指定特定服务器
|
# 更精确 - 指定 Debian 版本
|
||||||
runs-on: [self-hosted, ip-172-20-0-81]
|
runs-on: [self-hosted, debian-12]
|
||||||
|
|
||||||
|
# 根据配置筛选 - 需要 8核16G 的 runner
|
||||||
|
runs-on: [self-hosted, 8c16g]
|
||||||
|
|
||||||
|
# 组合条件 - Debian 系统且 8核16G
|
||||||
|
runs-on: [debian, 8c16g]
|
||||||
|
|
||||||
|
# macOS 环境
|
||||||
|
runs-on: [self-hosted, macOS]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Docker 模式标签
|
### Docker 模式标签
|
||||||
@@ -59,6 +88,12 @@ Docker 模式使用预定义的镜像映射:
|
|||||||
- `ubuntu-20.04:docker://catthehacker/ubuntu:act-20.04`
|
- `ubuntu-20.04:docker://catthehacker/ubuntu:act-20.04`
|
||||||
- `linux:docker://catthehacker/ubuntu:act-latest`
|
- `linux:docker://catthehacker/ubuntu:act-latest`
|
||||||
|
|
||||||
|
**标签设计说明**:
|
||||||
|
1. **`ubuntu-latest` 是兼容标签**:所有 Linux Host Runner 都包含此标签,方便兼容 GitHub Actions workflow
|
||||||
|
2. **实际发行版标签提供精确控制**:如 `debian`、`ubuntu` 等,用于需要特定系统的场景
|
||||||
|
3. **`host` 标签**:用于区分 Host 模式和 Docker 模式的 runner
|
||||||
|
4. **配置标签**:如 `4c8g`,方便根据资源需求调度任务
|
||||||
|
|
||||||
## 📦 快速使用
|
## 📦 快速使用
|
||||||
|
|
||||||
### 方法一:直接执行(推荐)
|
### 方法一:直接执行(推荐)
|
||||||
@@ -665,42 +700,65 @@ create_runner() {
|
|||||||
|
|
||||||
if [ "$mode" = "host" ]; then
|
if [ "$mode" = "host" ]; then
|
||||||
OS=$(uname -s)
|
OS=$(uname -s)
|
||||||
case "$OS" in
|
|
||||||
Darwin) os_label="macOS" ;;
|
|
||||||
Linux) os_label="ubuntu" ;;
|
|
||||||
*) os_label="unknown" ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
ARCH=$(uname -m)
|
ARCH=$(uname -m)
|
||||||
|
|
||||||
|
# 检测架构
|
||||||
case "$ARCH" in
|
case "$ARCH" in
|
||||||
arm64|aarch64) arch_label="ARM64" ;;
|
arm64|aarch64) arch_label="ARM64" ;;
|
||||||
x86_64) arch_label="x64" ;;
|
x86_64) arch_label="x64" ;;
|
||||||
*) arch_label="unknown" ;;
|
*) arch_label="unknown" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# 检测操作系统和发行版
|
||||||
|
if [ "$OS" = "Darwin" ]; then
|
||||||
|
os_label="macOS"
|
||||||
|
distro_label=""
|
||||||
|
distro_version_label=""
|
||||||
|
elif [ "$OS" = "Linux" ]; then
|
||||||
|
# 检测 Linux 发行版
|
||||||
|
if [ -f /etc/os-release ]; then
|
||||||
|
. /etc/os-release
|
||||||
|
distro_label="$ID" # debian, ubuntu, centos, etc.
|
||||||
|
distro_version_label="${ID}-${VERSION_ID%%.*}" # debian-12, ubuntu-22, etc.
|
||||||
|
else
|
||||||
|
distro_label="linux"
|
||||||
|
distro_version_label=""
|
||||||
|
fi
|
||||||
|
os_label="$distro_label"
|
||||||
|
else
|
||||||
|
os_label="unknown"
|
||||||
|
distro_label=""
|
||||||
|
distro_version_label=""
|
||||||
|
fi
|
||||||
|
|
||||||
# 检测设备配置
|
# 检测设备配置
|
||||||
cpu_cores=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo "unknown")
|
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")
|
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:]')
|
combined=$(echo "${OS}-${ARCH}" | tr '[:upper:]' '[:lower:]')
|
||||||
|
|
||||||
|
# 构建标签(移除 :host 后缀,统一添加 host 模式标签)
|
||||||
# 添加 ubuntu-latest 以兼容 GitHub Actions workflow
|
# 添加 ubuntu-latest 以兼容 GitHub Actions workflow
|
||||||
if [ "$os_label" = "ubuntu" ]; then
|
labels="host,ubuntu-latest,self-hosted,${arch_label},${combined}"
|
||||||
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"
|
if [ -n "$distro_label" ] && [ "$distro_label" != "linux" ]; then
|
||||||
|
labels="${labels},${distro_label}"
|
||||||
|
if [ -n "$distro_version_label" ]; then
|
||||||
|
labels="${labels},${distro_version_label}"
|
||||||
|
fi
|
||||||
|
elif [ "$os_label" != "unknown" ]; then
|
||||||
|
labels="${labels},${os_label}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 添加通用 linux 标签(用于区分 macOS)
|
||||||
|
if [ "$OS" = "Linux" ]; then
|
||||||
|
labels="${labels},linux"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 添加设备配置标签
|
# 添加设备配置标签
|
||||||
if [ "$cpu_cores" != "unknown" ] && [ "$mem_gb" != "unknown" ]; then
|
if [ "$cpu_cores" != "unknown" ] && [ "$mem_gb" != "unknown" ]; then
|
||||||
labels="${labels},${cpu_cores}c${mem_gb}g:host"
|
labels="${labels},${cpu_cores}c${mem_gb}g"
|
||||||
fi
|
|
||||||
|
|
||||||
# 添加 IP 标签
|
|
||||||
if [ "$ip_addr" != "unknown" ]; then
|
|
||||||
labels="${labels},ip-${ip_label}:host"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user