Skip to content

编译 2024-12-01 18:13:03 #39

编译 2024-12-01 18:13:03

编译 2024-12-01 18:13:03 #39

Workflow file for this run

###
# @Author : jiaopengzi
# @BuildDate : 2024-12-01 18:13:03
# @FilePath : \build-openwrt\.github\workflows\build.yaml
# @Description : GitHub Actions 自动构建 OpenWrt
###
name: Build OpenWrt
# 触发条件
on:
push:
branches:
- main
paths:
# 当 main 分支下的 .github/workflows/build.yaml 文件发生变化时触发
- .github/workflows/build.yaml
workflow_dispatch:
# 手动触发
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
# 限制并发构建,防止同时构建多个
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
env:
# 在这里定义全局变量
KERNEL_VERSION: '6.6' # 可选内核版本 6.6 | 6.1 | 5.15 | 5.10 | 5.4
CONFIG_FILE: 'x86_64.config' # 配置文件
steps:
- name: __磁盘空间监控
run: |
echo "磁盘空间监控"
echo "=============================================================================="
df -hT
echo "=============================================================================="
# 设置日期环境变量
echo "DATETIME=$(TZ='Asia/Shanghai' date '+%Y%m%d%H%M%S')" >> $GITHUB_ENV
- name: 1. 磁盘空间优化
# 参考:https://github.com/dzikaros/ActionsBuildOpenWRT/blob/main/.github/workflows/build-x86_64_ipv4.yml
uses: 'hugoalh/disk-space-optimizer-ghaction@main'
with:
operate_sudo: 'True'
general_include: '.+'
general_exclude: |-
^GCC$
^G\+\+$
Clang
LLVM
docker_include: '.+'
docker_prune: 'True'
docker_clean: 'True'
apt_prune: 'True'
apt_clean: 'True'
homebrew_prune: 'True'
homebrew_clean: 'True'
npm_prune: 'True'
npm_clean: 'True'
os_swap: 'True'
- name: 2. 磁盘空间释放
uses: easimon/maximize-build-space@master
with:
root-reserve-mb: 2048
swap-size-mb: 1
remove-dotnet: 'true'
remove-android: 'true'
remove-haskell: 'true'
remove-codeql: 'true'
remove-docker-images: 'true'
- name: __磁盘空间监控
run: |
echo "磁盘空间监控"
echo "=============================================================================="
df -hT
echo "=============================================================================="
- name: 3. 检出仓库
uses: actions/checkout@v4
- name: 4. 安装环境依赖
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt update -y
sudo apt full-upgrade -y
sudo apt install -y ack antlr3 asciidoc autoconf automake autopoint binutils bison build-essential \
bzip2 ccache cmake cpio curl device-tree-compiler fastjar flex gawk gettext gcc-multilib g++-multilib \
git gperf haveged help2man intltool libc6-dev-i386 libelf-dev libfuse-dev libglib2.0-dev libgmp3-dev \
libltdl-dev libmpc-dev libmpfr-dev libncurses5-dev libncursesw5-dev libpython3-dev libreadline-dev \
libssl-dev libtool lrzsz mkisofs msmtp ninja-build p7zip p7zip-full patch pkgconf python3 \
python3-pyelftools python3-setuptools qemu-utils rsync scons squashfs-tools subversion swig texinfo \
uglifyjs upx-ucl unzip vim wget xmlto xxd zlib1g-dev \
make clang llvm nano python3-pip aria2 \
bc lm-sensors pciutils curl miniupnpd conntrack conntrackd jq liblzma-dev \
libpcre2-dev libpam0g-dev libkmod-dev libtirpc-dev libaio-dev libcurl4-openssl-dev libtins-dev libyaml-cpp-dev libglib2.0-dev libgpiod-dev
- name: 5. 下载源码
run: |
# 下载源码
echo "======================================== 下载源码"
git clone --depth 1 https://github.com/coolsnowwolf/lede -b master openwrt
# git clone https://github.com/coolsnowwolf/lede -b master openwrt
cd openwrt || exit
# 退回到 2024-10-16 版本
# git checkout 21bbc6fbed2122945184500e4fdefe2598c1a1e5
# 添加 ssrp 源
echo "src-git ssrp https://github.com/fw876/helloworld.git" >>./feeds.conf.default
# 更新软件包 & 安装依赖,出现 warning 信息不影响编译
echo "======================================== 更新软件包"
./scripts/feeds update -a
- name: 6. 安装编译依赖
run: |
echo "======================================== 安装依赖"
cd openwrt || exit
./scripts/feeds install -a
echo "======================================== 二次安装依赖,确保安装完整"
./scripts/feeds install -a
- name: 7. make_download
run: |
[ -e $CONFIG_FILE ] && mv $CONFIG_FILE ./openwrt/.config
# 打印当前目录
echo "======================================== 版本:$KERNEL_VERSION 当前下载目录"
cd openwrt || exit
pwd
# 指定内核版本
sed -i "s/^KERNEL_PATCHVER:=.*$/KERNEL_PATCHVER:=$KERNEL_VERSION/" target/linux/x86/Makefile
sed -i "s/^KERNEL_TESTING_PATCHVER:=.*$/KERNEL_TESTING_PATCHVER:=$KERNEL_VERSION/" target/linux/x86/Makefile
echo "======================================== 版本:$KERNEL_VERSION 修改指定内核完成."
# defconfig
echo "======================================== 版本:$KERNEL_VERSION make defconfig"
make defconfig
# 查看编译线程最大值
echo "======================================== 版本:$KERNEL_VERSION 下载线程数量:$(nproc)"
# 下载 dl 库
echo "======================================== 版本:$KERNEL_VERSION 下载dl库"
make download -j"$(nproc)"
- name: __磁盘空间监控
run: |
echo "磁盘空间监控"
echo "=============================================================================="
df -hT
echo "=============================================================================="
- name: 8. 编译固件
run: |
echo "======================================== 版本:$KERNEL_VERSION 当前编译目录"
cd openwrt || exit
pwd
echo "======================================== 版本:$KERNEL_VERSION 开始编译固件"
make -j"$(nproc)"
# make V=s -j1
echo "======================================== 版本:$KERNEL_VERSION 编译完成"
# 返回上层目录
echo "======================================== 当前目录"
cd ..
pwd
# 删除基础镜像
rm -f ./openwrt/bin/targets/x86/64/openwrt-x86-64-generic-squashfs-rootfs.img.gz
# 删除 kernel 文件
rm -f ./openwrt/bin/targets/x86/64/openwrt-x86-64-generic-kernel.bin
# 删除 packages 文件夹
rm -rf ./openwrt/bin/targets/x86/64/packages
- name: __磁盘空间监控
run: |
echo "磁盘空间监控"
echo "=============================================================================="
df -hT
echo "=============================================================================="
- name: 9. 上传编译固件
uses: actions/upload-artifact@v4
with:
name: openwrt-x86-64-${{ env.DATETIME }}
path: ./openwrt/bin/targets/x86/64
retention-days: 3 # 设置保留天数为3天
- name: 10. 停止job
run: |
echo "======================================== 停止job"
exit 0