Build OpenWrt N1_rootfs #130
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 OpenWrt N1_rootfs | |
on: | |
repository_dispatch: | |
workflow_dispatch: | |
inputs: | |
ssh: | |
description: 'SSH connection to Actions' | |
required: false | |
default: 'false' | |
upload_firmware: | |
description: "whether to upload firmware." | |
required: false | |
default: "false" | |
env: | |
REPO_URL: https://github.com/coolsnowwolf/lede | |
REPO_BRANCH: master | |
FEEDS_CONF: lede.feeds.conf.default | |
CONFIG_FILE: n1_lede_4and6.config | |
DIY_P1_SH: diy-part1_n1_lede.sh | |
DIY_P2_SH: diy-part2_n1_lede.sh | |
CUSTOM: custom.sh | |
UPLOAD_BIN_DIR: false | |
UPLOAD_COWTRANSFER: false | |
UPLOAD_WETRANSFER: false | |
SERVERCHAN_SCKEY: true | |
USE_CACHEWRTBUILD: true | |
TZ: Asia/Shanghai | |
jobs: | |
build: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: telegrame_bot | |
run: | | |
echo "警告⚠" | |
echo "分配的服务器性能有限,若选择的插件过多,务必注意CPU性能!" | |
echo -e "已知CPU型号(降序): 7763,8370C,8272CL,8171M,E5-2673\n" | |
echo "--------------------------CPU信息--------------------------" | |
echo "CPU物理数量: $(cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l)" | |
echo "CPU核心数量: $(nproc)" | |
echo -e "CPU型号信息:$(cat /proc/cpuinfo | grep -m1 name | awk -F: '{print $2}')\n" | |
echo "--------------------------内存信息--------------------------" | |
echo "已安装内存详细信息:" | |
echo -e "$(sudo lshw -short -C memory | grep GiB)\n" | |
echo "--------------------------硬盘信息--------------------------" | |
echo "硬盘数量: $(ls /dev/sd* | grep -v [1-9] | wc -l)" && df -hT | |
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c > CPU | |
cat /proc/cpuinfo | grep "cpu cores" | uniq >> CPU | |
sed -i 's|[[:space:]]||g; s|^.||' CPU && sed -i 's|CPU||g; s|pucores:||' CPU | |
CPUNAME="$(awk 'NR==1' CPU)" && CPUCORES="$(awk 'NR==2' CPU)" | |
rm -rf CPU | |
if [[ "${SERVERCHAN_SCKEY}" == "true" ]]; then | |
curl -k --data chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" --data "text=🎉 主人: | |
您正在使用kissyouhunter仓库的 {CPU型号为 [ ${CPUNAME} ] 核心数 为 [ ${CPUCORES} ] 线程数为 [ $(nproc) ]的机器} 编译您自己的 N1 roofts 固件,请耐心等待...... 😋" "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" | |
fi | |
- name: Initialization environment | |
env: | |
DEBIAN_FRONTEND: noninteractive | |
run: | | |
docker rmi $(docker images -q) 2>/dev/null | |
[[ -n "${AGENT_TOOLSDIRECTORY}" ]] && sudo rm -rf "${AGENT_TOOLSDIRECTORY}" | |
sudo rm -rf /usr/share/dotnet /etc/apt/sources.list.d /usr/local/lib/android 2>/dev/null | |
sudo swapoff -a | |
sudo rm -f /swapfile /mnt/swapfile | |
sudo -E apt-get -y update | |
sudo -E apt-get -y purge azure-cli ghc* zulu* llvm* firefox google* dotnet* powershell openjdk* mongodb* moby* || true | |
sudo -E apt-get -y install $(curl -fsSL https://is.gd/depend_ubuntu2204_openwrt) | |
sudo -E systemctl daemon-reload | |
#sudo -E apt-get -y full-upgrade | |
sudo -E apt-get -y autoremove --purge | |
sudo -E apt-get clean | |
sudo sed -i '/NVM_DIR/d;/skel/d' /root/{.bashrc,.profile} | |
sudo rm -rf ~/{.cargo,.dotnet,.rustup} | |
sudo timedatectl set-timezone "${TZ}" | |
upload_firmware="${{ github.event.inputs.upload_firmware }}" | |
echo "UPLOAD_FIRMWARE=${upload_firmware}" >> $GITHUB_ENV | |
- name: Combine Disks | |
uses: easimon/maximize-build-space@master | |
with: | |
swap-size-mb: 1024 | |
root-reserve-mb: 512 | |
remove-dotnet: 'true' | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Clone source code | |
run: | | |
df -hT $GITHUB_WORKSPACE | |
git clone $REPO_URL -b $REPO_BRANCH openwrt | |
- name: Load custom feeds | |
run: | | |
[ -e $FEEDS_CONF ] && mv $FEEDS_CONF openwrt/feeds.conf.default | |
chmod +x $DIY_P1_SH | |
cd openwrt | |
$GITHUB_WORKSPACE/$DIY_P1_SH | |
- name: Update feeds | |
run: cd openwrt && ./scripts/feeds update -a | |
- name: Load custom configuration | |
run: | | |
[ -e files ] && mv files openwrt/files | |
[ -e $CONFIG_FILE ] && mv $CONFIG_FILE openwrt/.config | |
chmod +x $DIY_P2_SH | |
cd openwrt | |
$GITHUB_WORKSPACE/$DIY_P2_SH | |
chmod +x $GITHUB_WORKSPACE/$CUSTOM | |
$GITHUB_WORKSPACE/$CUSTOM | |
- name: Install feeds | |
run: | | |
cd openwrt && ./scripts/feeds install -a | |
- name: SSH connection to 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: chmod | |
run: | | |
cd openwrt | |
mkdir -p files/usr/sbin | |
cp $GITHUB_WORKSPACE/diy/n1_lede/usr/sbin/update files/usr/sbin/update -v | |
cp $GITHUB_WORKSPACE/diy/n1_lede/usr/sbin/install files/usr/sbin/install -v | |
chmod -R 755 . | |
- name: Download package | |
id: package | |
run: | | |
cd openwrt | |
make defconfig | |
make download -j8 | |
find dl -size -1024c -exec ls -l {} \; | |
find dl -size -1024c -exec rm -f {} \; | |
- name: Compile the firmware | |
id: compile | |
run: | | |
cd openwrt | |
echo -e "$(nproc) thread compile" | |
make -j$(nproc) || make -j1 || make -j1 V=s | |
# make -j1 V=s | |
echo "status=success" >> $GITHUB_OUTPUT | |
grep '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/.*DEVICE_(.*)=y/\1/' > DEVICE_NAME | |
[ -s DEVICE_NAME ] && echo "DEVICE_NAME=_$(cat DEVICE_NAME)" >> $GITHUB_ENV | |
echo "FILE_DATE=_$(date +"%Y%m%d%H%M")" >> $GITHUB_ENV | |
- name: Check space usage | |
if: (!cancelled()) | |
run: df -hT $GITHUB_WORKSPACE | |
- name: Upload bin directory | |
uses: actions/upload-artifact@master | |
if: steps.compile.outputs.status == 'success' && env.UPLOAD_BIN_DIR == 'true' | |
with: | |
name: OpenWrt_bin${{ env.DEVICE_NAME }}${{ env.FILE_DATE }} | |
path: openwrt/bin | |
- name: Organize files | |
id: organize | |
if: steps.compile.outputs.status == 'success' && !cancelled() | |
run: | | |
cd openwrt/bin/targets/*/* | |
rm -rf packages | |
echo "FIRMWARE=$PWD" >> $GITHUB_ENV | |
echo "status=success" >> $GITHUB_OUTPUT | |
- name: Upload firmware directory | |
uses: actions/upload-artifact@master | |
if: steps.organize.outputs.status == 'success' && env.UPLOAD_FIRMWARE == 'true' && !cancelled() | |
with: | |
name: OpenWrt_firmware${{ env.DEVICE_NAME }}${{ env.FILE_DATE }} | |
path: ${{ env.FIRMWARE }} | |
- name: Upload firmware to release | |
uses: ncipollo/release-action@v1 | |
if: steps.organize.outputs.status == 'success' && !cancelled() | |
with: | |
token: ${{ secrets.REPO_TOKEN }} | |
name: rootfs | |
tag: rootfs | |
commit: main | |
allowUpdates: true | |
artifacts: ${{ env.FIRMWARE }}/openwrt-armvirt-64-generic-rootfs.tar.gz | |
- name: Notify on failure | |
if: ${{ failure() }} | |
run: | | |
curl -k --data chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" --data "text=我亲爱的😭主人😭: | |
您使用kissyouhunter仓库的 N1 roofts 固件失败了,请及时处理!😭" "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" | |
- name: telegram_bot | |
run: | | |
if [[ "${SERVERCHAN_SCKEY}" == "true" ]]; then | |
curl -k --data chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" --data "text=我亲爱的✨主人✨: | |
您使用kissyouhunter仓库的 N1 roofts 固件顺利编译完成了!💐" "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" | |
fi |