name: Test Matrix on: [push, pull_request] jobs: test-distros: # 关键点 1: 在 Ubuntu 宿主机上运行 Job,而不是直接在容器里跑 runs-on: ubuntu-latest strategy: fail-fast: false matrix: container: - 'debian:11' - 'debian:12' - 'ubuntu:22.04' - 'alpine:latest' - 'almalinux:9' - 'rockylinux:9' - 'centos:7' # 这里的 CentOS 7 现在可以跑了! - 'quay.io/centos/centos:stream9' steps: - name: Checkout code uses: actions/checkout@v4 - name: Run Test in Container run: | echo "🚀 Testing on image: ${{ matrix.container }}" chmod +x init.sh # 启动容器 docker run --rm --privileged -v $(pwd):/mnt -w /mnt ${{ matrix.container }} /bin/sh -c ' # 调试信息:打印当前系统版本 if [ -f /etc/redhat-release ]; then echo "📝 System detected: $(cat /etc/redhat-release)" fi # ============================================ # 1. 针对 CentOS 7 的“起死回生”补丁 (正则修正版) # ============================================ # [FIX] 改为匹配 "release 7",兼容 "CentOS Linux release 7.x.x" if [ -f /etc/redhat-release ] && grep -q "release 7" /etc/redhat-release; then echo "💀 Detected CentOS 7 (EOL). Fixing repositories to Vault..." # 暴力替换所有 repo 文件 (base, updates, extras 等) # 1. 注释掉失效的 mirrorlist sed -i "s/^mirrorlist/#mirrorlist/g" /etc/yum.repos.d/*.repo # 2. 启用 baseurl 并指向 vault sed -i "s|^#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/*.repo sed -i "s|^baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/*.repo # 3. 强制清理缓存 yum clean all rm -rf /var/cache/yum fi # ============================================ # 2. 环境补全 # ============================================ echo "📦 Installing dependencies..." # --- Debian / Ubuntu --- if [ -f /etc/debian_version ]; then apt-get update -y && apt-get install -y curl sudo openssh-server ssh-keygen -A mkdir -p /run/sshd fi # --- Alpine --- if [ -f /etc/alpine-release ]; then apk add --no-cache curl sudo openssh-server bash 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 # CentOS 7 会走这里,现在源修好了,安装应该没问题 yum install -y curl sudo openssh-server fi ssh-keygen -A mkdir -p /run/sshd fi # ============================================ # 3. 运行脚本 # ============================================ echo "🚀 Running init script..." ./init.sh --user=root --port=2222 --key-raw="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPQQDejyTCPJO3Jyw5UX9jmojb/zjgcqVuRO28fmpWU5" --no-update --bbr --delay-restart --yes --strict # ============================================ # 4. 验证结果 # ============================================ 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 '