Updated test workflow to fix CentOS 7 EOL repository issues and install necessary dependencies.
102 lines
3.9 KiB
YAML
102 lines
3.9 KiB
YAML
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 '
|
|
|
|
# ============================================
|
|
# 1. 针对 CentOS 7 的“强效起死回生”补丁
|
|
# ============================================
|
|
if [ -f /etc/redhat-release ] && grep -q "CentOS Linux 7" /etc/redhat-release; then
|
|
echo "💀 Detected CentOS 7 (EOL). Fixing repositories to Vault..."
|
|
|
|
# 1. 注释掉失效的 mirrorlist
|
|
sed -i "s/^mirrorlist/#mirrorlist/g" /etc/yum.repos.d/CentOS-*.repo
|
|
|
|
# 2. 启用 baseurl 并指向 vault.centos.org (处理带#和不带#的情况)
|
|
sed -i "s|^#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*.repo
|
|
sed -i "s|^baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*.repo
|
|
|
|
# 3. 清理缓存,防止残留
|
|
yum clean all
|
|
rm -rf /var/cache/yum
|
|
fi
|
|
|
|
# ============================================
|
|
# 2. 环境补全 (安装 sudo, sshd, 生成 key)
|
|
# ============================================
|
|
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
|
|
'
|