Files
Dwrt-build/.github/workflows/build.yml
2025-07-25 21:31:22 +08:00

169 lines
5.0 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Build Custom WRT
on:
workflow_dispatch:
inputs:
project:
description: "选择 WRT 项目"
required: true
default: "immortalwrt"
type: choice
options:
- openwrt
- immortalwrt
- x-wrt
- lienol
- lede
version_type:
description: "版本类型"
required: true
default: "stable"
type: choice
options:
- "snapshot"
- "stable"
branch:
description: "snapshot-branch"
required: false
default: "master"
type: string
tag:
description: "stable-tag"
required: false
default: "v24.10.2"
type: string
config_path:
description: "config路径"
required: true
default: "config/myconfig"
type: string
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout current repository
uses: actions/checkout@v4
- name: Determine Git ref
id: refinfo
run: |
if [ "${{ inputs.version_type }}" = "snapshot" ]; then
echo "ref=${{ inputs.branch }}" >> $GITHUB_OUTPUT
else
echo "ref=${{ inputs.tag }}" >> $GITHUB_OUTPUT
fi
- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential clang flex bison g++ gawk gettext git \
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 \
findutils grep sed help2man texinfo \
libelf-dev libfuse-dev liblzma-dev libxml2-dev libyaml-dev \
uuid-dev device-tree-compiler antlr3 gperf \
time bc jq xxd swig upx-ucl ccache ecj fastjar imagemagick
- name: Determine Git URL
id: projectinfo
run: |
case "${{ inputs.project }}" in
immortalwrt)
echo "url=https://github.com/immortalwrt/immortalwrt.git" >> $GITHUB_OUTPUT
;;
x-wrt)
echo "url=https://github.com/x-wrt/x-wrt.git" >> $GITHUB_OUTPUT
;;
openwrt)
echo "url=https://git.openwrt.org/openwrt/openwrt.git" >> $GITHUB_OUTPUT
;;
lienol)
echo "url=https://github.com/Lienol/openwrt.git" >> $GITHUB_OUTPUT
;;
lede)
echo "url=https://github.com/coolsnowwolf/lede.git" >> $GITHUB_OUTPUT
;;
*)
echo "❌ 未知项目: ${{ inputs.project }}" >&2
exit 1
;;
esac
- name: Clone selected WRT source
run: |
echo "📥 克隆 ${{ inputs.project }} 仓库ref=${{ steps.refinfo.outputs.ref }}"
git clone --branch "${{ steps.refinfo.outputs.ref }}" \
"${{ steps.projectinfo.outputs.url }}" wrt
- name: Copy diy.sh to WRT
run: |
echo "📂 复制 diy.sh 到 wrt 目录"
cp diy.sh wrt/diy.sh
- name: Run diy.sh
working-directory: wrt
run: |
echo "🔧 执行 diy.sh"
chmod +x diy.sh
./diy.sh
- name: Update and install feeds
working-directory: wrt
run: |
echo "📦 更新 feeds"
./scripts/feeds update -a
echo "📦 安装 feeds"
./scripts/feeds install -a
- name: Setup configuration
run: |
echo "📋 复制配置:${{ inputs.config_path }} → wrt/.config"
if [ ! -f "${{ inputs.config_path }}" ]; then
echo "❌ 找不到配置文件:${{ inputs.config_path }}"
exit 1
fi
cp "${{ inputs.config_path }}" wrt/.config
cd wrt
echo "🔄 运行 make oldconfig"
make oldconfig
- name: Download source packages
working-directory: wrt
run: |
echo "⬇️ 下载所有源码包"
make download -j8
- name: Build Firmware
working-directory: wrt
run: |
JOBS=$(nproc)
echo "🚀 全量编译(并行 ${JOBS})开始"
START=$(date "+%Y-%m-%d %H:%M:%S")
echo "⏱️ 编译开始:${START}"
if ! time make world -j${JOBS} 2>&1 | tee build.log; then
echo "❌ 编译失败,输出最后 100 行日志:"
grep error ./build.log
exit 1
fi
END=$(date "+%Y-%m-%d %H:%M:%S")
echo "✅ 编译成功"
echo "⏱️ 结束:${END}"
- name: Upload firmware artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.project }}-output
path: |
wrt/bin/targets/**/*.{img,bin,tar.gz,zip}
- name: Upload build log
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.project }}-build-log
path: wrt/build.log