Files
linux-ssh-init-sh/.github/workflows/test.yml
T
247LIKE eab93f3e08 Fix CentOS 7 EOL and improve workflow steps
Updated the GitHub Actions workflow to fix CentOS 7 EOL repository issues and improve container initialization steps.
2025-12-16 10:08:18 +08:00

90 lines
3.3 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:
# 关键点 2: 在宿主机上检出代码 (Ubuntu 支持 Node20,没问题)
- name: Checkout code
uses: actions/checkout@v4
# 关键点 3: 使用 docker run 手动启动容器并挂载代码
- name: Run Test in Container
run: |
# 打印当前测试的镜像
echo "🚀 Testing on image: ${{ matrix.container }}"
# 赋予脚本执行权限
chmod +x init.sh
# 启动 Docker 容器运行测试逻辑
# --rm: 跑完删除
# --privileged: 允许修改系统参数
# -v $(pwd):/mnt: 把当前宿主机的代码挂载到容器的 /mnt 目录
docker run --rm --privileged -v $(pwd):/mnt -w /mnt ${{ matrix.container }} /bin/sh -c '
# === 第一步:修复 CentOS 7 EOL 源 (起死回生) ===
if [ -f /etc/redhat-release ] && grep -q "CentOS Linux 7" /etc/redhat-release; then
echo "Fixing CentOS 7 EOL repos..."
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
# === 第二步:环境补全 (安装 sudo, curl, 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
yum install -y curl sudo openssh-server
fi
ssh-keygen -A
mkdir -p /run/sshd
fi
# === 第三步:运行你的脚本 ===
echo "Running init script..."
./init.sh --user=root --port=2222 --key-raw="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPQQDejyTCPJO3Jyw5UX9jmojb/zjgcqVuRO28fmpWU5" --no-update --bbr --delay-restart --yes --strict
# === 第四步:验证结果 ===
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
'