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" - "snapshot"
- "stable" - "stable"
config_path: config_path:
description: "配置文件路径(留空则跳过)" description: "配置文件路径"
required: false required: true
default: "config/x86_64_config" default: "config/x86_64_config"
type: string type: string
proxy_passwall2: proxy_passwall2:
@@ -56,15 +56,10 @@ on:
required: false required: false
default: true default: true
type: boolean type: boolean
enable_bbr:
description: "启用 BBR 拥塞控制"
required: false
default: true
type: boolean
custom_shell: custom_shell:
description: "默认 shell" description: "默认 shell"
required: false required: false
default: "bash" default: "ash"
type: choice type: choice
options: options:
- ash - ash
@@ -78,6 +73,11 @@ on:
- argon - argon
- bootstrap - bootstrap
- material - material
enable_bbr:
description: "启用 BBR 拥塞控制"
required: false
default: true
type: boolean
custom_hostname: custom_hostname:
description: "自定义 hostname留空则跳过" description: "自定义 hostname留空则跳过"
required: false required: false
@@ -118,7 +118,7 @@ jobs:
id: validate id: validate
run: | run: |
echo "🔍 验证输入参数..." echo "🔍 验证输入参数..."
# 验证 threads 参数 # 验证 threads 参数
if [ -n "${{ inputs.threads }}" ]; then if [ -n "${{ inputs.threads }}" ]; then
if ! [[ "${{ inputs.threads }}" =~ ^[0-9]+$ ]]; then if ! [[ "${{ inputs.threads }}" =~ ^[0-9]+$ ]]; then
@@ -127,21 +127,18 @@ jobs:
exit 1 exit 1
fi fi
fi fi
# 验证配置文件是否存在(如果提供了路径) # 验证配置文件是否存在
if [ -n "${{ inputs.config_path }}" ]; then if [ -f "${{ inputs.config_path }}" ]; then
if [ -f "${{ inputs.config_path }}" ]; then echo "config_exists=true" >> "$GITHUB_OUTPUT"
echo "config_exists=true" >> "$GITHUB_OUTPUT" echo "✅ 配置文件存在:${{ inputs.config_path }}"
echo "✅ 配置文件存在:${{ inputs.config_path }}"
else
echo "config_exists=false" >> "$GITHUB_OUTPUT"
echo "⚠️ 配置文件不存在:${{ inputs.config_path }},将跳过配置文件"
fi
else else
echo "config_exists=false" >> "$GITHUB_OUTPUT" echo "config_exists=false" >> "$GITHUB_OUTPUT"
echo " 未提供配置文件路径,将使用默认配置" echo "❌ 配置文件不存在:${{ inputs.config_path }}"
echo "is_valid=false" >> "$GITHUB_OUTPUT"
exit 1
fi fi
echo "is_valid=true" >> "$GITHUB_OUTPUT" echo "is_valid=true" >> "$GITHUB_OUTPUT"
echo "✅ 所有输入参数验证通过" echo "✅ 所有输入参数验证通过"
@@ -155,15 +152,69 @@ jobs:
- name: Checkout current repository - name: Checkout current repository
uses: actions/checkout@v4 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 - name: Install dependencies
run: | run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/{ghc,az,microsoft} sudo apt-get update
sudo apt-get update && sudo apt-get install -y \ sudo apt-get install -y \
build-essential clang flex bison g++ gawk gettext git \ 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 \ rsync unzip zlib1g-dev file wget curl \
{gzip,tar,zip,xz-utils,bzip2,zstd} \ gzip tar zip xz-utils bzip2 zstd \
make cmake {autoconf,automake,libtool,patch,diffutils} \ make cmake autoconf automake libtool patch diffutils \
findutils grep sed help2man texinfo \ findutils grep sed help2man texinfo \
libelf-dev libfuse-dev liblzma-dev libxml2-dev libyaml-dev \ libelf-dev libfuse-dev liblzma-dev libxml2-dev libyaml-dev \
uuid-dev device-tree-compiler antlr3 gperf \ uuid-dev device-tree-compiler antlr3 gperf \
@@ -175,105 +226,134 @@ jobs:
id: projectinfo id: projectinfo
run: | run: |
case "${{ inputs.project }}" in case "${{ inputs.project }}" in
immortalwrt) echo "url=https://github.com/immortalwrt/immortalwrt.git" >> $GITHUB_OUTPUT ;; immortalwrt)
immortalwrt-mt798x) echo "url=https://github.com/hanwckf/immortalwrt-mt798x.git" >> $GITHUB_OUTPUT ;; echo "url=https://github.com/immortalwrt/immortalwrt.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 ;; immortalwrt-mt798x)
*) echo "❌ 未知项目" >&2; exit 1 ;; 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 esac
- name: Clone Wrt source - name: Clone Wrt source
run: | run: |
echo "📥 克隆 ${{ inputs.project }} (${{ inputs.version_type }})" echo "📥 克隆 ${{ inputs.project }} 仓库"
git clone --depth 1 "${{ steps.projectinfo.outputs.url }}" -b "${{ steps.refinfo.outputs.ref }}" wrt || \
[ "${{ inputs.version_type }}" = "snapshot" ] && BRANCH_MODE=1 || BRANCH_MODE=0 (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)"
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 }}
- name: Apply custom configurations - name: Apply custom configurations
working-directory: wrt working-directory: wrt
run: | run: |
TARGET_TYPE=$(grep -qi immortalwrt package/base-files/files/etc/openwrt_release 2>/dev/null && echo ImmortalWrt || \ echo "⚙️ 应用自定义配置..."
[ -d feeds/packages ] && echo ImmortalWrt || echo OpenWrt)
CONFIG_GEN=package/base-files/files/bin/config_generate
[ -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" ] && \ # 1. 设置自定义 hostname
sed -i 's/192\.168\.[0-9]*\.[0-9]*/${{ inputs.custom_ip }}/g' "$CONFIG_GEN" && echo "✅ IP: ${{ inputs.custom_ip }}" 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 ] && { # 2. 设置自定义 IP 地址
HASH=$(openssl passwd -1 '${{ inputs.root_password }}') if [ -n "${{ inputs.custom_ip }}" ]; then
sed -i "s|^root:[^:]*:|root:${HASH}:|" package/base-files/files/etc/shadow CONFIG_GEN_FILE="package/base-files/files/bin/config_generate"
echo "✅ Root 密码已设置" 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 mkdir -p package/base-files/files/etc/uci-defaults
cat >package/base-files/files/etc/uci-defaults/99_set_theme <<'EOF' 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 EOF
chmod +x package/base-files/files/etc/uci-defaults/99_set_theme 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 if [ "${{ inputs.enable_bbr }}" = "true" ]; then
mkdir -p package/base-files/files/etc/sysctl.d mkdir -p package/base-files/files/etc/sysctl.d
echo -e 'net.core.default_qdisc=fq_codel\nnet.ipv4.tcp_congestion_control=bbr' \ cat >package/base-files/files/etc/sysctl.d/99-bbr.conf <<'EOF'
> package/base-files/files/etc/sysctl.d/99-bbr.conf && echo "✅ BBR 已启用" net.core.default_qdisc=fq_codel
net.ipv4.tcp_congestion_control=bbr
EOF
echo "✅ BBR 拥塞控制算法已启用"
else 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 fi
PASSWD=package/base-files/files/etc/passwd # 6. 设置默认 shell
if [ -f "$PASSWD" ]; then PASSWD_FILE="package/base-files/files/etc/passwd"
[ "${{ inputs.custom_shell }}" = "bash" ] && sed -i 's|/bin/ash|/bin/bash|g' "$PASSWD" || \ if [ -f "$PASSWD_FILE" ]; then
sed -i 's|/bin/bash|/bin/ash|g' "$PASSWD" if [ "${{ inputs.custom_shell }}" = "bash" ]; then
echo "✅ Shell: ${{ inputs.custom_shell }}" 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 fi
# 7. 设置自定义 SSH 横幅
mkdir -p package/base-files/files/etc mkdir -p package/base-files/files/etc
if [ -n "${{ inputs.custom_banner }}" ]; then 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 else
cat >package/base-files/files/etc/banner <<'EOF' cat >package/base-files/files/etc/banner <<'EOF'
| | _____ _____ ____________/ |______ | | | | _____ _____ ____________/ |______ | |
@@ -283,43 +363,57 @@ jobs:
\/ \/ By Dich \/ \/ \/ By Dich \/
----------------------------------------------------- -----------------------------------------------------
EOF 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 - name: Update and install feeds
working-directory: wrt working-directory: wrt
run: | run: |
if [ "${{ inputs.proxy_luci_app_zzz }}" = "true" ]; then 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 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 - name: Setup configuration
working-directory: wrt
run: | run: |
# 复制配置文件(如果提供) echo "📋 复制配置:${{ inputs.config_path }} → wrt/.config"
if [ -n "${{ inputs.config_path }}" ] && [ -f "${{ inputs.config_path }}" ]; then cp "${{ inputs.config_path }}" wrt/.config
echo "📋 复制配置:${{ inputs.config_path }} → .config"
cp "${{ inputs.config_path }}" .config
else
echo " 未提供配置文件,使用默认配置"
# 生成默认配置
make defconfig || true
fi
# 备份配置文件以供对比 cd wrt
echo "📑 备份配置文件以供对比"
cp .config .config.before_oldconfig cp .config .config.before_oldconfig
echo "🔄 运行 defconfig" echo "🔄 运行 make oldconfig"
make defconfig
echo "🔄 运行 oldconfig"
make oldconfig make oldconfig
echo "🔍 对比 make oldconfig 前后的 .config 差异" echo "🔍 对比 make oldconfig 前后的 .config 差异"
@@ -386,29 +480,19 @@ jobs:
- name: Build statistics - name: Build statistics
if: steps.build.outputs.build_success == 'true' if: steps.build.outputs.build_success == 'true'
working-directory: wrt
run: | run: |
echo "📊 编译统计信息:" echo "📊 编译统计信息:"
echo "项目:${{ inputs.project }}" echo "项目:${{ inputs.project }}"
echo "版本类型${{ inputs.version_type }}" echo "版本:${{ steps.refinfo.outputs.ref }}"
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.build.outputs.jobs_count }}" echo "编译线程:${{ steps.build.outputs.jobs_count }}"
echo "缓存状态:${{ inputs.cache_enabled }}" echo "缓存状态:${{ inputs.cache_enabled }}"
echo "" echo ""
echo "固件文件列表:" echo "固件文件列表:"
if [ -d bin/targets ]; then if [ -d wrt/bin/targets ]; then
find bin/targets -type f -exec ls -lh {} \; | awk '{print $9, $5}' find wrt/bin/targets -type f -exec ls -lh {} \; | awk '{print $9, $5}'
echo "" echo ""
echo "总固件大小:" echo "总固件大小:"
du -sh bin/targets du -sh wrt/bin/targets
fi fi
- name: Upload build log on failure - name: Upload build log on failure
@@ -449,10 +533,6 @@ jobs:
if: always() if: always()
run: | run: |
echo "🧹 清理工作空间..." echo "🧹 清理工作空间..."
if [ -d "wrt" ]; then cd wrt
cd wrt make clean || true
make clean || true echo "✅ 清理完成"
echo "✅ 清理完成"
else
echo " wrt 目录不存在,跳过清理"
fi

View File

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