2 Commits

Author SHA1 Message Date
dichgrem
130a2298f2 chore:actions 2026-01-18 15:51:42 +08:00
dichgrem
15e1df01f5 chore:actions 2026-01-18 15:41:16 +08:00
2 changed files with 225 additions and 144 deletions

View File

@@ -27,8 +27,8 @@ on:
- "snapshot"
- "stable"
config_path:
description: "配置文件路径(留空则跳过)"
required: false
description: "配置文件路径"
required: true
default: "config/x86_64_config"
type: string
proxy_passwall2:
@@ -56,15 +56,10 @@ on:
required: false
default: true
type: boolean
enable_bbr:
description: "启用 BBR 拥塞控制"
required: false
default: true
type: boolean
custom_shell:
description: "默认 shell"
required: false
default: "bash"
default: "ash"
type: choice
options:
- ash
@@ -78,6 +73,11 @@ on:
- argon
- bootstrap
- material
enable_bbr:
description: "启用 BBR 拥塞控制"
required: false
default: true
type: boolean
custom_hostname:
description: "自定义 hostname留空则跳过"
required: false
@@ -128,18 +128,15 @@ jobs:
fi
fi
# 验证配置文件是否存在(如果提供了路径)
if [ -n "${{ inputs.config_path }}" ]; then
if [ -f "${{ inputs.config_path }}" ]; then
echo "config_exists=true" >> "$GITHUB_OUTPUT"
echo "✅ 配置文件存在:${{ inputs.config_path }}"
else
echo "config_exists=false" >> "$GITHUB_OUTPUT"
echo "⚠️ 配置文件不存在:${{ inputs.config_path }},将跳过配置文件"
fi
# 验证配置文件是否存在
if [ -f "${{ inputs.config_path }}" ]; then
echo "config_exists=true" >> "$GITHUB_OUTPUT"
echo "✅ 配置文件存在:${{ inputs.config_path }}"
else
echo "config_exists=false" >> "$GITHUB_OUTPUT"
echo " 未提供配置文件路径,将使用默认配置"
echo "❌ 配置文件不存在:${{ inputs.config_path }}"
echo "is_valid=false" >> "$GITHUB_OUTPUT"
exit 1
fi
echo "is_valid=true" >> "$GITHUB_OUTPUT"
@@ -155,15 +152,69 @@ jobs:
- name: Checkout current repository
uses: actions/checkout@v4
- name: Free up disk space
run: |
echo "🧹 开始清理无用文件,释放磁盘空间"
sudo rm -rf /usr/share/dotnet \
/usr/local/lib/android \
/opt/ghc \
/opt/az \
/opt/microsoft \
/usr/local/share/boost \
/usr/share/swift \
/usr/local/lib/nodejs
sudo apt-get clean
sudo rm -rf /var/lib/apt/lists/*
echo "📊 磁盘使用情况:"
df -h || true
- name: Setup ccache
uses: hendrikmuhs/ccache-action@v1.2
if: inputs.cache_enabled == true
with:
key: ${{ runner.os }}-wrt-ccache-${{ inputs.project }}-${{ inputs.version_type }}
max-size: 2G
- name: Cache downloads
uses: actions/cache@v4
if: inputs.cache_enabled == true
with:
path: ${{ env.DL_DIR }}
key: ${{ runner.os }}-wrt-dl-${{ inputs.project }}-${{ inputs.version_type }}-${{ hashFiles('**/*.config') }}
restore-keys: |
${{ runner.os }}-wrt-dl-${{ inputs.project }}-${{ inputs.version_type }}-
${{ runner.os }}-wrt-dl-${{ inputs.project }}-
${{ runner.os }}-wrt-dl-
- name: Cache build directory
uses: actions/cache@v4
if: inputs.cache_enabled == true
with:
path: wrt/build_dir
key: ${{ runner.os }}-wrt-build-${{ inputs.project }}-${{ inputs.version_type }}-${{ hashFiles('**/*.config') }}
restore-keys: |
${{ runner.os }}-wrt-build-${{ inputs.project }}-${{ inputs.version_type }}-
${{ runner.os }}-wrt-build-${{ inputs.project }}-
${{ runner.os }}-wrt-build-
- name: Choose Wrt Version
id: refinfo
run: |
if [ "${{ inputs.version_type }}" = "snapshot" ]; then
echo "ref=master" >> "$GITHUB_OUTPUT"
else
echo "ref=${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
fi
- name: Install dependencies
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/{ghc,az,microsoft}
sudo apt-get update && sudo apt-get install -y \
sudo apt-get update
sudo apt-get install -y \
build-essential clang flex bison g++ gawk gettext git \
libncurses-dev libssl-dev python3{,-dev,-setuptools} \
libncurses-dev libssl-dev python3 python3-dev python3-setuptools \
rsync unzip zlib1g-dev file wget curl \
{gzip,tar,zip,xz-utils,bzip2,zstd} \
make cmake {autoconf,automake,libtool,patch,diffutils} \
gzip tar zip xz-utils bzip2 zstd \
make cmake autoconf automake libtool patch diffutils \
findutils grep sed help2man texinfo \
libelf-dev libfuse-dev liblzma-dev libxml2-dev libyaml-dev \
uuid-dev device-tree-compiler antlr3 gperf \
@@ -175,105 +226,134 @@ jobs:
id: projectinfo
run: |
case "${{ inputs.project }}" in
immortalwrt) echo "url=https://github.com/immortalwrt/immortalwrt.git" >> $GITHUB_OUTPUT ;;
immortalwrt-mt798x) echo "url=https://github.com/hanwckf/immortalwrt-mt798x.git" >> $GITHUB_OUTPUT ;;
immortalwrt-mt798x-6.6) echo "url=https://github.com/padavanonly/immortalwrt-mt798x-6.6.git" >> $GITHUB_OUTPUT ;;
openwrt) echo "url=https://git.openwrt.org/openwrt/openwrt.git" >> $GITHUB_OUTPUT ;;
*) echo "❌ 未知项目" >&2; exit 1 ;;
immortalwrt)
echo "url=https://github.com/immortalwrt/immortalwrt.git" >> $GITHUB_OUTPUT
;;
immortalwrt-mt798x)
echo "url=https://github.com/hanwckf/immortalwrt-mt798x.git" >> $GITHUB_OUTPUT
;;
immortalwrt-mt798x-6.6)
echo "url=https://github.com/padavanonly/immortalwrt-mt798x-6.6.git" >> $GITHUB_OUTPUT
;;
openwrt)
echo "url=https://git.openwrt.org/openwrt/openwrt.git" >> $GITHUB_OUTPUT
;;
*)
echo "❌ 未知项目: ${{ inputs.project }}" >&2
exit 1
;;
esac
- name: Clone Wrt source
run: |
echo "📥 克隆 ${{ inputs.project }} (${{ inputs.version_type }})"
[ "${{ inputs.version_type }}" = "snapshot" ] && BRANCH_MODE=1 || BRANCH_MODE=0
if [ $BRANCH_MODE -eq 1 ]; then
git clone --depth 1 "${{ steps.projectinfo.outputs.url }}" wrt
cd wrt
DEFAULT_BRANCH=$(git remote show origin | grep 'HEAD branch' | awk '{print $NF}')
[ -z "$DEFAULT_BRANCH" ] && for b in main master openwrt-24.10; do
git ls-remote --heads origin "$b" | grep -q "$b" && DEFAULT_BRANCH=$b && break
done
[ -z "$DEFAULT_BRANCH" ] && { echo "❌ 无法确定默认分支"; exit 1; }
git fetch origin "${DEFAULT_BRANCH}" 2>/dev/null
git switch "${DEFAULT_BRANCH}" 2>/dev/null || git checkout "${DEFAULT_BRANCH}"
else
git clone "${{ steps.projectinfo.outputs.url }}" wrt
cd wrt
git checkout "${{ inputs.tag }}" 2>/dev/null || \
(git fetch --tags && git checkout "${{ inputs.tag }}") || \
{ echo "❌ 标签不存在"; exit 1; }
fi
echo "🔖 $(git describe --tags --always 2>/dev/null || git rev-parse --short HEAD)"
echo "🌿 $(git branch --show-current 2>/dev/null || echo 'detached')"
- name: Setup ccache
uses: hendrikmuhs/ccache-action@v1.2
if: inputs.cache_enabled == true
with:
key: ${{ runner.os }}-wrt-ccache-${{ inputs.project }}-${{ inputs.version_type }}
max-size: 2G
update-package-index: true
- name: Cache downloads
uses: actions/cache@v4
if: inputs.cache_enabled == true
with:
path: wrt/dl
key: ${{ runner.os }}-wrt-dl-${{ inputs.project }}-${{ inputs.version_type }}
- name: Cache build directory
uses: actions/cache@v4
if: inputs.cache_enabled == true
with:
path: wrt/build_dir
key: ${{ runner.os }}-wrt-build-${{ inputs.project }}-${{ inputs.version_type }}
echo "📥 克隆 ${{ inputs.project }} 仓库"
git clone --depth 1 "${{ steps.projectinfo.outputs.url }}" -b "${{ steps.refinfo.outputs.ref }}" wrt || \
(git clone "${{ steps.projectinfo.outputs.url }}" wrt && cd wrt && git checkout "${{ steps.refinfo.outputs.ref }}")
echo "🔖 当前版本:$(cd wrt && git describe --tags --always || git rev-parse --short HEAD)"
- name: Apply custom configurations
working-directory: wrt
run: |
TARGET_TYPE=$(grep -qi immortalwrt package/base-files/files/etc/openwrt_release 2>/dev/null && echo ImmortalWrt || \
[ -d feeds/packages ] && echo ImmortalWrt || echo OpenWrt)
CONFIG_GEN=package/base-files/files/bin/config_generate
echo "⚙️ 应用自定义配置..."
[ -n "${{ inputs.custom_hostname }}" ] && [ -f "$CONFIG_GEN" ] && \
sed -i "s/${TARGET_TYPE}/${{ inputs.custom_hostname }}/g" "$CONFIG_GEN" && echo "✅ Hostname: ${{ inputs.custom_hostname }}"
# 检测项目类型
DETECT_TARGET_FILE="package/base-files/files/etc/openwrt_release"
if [ -f "$DETECT_TARGET_FILE" ]; then
if grep -qi "immortalwrt" "$DETECT_TARGET_FILE"; then
TARGET_TYPE="ImmortalWrt"
else
TARGET_TYPE="OpenWrt"
fi
else
if [ -d "feeds/packages" ]; then
TARGET_TYPE="ImmortalWrt"
else
TARGET_TYPE="OpenWrt"
fi
fi
echo "📋 检测到目标类型:$TARGET_TYPE"
[ -n "${{ inputs.custom_ip }}" ] && [ -f "$CONFIG_GEN" ] && \
sed -i 's/192\.168\.[0-9]*\.[0-9]*/${{ inputs.custom_ip }}/g' "$CONFIG_GEN" && echo "✅ IP: ${{ inputs.custom_ip }}"
# 1. 设置自定义 hostname
if [ -n "${{ inputs.custom_hostname }}" ]; then
CONFIG_GEN_FILE="package/base-files/files/bin/config_generate"
if [ -f "$CONFIG_GEN_FILE" ]; then
if [ "$TARGET_TYPE" = "ImmortalWrt" ]; then
sed -i "s/ImmortalWrt/${{ inputs.custom_hostname }}/g" "$CONFIG_GEN_FILE"
else
sed -i "s/OpenWrt/${{ inputs.custom_hostname }}/g" "$CONFIG_GEN_FILE"
fi
echo "✅ Hostname 已设置为:${{ inputs.custom_hostname }}"
fi
fi
[ -n "${{ inputs.root_password }}" ] && [ -f package/base-files/files/etc/shadow ] && {
HASH=$(openssl passwd -1 '${{ inputs.root_password }}')
sed -i "s|^root:[^:]*:|root:${HASH}:|" package/base-files/files/etc/shadow
echo "✅ Root 密码已设置"
}
# 2. 设置自定义 IP 地址
if [ -n "${{ inputs.custom_ip }}" ]; then
CONFIG_GEN_FILE="package/base-files/files/bin/config_generate"
if [ -f "$CONFIG_GEN_FILE" ]; then
sed -i 's/192\.168\.[0-9]*\.[0-9]*/${{ inputs.custom_ip }}/g' "$CONFIG_GEN_FILE"
echo "✅ 默认 IP 已设置为:${{ inputs.custom_ip }}"
fi
fi
# 3. 设置 root 密码
if [ -n "${{ inputs.root_password }}" ]; then
SHADOW_FILE="package/base-files/files/etc/shadow"
if [ -f "$SHADOW_FILE" ]; then
HASH=$(openssl passwd -1 '${{ inputs.root_password }}')
if grep -q "^root:" "$SHADOW_FILE"; then
sed -i "s|^root:[^:]*:|root:${HASH}:|" "$SHADOW_FILE"
elif grep -q "^root::" "$SHADOW_FILE"; then
sed -i "s|root::|root:${HASH}:|" "$SHADOW_FILE"
fi
echo "✅ root 密码已设置"
fi
fi
# 4. 设置 LuCI 主题
mkdir -p package/base-files/files/etc/uci-defaults
cat >package/base-files/files/etc/uci-defaults/99_set_theme <<'EOF'
uci set luci.main.mediaurlbase=/luci-static/${{ inputs.luci_theme }}; uci commit luci
uci set luci.main.mediaurlbase=/luci-static/${{ inputs.luci_theme }}
uci commit luci
EOF
chmod +x package/base-files/files/etc/uci-defaults/99_set_theme
echo "✅ LuCI 主题已设置为:${{ inputs.luci_theme }}"
# 5. 启用/禁用 BBR
if [ "${{ inputs.enable_bbr }}" = "true" ]; then
mkdir -p package/base-files/files/etc/sysctl.d
echo -e 'net.core.default_qdisc=fq_codel\nnet.ipv4.tcp_congestion_control=bbr' \
> package/base-files/files/etc/sysctl.d/99-bbr.conf && echo "✅ BBR 已启用"
cat >package/base-files/files/etc/sysctl.d/99-bbr.conf <<'EOF'
net.core.default_qdisc=fq_codel
net.ipv4.tcp_congestion_control=bbr
EOF
echo "✅ BBR 拥塞控制算法已启用"
else
rm -f package/base-files/files/etc/sysctl.d/99-bbr.conf && echo " BBR 已禁用"
rm -f package/base-files/files/etc/sysctl.d/99-bbr.conf || true
echo " BBR 拥塞控制算法已禁用"
fi
PASSWD=package/base-files/files/etc/passwd
if [ -f "$PASSWD" ]; then
[ "${{ inputs.custom_shell }}" = "bash" ] && sed -i 's|/bin/ash|/bin/bash|g' "$PASSWD" || \
sed -i 's|/bin/bash|/bin/ash|g' "$PASSWD"
echo "✅ Shell: ${{ inputs.custom_shell }}"
# 6. 设置默认 shell
PASSWD_FILE="package/base-files/files/etc/passwd"
if [ -f "$PASSWD_FILE" ]; then
if [ "${{ inputs.custom_shell }}" = "bash" ]; then
if grep -q "/bin/ash" "$PASSWD_FILE"; then
sed -i "s|/bin/ash|/bin/bash|g" "$PASSWD_FILE"
echo "✅ 默认 shell 已设置为 bash"
fi
else
if grep -q "/bin/bash" "$PASSWD_FILE"; then
sed -i "s|/bin/bash|/bin/ash|g" "$PASSWD_FILE"
echo "✅ 默认 shell 已设置为 ash"
fi
fi
fi
# 7. 设置自定义 SSH 横幅
mkdir -p package/base-files/files/etc
if [ -n "${{ inputs.custom_banner }}" ]; then
echo "${{ inputs.custom_banner }}" > package/base-files/files/etc/banner
cat >package/base-files/files/etc/banner <<'EOF'
${{ inputs.custom_banner }}
EOF
echo "✅ 使用自定义 banner"
else
cat >package/base-files/files/etc/banner <<'EOF'
| | _____ _____ ____________/ |______ | |
@@ -283,43 +363,57 @@ jobs:
\/ \/ By Dich \/
-----------------------------------------------------
EOF
fi && echo "✅ Banner 已设置"
echo "✅ 默认 banner 已设置"
fi
echo "✅ 自定义配置完成"
- name: Copy and Run diy.sh
run: |
echo "📂 复制 diy.sh 到 wrt 目录并执行(可选)"
if [ -f diy.sh ]; then
cp diy.sh wrt/diy.sh
cd wrt
chmod +x diy.sh
./diy.sh || echo "⚠️ diy.sh 执行失败,继续构建..."
else
echo " diy.sh 不存在,跳过"
fi
- name: Update and install feeds
working-directory: wrt
run: |
if [ "${{ inputs.proxy_luci_app_zzz }}" = "true" ]; then
echo "src-git luci-app-zzz https://github.com/Dichgrem/luci-app-zzz.git" >> feeds.conf.default
echo "📦 添加 luci-app-zzz feed"
echo "src-git luci-app-zzz https://github.com/Dichgrem/luci-app-zzz.git" >> "feeds.conf.default"
fi
if [ "${{ inputs.proxy_passwall2 }}" = "true" ]; then
echo "src-git passwall https://github.com/xiaorouji/openwrt-passwall2.git" >> feeds.conf.default
fi
if [ "${{ inputs.proxy_luci_app_momo }}" = "true" ]; then
echo "src-git momo https://github.com/nikkinikki-org/OpenWrt-momo.git" >> feeds.conf.default
fi
./scripts/feeds update -a && ./scripts/feeds install -a
if [ "${{ inputs.proxy_passwall2 }}" = "true" ]; then
echo "📦 添加 passwall2 feed"
echo "src-git passwall https://github.com/xiaorouji/openwrt-passwall2.git" >> "feeds.conf.default"
fi
if [ "${{ inputs.proxy_luci_app_momo }}" = "true" ]; then
echo "📦 添加 luci-app-momo feed"
echo "src-git momo https://github.com/nikkinikki-org/OpenWrt-momo.git" >> "feeds.conf.default"
fi
echo "📦 更新 feeds"
./scripts/feeds update -a
echo "📦 安装 feeds"
./scripts/feeds install -a
- name: Setup configuration
working-directory: wrt
run: |
# 复制配置文件(如果提供)
if [ -n "${{ inputs.config_path }}" ] && [ -f "${{ inputs.config_path }}" ]; then
echo "📋 复制配置:${{ inputs.config_path }} → .config"
cp "${{ inputs.config_path }}" .config
else
echo " 未提供配置文件,使用默认配置"
# 生成默认配置
make defconfig || true
fi
echo "📋 复制配置:${{ inputs.config_path }} → wrt/.config"
cp "${{ inputs.config_path }}" wrt/.config
# 备份配置文件以供对比
cd wrt
echo "📑 备份配置文件以供对比"
cp .config .config.before_oldconfig
echo "🔄 运行 defconfig"
make defconfig
echo "🔄 运行 oldconfig"
echo "🔄 运行 make oldconfig"
make oldconfig
echo "🔍 对比 make oldconfig 前后的 .config 差异"
@@ -386,29 +480,19 @@ jobs:
- name: Build statistics
if: steps.build.outputs.build_success == 'true'
working-directory: wrt
run: |
echo "📊 编译统计信息:"
echo "项目:${{ inputs.project }}"
echo "版本类型${{ inputs.version_type }}"
if [ "${{ inputs.version_type }}" = "snapshot" ]; then
VERSION_INFO=$(git describe --tags --always 2>/dev/null || echo "latest")
BRANCH_INFO=$(git branch --show-current 2>/dev/null || echo "unknown")
echo "版本:${VERSION_INFO} (${BRANCH_INFO}分支)"
else
echo "版本:${{ inputs.tag }} (稳定版)"
fi
echo "版本:${{ steps.refinfo.outputs.ref }}"
echo "编译线程:${{ steps.build.outputs.jobs_count }}"
echo "缓存状态:${{ inputs.cache_enabled }}"
echo ""
echo "固件文件列表:"
if [ -d bin/targets ]; then
find bin/targets -type f -exec ls -lh {} \; | awk '{print $9, $5}'
if [ -d wrt/bin/targets ]; then
find wrt/bin/targets -type f -exec ls -lh {} \; | awk '{print $9, $5}'
echo ""
echo "总固件大小:"
du -sh bin/targets
du -sh wrt/bin/targets
fi
- name: Upload build log on failure
@@ -449,10 +533,6 @@ jobs:
if: always()
run: |
echo "🧹 清理工作空间..."
if [ -d "wrt" ]; then
cd wrt
make clean || true
echo "✅ 清理完成"
else
echo " wrt 目录不存在,跳过清理"
fi
cd wrt
make clean || true
echo "✅ 清理完成"

View File

@@ -10,3 +10,4 @@ This is a Openwrt build workflows.
| immortalwrt | https://github.com/immortalwrt/immortalwrt.git | immortalwrt/immortalwrt |
| immortalwrt-mt798x | https://github.com/hanwckf/immortalwrt-mt798x.git | hanwckf/immortalwrt-mt798x |
| immortalwrt-mt798x-6.6 | https://github.com/padavanonly/immortalwrt-mt798x-6.6.git | padavanonly/immortalwrt-mt798x-6.6 |