chore:actions

This commit is contained in:
dichgrem
2026-01-18 15:41:16 +08:00
parent f69b2749db
commit 15e1df01f5
2 changed files with 232 additions and 44 deletions

View File

@@ -30,15 +30,15 @@ on:
config_path:
description: "配置文件路径"
required: true
default: "config/myconfig"
default: "config/x86_64_config"
type: string
proxy_nikki:
description: "启用Nikki"
proxy_passwall2:
description: "启用Passwall2"
required: false
default: false
type: boolean
proxy_passwall2:
description: "启用Passwall2"
proxy_luci_app_zzz:
description: "启用luci-app-zzz"
required: false
default: false
type: boolean
@@ -52,10 +52,60 @@ on:
required: false
default: "0"
type: string
cache_enabled:
description: "启用缓存加速编译"
required: false
default: true
type: boolean
env:
CCACHE_DIR: ${{ github.workspace }}/wrt/.ccache
DL_DIR: ${{ github.workspace }}/wrt/dl
jobs:
build:
validate:
name: 验证输入参数
runs-on: ubuntu-latest
outputs:
is_valid: ${{ steps.validate.outputs.is_valid }}
config_exists: ${{ steps.validate.outputs.config_exists }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Validate inputs
id: validate
run: |
echo "🔍 验证输入参数..."
# 验证 threads 参数
if [ -n "${{ inputs.threads }}" ]; then
if ! [[ "${{ inputs.threads }}" =~ ^[0-9]+$ ]]; then
echo "❌ threads 参数必须是数字"
echo "is_valid=false" >> "$GITHUB_OUTPUT"
exit 1
fi
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 "❌ 配置文件不存在:${{ inputs.config_path }}"
echo "is_valid=false" >> "$GITHUB_OUTPUT"
exit 1
fi
echo "is_valid=true" >> "$GITHUB_OUTPUT"
echo "✅ 所有输入参数验证通过"
build:
name: 编译固件
runs-on: ubuntu-latest
needs: validate
timeout-minutes: 360
steps:
- name: Checkout current repository
@@ -68,23 +118,52 @@ jobs:
/usr/local/lib/android \
/opt/ghc \
/opt/az \
/opt/microsoft
/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 [ "$VERSION_TYPE" = "snapshot" ]; then
if [ "${{ inputs.version_type }}" = "snapshot" ]; then
echo "ref=master" >> "$GITHUB_OUTPUT"
else
echo "ref=$TAG" >> "$GITHUB_OUTPUT"
echo "ref=${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
fi
env:
VERSION_TYPE: ${{ inputs.version_type }}
TAG: ${{ inputs.tag }}
- name: Install dependencies
run: |
@@ -99,7 +178,8 @@ jobs:
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 \
llvm linux-tools-common libbpf-dev linux-tools-$(uname -r)
llvm linux-tools-common libbpf-dev linux-tools-$(uname -r) \
u-boot-tools device-tree-compiler
- name: Determine Git URL
id: projectinfo
@@ -129,10 +209,9 @@ jobs:
- name: Clone Wrt source
run: |
echo "📥 克隆 ${{ inputs.project }} 仓库"
git clone "${{ steps.projectinfo.outputs.url }}" wrt
cd wrt
echo "🔖 切换到版本:${{ steps.refinfo.outputs.ref }}"
git checkout "${{ steps.refinfo.outputs.ref }}"
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: Copy and Run diy.sh
run: |
@@ -145,19 +224,19 @@ jobs:
- name: Update and install feeds
working-directory: wrt
run: |
if [ "${{ github.event.inputs.proxy_nikki }}" == "true" ]; then
echo "📦 添加 nikki feed"
echo "src-git nikki https://github.com/nikkinikki-org/OpenWrt-nikki.git;main" >> "feeds.conf.default"
if [ "${{ inputs.proxy_luci_app_zzz }}" = "true" ]; then
echo "📦 添加 luci-app-zzz feed"
echo "src-git luci-app-zzz https://github.com/Dichgrem/luci-app-zzz.git" >> "feeds.conf.default"
fi
if [ "${{ github.event.inputs.proxy_passwall2 }}" == "true" ]; then
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 [ "${{ github.event.inputs.proxy_luci_app_momo }}" == "true" ]; then
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;main" >> "feeds.conf.default"
echo "src-git momo https://github.com/nikkinikki-org/OpenWrt-momo.git" >> "feeds.conf.default"
fi
echo "📦 更新 feeds"
@@ -168,11 +247,6 @@ jobs:
- 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
@@ -196,9 +270,14 @@ jobs:
run: |
echo "⬇️ 下载所有源码包(使用单线程 -j1 避免卡住)"
set -o pipefail
START=$(date +%s)
time make download -j1
END=$(date +%s)
DURATION=$((END - START))
echo "✅ 下载完成,耗时:${DURATION}秒"
- name: Build Firmware
id: build
working-directory: wrt
run: |
if [ "${{ inputs.threads }}" = "0" ] || [ -z "${{ inputs.threads }}" ]; then
@@ -209,7 +288,9 @@ jobs:
echo "🚀 全量编译(并行 ${JOBS})开始"
START=$(date "+%Y-%m-%d %H:%M:%S")
START_TS=$(date +%s)
echo "⏱️ 编译开始:${START}"
echo "jobs_count=${JOBS}" >> "$GITHUB_OUTPUT"
set -o pipefail
@@ -227,31 +308,72 @@ jobs:
fi
END=$(date "+%Y-%m-%d %H:%M:%S")
END_TS=$(date +%s)
DURATION=$((END_TS - START_TS))
DURATION_H=$((DURATION / 3600))
DURATION_M=$(((DURATION % 3600) / 60))
DURATION_S=$((DURATION % 60))
echo "✅ 编译成功"
echo "⏱️ 编译结束:${END}"
echo "⏱️ 总耗时:${DURATION_H}小时 ${DURATION_M}分钟 ${DURATION_S}秒"
echo "build_success=true" >> "$GITHUB_OUTPUT"
- name: list all target files
- name: Build statistics
if: steps.build.outputs.build_success == 'true'
run: |
echo ">>> 打印 wrt/bin/targets 下所有文件"
echo "📊 编译统计信息"
echo "项目:${{ inputs.project }}"
echo "版本:${{ steps.refinfo.outputs.ref }}"
echo "编译线程:${{ steps.build.outputs.jobs_count }}"
echo "缓存状态:${{ inputs.cache_enabled }}"
echo ""
echo "固件文件列表:"
if [ -d wrt/bin/targets ]; then
find wrt/bin/targets -type f | sed 's/^/ - /'
else
echo "❗ wrt/bin/targets 目录不存在"
find wrt/bin/targets -type f -exec ls -lh {} \; | awk '{print $9, $5}'
echo ""
echo "总固件大小:"
du -sh wrt/bin/targets
fi
- name: Upload build log on failure
uses: actions/upload-artifact@v4
if: failure()
with:
name: ${{ inputs.project }}-build-log-error
path: wrt/world_debug.log
retention-days: 7
if-no-files-found: ignore
- name: Upload build artifacts
uses: actions/upload-artifact@v4
if: steps.build.outputs.build_success == 'true'
with:
name: ${{ inputs.project }}-output
name: ${{ inputs.project }}-output-${{ inputs.version_type }}-${{ github.run_number }}
path: |
wrt/bin/targets/**
!wrt/bin/targets/x86/64/packages/**
!wrt/bin/targets/**/packages/**
if-no-files-found: warn
compression-level: 6
overwrite: false
retention-days: 30
- name: Upload build log
- name: Upload config diff
uses: actions/upload-artifact@v4
if: steps.build.outputs.build_success == 'true'
with:
name: ${{ inputs.project }}-build-log
path: wrt/world_debug.log
name: ${{ inputs.project }}-config-diff
path: |
wrt/.config
wrt/.config.before_oldconfig
if-no-files-found: ignore
retention-days: 7
- name: Cleanup
if: always()
run: |
echo "🧹 清理工作空间..."
cd wrt
make clean || true
echo "✅ 清理完成"