Files
linux-ssh-init-sh/.github/workflows/test.yml
T
247LIKE 51fb3bd675 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.
2025-12-16 10:03:58 +08:00

90 lines
2.9 KiB
YAML

name: Test Matrix
on: [push, pull_request]
jobs:
test-distros:
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'
- 'quay.io/centos/centos:stream9'
container:
image: ${{ matrix.container }}
options: --privileged # 必须开启特权模式
steps:
- name: Checkout code
uses: actions/checkout@v3
# 1. 修复 CentOS 7 EOL 源问题
- name: Fix CentOS 7 EOL Repos
run: |
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
# 2. 安装依赖并初始化运行环境 (这是修复核心)
- name: Initialize Environment (Fix Docker Quirks)
run: |
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