Skip to content

我的OpenWrt云编译:NFD2 2024.06.06 #111

我的OpenWrt云编译:NFD2 2024.06.06

我的OpenWrt云编译:NFD2 2024.06.06 #111

Workflow file for this run

#
# Copyright (c) 2019-2023 cnbbx <https://cnbbx.com>
#
# This is free software, licensed under the MIT License.
# See /LICENSE for more information.
#
name: build-openWrt
run-name: 我的OpenWrt云编译:${{ inputs.TITLE_SHOW }}
env:
REPO_URL: https://github.com/cnbbx/Openwrt-src.git
REPO_BRANCH: openwrt-23.05
BUILD_USER: ${{ github.actor }}
TZ: Asia/Shanghai
on:
repository_dispatch:
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: "开启tmate远程调试"
required: false
default: false
git_init_enabled:
description: "首次初始化GIT"
type: boolean
required: false
default: false
UPLOAD_BIN_DIR:
description: "保存编译后的全部文件"
type: boolean
default: true
UPLOAD_RELEASE:
description: "发布固件到Releases"
type: boolean
default: true
YOUKU_BUILD:
description: "开启youku_yk-l2编译"
type: boolean
default: true
NEWIFI_BUILD:
description: "开启d-team_newifi-d2编译"
type: boolean
default: true
X86_BUILD:
description: "开启x86_64编译"
type: boolean
default: true
TITLE_SHOW:
type: string
description: 任务流程标题
#schedule:
# - cron: '5 22 * * 0'
jobs:
build:
runs-on: ubuntu-20.04
strategy:
matrix:
include:
- FIRMWARE_NAME: youku_yk-l2
FIRMWARE_BUILD: ${{ inputs.YOUKU_BUILD }}
- FIRMWARE_NAME: d-team_newifi-d2
FIRMWARE_BUILD: ${{ inputs.NEWIFI_BUILD }}
- FIRMWARE_NAME: x86_64
FIRMWARE_BUILD: ${{ inputs.X86_BUILD }}
steps:
- name: checkout
uses: actions/checkout@main
- name: 检查空间使用情况
run: |
echo "警告⚠"
echo -e "-------------- ------------CPU信息------------------------------------------\n"
echo "CPU物理数量:$(cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l)"
echo -e "CPU核心及版本信息:$(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c) \n"
echo "-------------------------------内存信息-------------------------------------------"
echo "已安装内存详细信息:"
sudo lshw -short -C memory | grep GiB
echo -e "\n"
echo "-----------------------------硬盘信息---------------------------------------------"
echo -e "硬盘数量:$(ls /dev/sd* | grep -v [1-9] | wc -l) \n"
echo "硬盘详情:"
df -Th
- name: 初始化系统环境
if: matrix.FIRMWARE_BUILD == true
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc
sudo -E apt-get -qq update
sudo -E apt-get -qq install libfuse-dev build-essential asciidoc binutils bzip2 gawk gettext \
git libncurses5-dev libz-dev patch python3 python2.7 unzip zlib1g-dev lib32gcc1 libc6-dev-i386 \
subversion flex uglifyjs git-core gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo \
libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint \
device-tree-compiler g++-multilib antlr3 gperf wget curl swig rsync
sudo -E apt-get -qq autoremove --purge
sudo -E apt-get -qq clean
sudo timedatectl set-timezone "$TZ"
sudo mkdir -p /workdir
sudo chown $USER:$GROUPS /workdir
- name: Cache OpenWrt Source
id: cache
uses: actions/cache@v3
with:
path: /workdir/openwrt
key: openwrt-${{ hashFiles('**/openwrt/.git/ref') }}
restore-keys: |
openwrt-
- name: 克隆软路由源代码
if: matrix.FIRMWARE_BUILD == true && inputs.git_init_enabled
run: |
git clone --depth=1 $REPO_URL -b $REPO_BRANCH openwrt
ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt
- name: 更新Git仓库到最新
if: matrix.FIRMWARE_BUILD == true
run: |
cd openwrt
git fetch origin $REPO_BRANCH
git reset --hard FETCH_HEAD
git pull
- name: 下载自定义项目的清单
if: matrix.FIRMWARE_BUILD == true
run: |
tree
[ -e feeds.conf.default ] && mv feeds.conf.default openwrt/feeds.conf.default
[ -e my-changes.patch ] && mv my-changes.patch openwrt/my-changes.patch
cd openwrt
[ -e my-changes.patch ] && git apply my-changes.patch
./scripts/feeds update -a
- name: 安装自定义项目的清单
if: matrix.FIRMWARE_BUILD == true
run: cd openwrt && ./scripts/feeds install -a
- name: 加载自定义固件配置
if: matrix.FIRMWARE_BUILD == true && !cancelled()
run: |
[ -e files ] && mv files openwrt/files
[ -e ${{ matrix.FIRMWARE_NAME }}.config ] && mv ${{ matrix.FIRMWARE_NAME }}.config openwrt/.config
[ -e ${{ matrix.FIRMWARE_NAME }}.sh ] && mv ${{ matrix.FIRMWARE_NAME }}.sh openwrt/diy.sh
cd openwrt/ && chmod +x diy.sh && ./diy.sh
- name: 启动tmate远程调试
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
- name: 下载自定义固件插件
if: matrix.FIRMWARE_BUILD == true && !cancelled()
id: package
run: |
cd openwrt
make defconfig
make download -j$(nproc)
find dl -size -1024c -exec ls -l {} \;
find dl -size -1024c -exec rm -f {} \;
- name: 编译固件
if: matrix.FIRMWARE_BUILD == true && !cancelled()
id: compile
run: |
cd openwrt && mkdir -p firmware
echo -e "$(nproc) thread compile"
make -j$(nproc) || make -j1 V=s
cd bin/targets/*/*
mv *.buildinfo *.manifest *.bin $GITHUB_WORKSPACE/openwrt/firmware || true
mv *.vmdk $GITHUB_WORKSPACE/openwrt/firmware || true
mv *.vhdx $GITHUB_WORKSPACE/openwrt/firmware || true
- name: 保存编译后的固件文件
if: matrix.FIRMWARE_BUILD == true && inputs.UPLOAD_BIN_DIR == true && !cancelled()
uses: actions/upload-artifact@main
with:
name: OpenWrt_Firmware
path: openwrt/firmware
- name: 保存编译后的插件文件
if: matrix.FIRMWARE_BUILD == true && inputs.UPLOAD_BIN_DIR == true&& !cancelled()
uses: actions/upload-artifact@main
with:
name: OpenWrt_Packages
path: openwrt/bin
deploy:
needs: build
runs-on: ubuntu-20.04
steps:
- name: 调取编译后的固件文件
uses: actions/download-artifact@main
with:
name: OpenWrt_Firmware
path: openwrt/firmware
- name: 调取编译后的插件文件
uses: actions/download-artifact@main
with:
name: OpenWrt_Packages
path: openwrt/bin
- name: 优化需要发布的固件
id: organize
if: (!cancelled())
run: |
cd openwrt
tar -zcvf firmware/Packages.tar.gz ./bin/
- name: 生成 release tag
id: tag
if: (inputs.UPLOAD_RELEASE == true) && !cancelled()
run: |
echo "release_tag=$(date +"%Y.%m.%d-%H%M")" >> $GITHUB_OUTPUT
touch release.txt
cat >> release.txt <<EOF
1、本固件为自动编译
2、发行版中只提供完整的固件
3、源码:${{ env.REPO_URL }}
-- Build by ${{ env.BUILD_USER }} @ with Github Action on $(date +"%Y.%m.%d-%H%M")
🚀 Auto build | 自动编译
EOF
- name: 上传固件到release
uses: softprops/action-gh-release@v1
if: (inputs.UPLOAD_RELEASE == true) && !cancelled()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag.outputs.release_tag }}
body_path: release.txt
files: openwrt/firmware/*
- name: 移除老的 workflow runs
uses: zhoujinshi/delete-workflow-runs@main
with:
retain_days: 1
keep_minimum_runs: 3
- name: 移除老的 Releases
uses: dev-drprasad/delete-older-releases@master
if: (inputs.UPLOAD_RELEASE == true || inputs.UPLOAD_RELEASE == '') && !cancelled()
with:
keep_latest: 3
delete_tags: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}