Enhance test workflow for better OS compatibility

Updated the test workflow to improve compatibility with CentOS and other distributions. Added comments for clarity and fixed the initialization process for various environments.
This commit is contained in:
247LIKE authored and GitHub committed 2025-12-16 10:03:58 +08:00
1 parent 9da662f8d6
commit 51fb3bd675
1 file changed
+53 -22
+53 -22
View File
@@ -13,46 +13,77 @@ jobs:
- 'debian:12'
- 'ubuntu:22.04'
- 'alpine:latest'
- 'almalinux:9' # 推荐:CentOS 9 的完美替代
- 'rockylinux:9' # 推荐:CentOS 9 的完美替代
- 'centos:7' # 官方 CentOS 7 (需修复源)
- 'quay.io/centos/centos:stream9' # 官方 CentOS Stream 9 (原生可用)
- 'almalinux:9'
- 'rockylinux:9'
- 'centos:7'
- 'quay.io/centos/centos:stream9'
container:
image: ${{ matrix.container }}
options: --privileged
options: --privileged # 必须开启特权模式
steps:
- name: Checkout code
uses: actions/checkout@v3
# === 关键:针对旧版 CentOS 的“起死回生”补丁 ===
- name: Fix CentOS EOL Repos
# 1. 修复 CentOS 7 EOL 源问题
- name: Fix CentOS 7 EOL Repos
run: |
# 如果是 CentOS 8 (已死),需要切到 vault 源
if grep -q "CentOS Linux 8" /etc/os-release 2>/dev/null; then
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
fi
# 如果是 CentOS 7 (已死),同样需要切到 vault 源
if grep -q "CentOS Linux 7" /etc/os-release 2>/dev/null; then
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Base.repo
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Base.repo
fi
- name: Pre-install basic requirements
# 2. 安装依赖并初始化运行环境 (这是修复核心)
- name: Initialize Environment (Fix Docker Quirks)
run: |
if [ -f /etc/alpine-release ]; then
apk add --no-cache curl sudo openssh-server
elif [ -f /etc/debian_version ]; then
apt-get update && apt-get install -y curl sudo openssh-server
elif [ -f /etc/redhat-release ]; then
# CentOS/Alma/Rocky 都在这里
dnf install -y curl sudo openssh-server || yum install -y curl sudo openssh-server
echo "Initializing environment for $(cat /etc/os-release | grep PRETTY_NAME)"
# --- Debian / Ubuntu ---
if [ -f /etc/debian_version ]; then
apt-get update
apt-get install -y curl sudo openssh-server
# [关键修复] 生成 Host Keys,否则 sshd -t 会报错
ssh-keygen -A
# [关键修复] 创建运行目录
mkdir -p /run/sshd
fi
# --- Alpine ---
if [ -f /etc/alpine-release ]; then
apk add --no-cache curl sudo openssh-server bash
# [关键修复] 生成 Host Keys
ssh-keygen -A
fi
# --- RHEL / CentOS / Alma / Rocky ---
if [ -f /etc/redhat-release ]; then
# [关键修复] AlmaLinux 9 解决 curl-minimal 冲突
if command -v dnf >/dev/null; then
dnf install -y --allowerasing curl sudo openssh-server
else
yum install -y curl sudo openssh-server
fi
# [关键修复] 生成 Host Keys 和目录
ssh-keygen -A
mkdir -p /run/sshd
fi
# 3. 运行测试脚本
- name: Run Init Script
run: |
chmod +x init.sh
# 使用 --strict 严格模式测试,遇到错误立即退出
./init.sh --user=root --port=2222 --key-raw="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPQQDejyTCPJO3Jyw5UX9jmojb/zjgcqVuRO28fmpWU5" --no-update --bbr --delay-restart --yes --strict
# 4. 验证结果 (可选)
- name: Verify Configuration
run: |
if grep -q "BEGIN SERVER-INIT MANAGED BLOCK" /etc/ssh/sshd_config; then
echo "✅ SUCCESS: Config block injected."
else
echo "❌ FAIL: Config block missing."
exit 1
fi