Build Lede #49
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Copyright (c) 2019-2020 P3TERX <https://p3terx.com> | |
# | |
# This is free software, licensed under the MIT License. | |
# See /LICENSE for more information. | |
# | |
# https://github.com/P3TERX/Actions-OpenWrt | |
# Description: Build OpenWrt using GitHub Actions | |
# | |
name: Build Lede | |
on: | |
repository_dispatch: | |
workflow_dispatch: | |
inputs: | |
ssh: | |
description: 'SSH connection to Actions' | |
required: false | |
default: 'false' | |
schedule: | |
- cron: 0 4 * * 5 | |
env: | |
REPO_URL: https://github.com/coolsnowwolf/lede | |
REPO_BRANCH: master | |
FEEDS_CONF: feeds.conf.default | |
CONFIG_FILE: .config | |
DIY_P1_SH: diy-part1.sh | |
DIY_P2_SH: diy-part2.sh | |
UPLOAD_BIN_DIR: true | |
UPLOAD_FIRMWARE: true | |
UPLOAD_RELEASE: true | |
UPLOAD_COWTRANSFER: false | |
UPLOAD_WETRANSFER: false | |
TZ: Asia/Shanghai | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
REPO_BRANCH: | |
- master | |
ARCHITECTURE: | |
- armv8 | |
os: | |
- ubuntu-22.04 | |
steps: | |
- name: 准备完成 | |
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 -e "------------------------------- 内存信息 -------------------------------\n" | |
echo "已安装内存详细信息: " | |
sudo lshw -short -C memory | grep GiB | |
echo -e "\n" | |
echo -e "------------------------------- 磁盘信息 -------------------------------\n" | |
echo -e "磁盘数量: $(ls /dev/sd* | grep -v [1-9] | wc -l) \n" | |
echo "------------------------------- 磁盘详情 -------------------------------\n" | |
df -Th | |
echo -e "------------------------------- 系统信息 -------------------------------\n" | |
cat /etc/os-release | |
uname -a | |
echo -e "------------------------------- 网络信息 -------------------------------\n" | |
ip addr show | |
echo -e "------------------------------- 网络连接信息 -------------------------------\n" | |
netstat -ntlp | |
echo -e "------------------------------- 进程信息 -------------------------------\n" | |
ps -ef | grep -v grep | |
echo -e "------------------------------- 系统负载信息 -------------------------------\n" | |
uptime | |
echo -e "------------------------------- 系统日志信息 -------------------------------\n" | |
cat /var/log/syslog | |
- name: 初始化编译环境 | |
env: | |
DEBIAN_FRONTEND: noninteractive | |
run: | | |
echo "------------------------------- 更新并安装依赖 -------------------------------" | |
sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /etc/mysql /usr/local/lib/android /opt/ghc | |
sudo -E apt-get -y update | |
sudo -E apt-get upgrade -qq -y | |
#sudo -E apt-get -qq -y install dialog | |
echo "------------------------------- 安装工具 --------------------------------------" | |
cat $GITHUB_WORKSPACE/depends/${{ matrix.os }} | |
sudo -E apt-get -qq -y install $(cat $GITHUB_WORKSPACE/depends/${{ matrix.os }}) | |
echo "------------------------------- 添加Python2符号链接 --------------------------------------" | |
sudo -E ln -s /usr/bin/python2.7 /usr/bin/python2 | |
echo "------------------------------- 清理Docker镜像和软件 -------------------------------" | |
docker rmi `docker images -q` | |
docker image prune -a -f | |
sudo -E apt-get -qq -y purge ghc* zulu* llvm* firefox google* dotnet* openjdk* mysql* php* mongodb* dotnet* moby* snapd* || true | |
sudo -E apt-get -qq autoremove --purge | |
sudo -E apt-get -qq clean | |
echo "------------------------------- 设置工作目录及时区 -------------------------------" | |
sudo timedatectl set-timezone "$TZ" | |
sudo mkdir -p /workdir | |
sudo chown $USER:$GROUPS /workdir | |
echo "------------------------------- 清理后磁盘详情 -------------------------------\n" | |
df -Th | |
- name: 克隆源码 | |
working-directory: /workdir | |
run: | | |
df -hT $PWD | |
git clone $REPO_URL -b ${{ matrix.REPO_BRANCH }} openwrt | |
ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt | |
- name: 缓存构建动作 | |
uses: klever1988/cachewrtbuild@main | |
with: | |
ccache: 'true' | |
mixkey: ${{ matrix.os }}-${{ matrix.ARCHITECTURE }}-${{ matrix.REPO_BRANCH }} | |
prefix: ${{ github.workspace }}/openwrt | |
- name: 加载自定义 feeds | |
env: | |
FEEDS_CONF_PATH: ${{ matrix.ARCHITECTURE }}/${{ env.FEEDS_CONF }} | |
run: | | |
[ -e $FEEDS_CONF_PATH ] && mv $FEEDS_CONF_PATH openwrt/$FEEDS_CONF | |
chmod +x $DIY_P1_SH | |
cd openwrt | |
$GITHUB_WORKSPACE/$DIY_P1_SH | |
- name: 更新 feeds | |
run: cd openwrt && ./scripts/feeds update -a | |
- name: 安装 feeds | |
run: cd openwrt && ./scripts/feeds install -a | |
- name: 加载自定义配置 | |
env: | |
CONFIG_FILE_PATH: ${{ matrix.ARCHITECTURE }}/config | |
run: | | |
[ -e files ] && mv files openwrt/files | |
[ -e $CONFIG_FILE_PATH ] && mv $CONFIG_FILE_PATH openwrt/$CONFIG_FILE | |
chmod +x $DIY_P2_SH | |
cd openwrt | |
$GITHUB_WORKSPACE/$DIY_P2_SH | |
- name: SSH 连接到 Actions | |
uses: P3TERX/[email protected] | |
if: (github.event.inputs.ssh == 'true' && github.event.inputs.ssh != 'false') || contains(github.event.action, 'ssh') | |
env: | |
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} | |
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} | |
- name: 下载软件包 | |
id: package | |
run: | | |
cd openwrt | |
yes ""|make oldconfig | |
make download -j8 | |
find dl -size -1024c -exec ls -l {} \; | |
find dl -size -1024c -exec rm -f {} \; | |
- name: 编译固件 | |
id: compile | |
run: | | |
cd openwrt | |
echo -e "$(nproc) thread compile" | |
make -j$(nproc) || make -j1 V=s | |
echo "FILE_DATE=_$(date +"%Y%m%d%H%M")" >> $GITHUB_ENV | |
# echo "::set-output name=status::success" | |
echo "status=success" >> $GITHUB_OUTPUT | |
- name: 检查磁盘空间 | |
if: (!cancelled()) | |
run: df -hT | |
- name: 上传 bin 文件夹 | |
uses: actions/upload-artifact@main | |
if: steps.compile.outputs.status == 'success' && env.UPLOAD_BIN_DIR == 'true' | |
with: | |
name: OpenWrt_bin${{ env.FILE_DATE }} | |
path: openwrt/bin | |
- name: 整理固件文件 | |
id: organize | |
if: env.UPLOAD_FIRMWARE == 'true' && !cancelled() | |
run: | | |
cd openwrt/bin/targets/*/* | |
ls -la | |
rm -rf packages | |
echo "FIRMWARE=$PWD" >> $GITHUB_ENV | |
# echo "::set-output name=status::success" | |
echo "status=success" >> $GITHUB_OUTPUT | |
ls $PWD/* | |
- name: 上传固件目录 | |
uses: actions/upload-artifact@main | |
if: steps.organize.outputs.status == 'success' && !cancelled() | |
with: | |
name: OpenWrt_firmware${{ env.FILE_DATE }} | |
path: ${{ env.FIRMWARE }} | |
- name: 生成发布标签 | |
id: tag | |
if: steps.compile.outputs.status == 'success' && env.UPLOAD_RELEASE == 'true' && !cancelled() | |
run: | | |
# echo "::set-output name=release_tag::$(date +"%Y.%m.%d-%H.%M")" | |
echo "release_tag=$(date +"%Y.%m.%d-%H.%M")" >> $GITHUB_OUTPUT | |
touch release.txt | |
echo " | |
💻 架构: ${{ matrix.ARCHITECTURE }} | |
📂 源码: ${{ env.REPO_URL }} | |
🌳 分支: ${{ matrix.REPO_BRANCH }} | |
⏱️ 编译时间: $(date +"%Y年%m月%d日%H时%M分") | |
🌐 管理地址: 192.168.100.1 | |
👤 用户名: root | |
🔒 密码: password " >> release.txt | |
# echo "::set-output name=status::success" | |
echo "status=success" >> $GITHUB_OUTPUT | |
- name: 自动发布固件到 Releases | |
uses: softprops/action-gh-release@v2 | |
if: steps.tag.outputs.status == 'success' && env.UPLOAD_RELEASE == 'true' && !cancelled() | |
with: | |
tag_name: ${{ steps.tag.outputs.release_tag }} | |
body_path: release.txt | |
files: ${{ env.FIRMWARE }}/* | |
token: ${{ env.GITHUB_TOKE }} | |
- name: 删除运行记录 | |
uses: GitRML/delete-workflow-runs@main | |
with: | |
retain_days: 1 | |
keep_minimum_runs: 1 | |
token: ${{ env.GITHUB_TOKEN }} | |
- name: 删除自动发布的旧固件 | |
uses: dev-drprasad/[email protected] | |
if: env.UPLOAD_RELEASE == 'true' && !cancelled() | |
with: | |
keep_latest: 4 | |
delete_tags: true |