Skip to content

Build ImmortalWrt

Build ImmortalWrt #56

#
# 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 ImmortalWrt
permissions: write-all
# 开启写权限,防止无法上传到release
on:
workflow_dispatch:
inputs:
USE_NX30PRO_EEPROM:
description: 'Use nx30pro eeprom'
required: true
default: true
type: boolean
USE_52MHZ:
description: 'Use 52MHz max-frequency'
required: true
default: true
type: boolean
env:
REPO_URL: https://github.com/immortalwrt/immortalwrt
REPO_BRANCH: openwrt-23.05
FREE_DISK_SH: scripts/free_disk_space.sh
ENV_SH: scripts/environment.sh
DIY_SH: scripts/diy.sh
CLASH_CORE: scripts/preset-clash-core.sh
UPLOAD_BIN_DIR: false
UPLOAD_FIRMWARE: false
UPLOAD_RELEASE: true
TZ: Asia/Shanghai
jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: 检查
uses: actions/checkout@main
- name: 初始化环境
env:
DEBIAN_FRONTEND: noninteractive
run: |
echo "USE_NX30PRO_EEPROM=${{ github.event.inputs.USE_NX30PRO_EEPROM }}" >> $GITHUB_ENV
echo "USE_52MHZ=${{ github.event.inputs.USE_52MHZ }}" >> $GITHUB_ENV
chmod +x $FREE_DISK_SH && $FREE_DISK_SH
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc
sudo -E apt-get -qq update -y
sudo -E apt-get -qq full-upgrade -y
chmod +x $ENV_SH && $ENV_SH
sudo timedatectl set-timezone "$TZ"
sudo mkdir -p /workdir
sudo chown $USER:$GROUPS /workdir
- name: 检查空间使用情况
if: (!cancelled())
run: df -hT
- name: 克隆源码
working-directory: /workdir
run: |
git clone $REPO_URL -b $REPO_BRANCH openwrt
ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt
- name: 开启缓存
uses: klever1988/cachewrtbuild@main
with:
ccache: 'true'
mixkey: 'openwrt23-cortexa53'
prefix: ${{ github.workspace }}/openwrt
- name: 更新 & 安装 feeds & 执行脚本
run: |
cd openwrt
./scripts/feeds update -a && ./scripts/feeds install -a
chmod +x $GITHUB_WORKSPACE/$DIY_SH && $GITHUB_WORKSPACE/$DIY_SH
- name: 导入补丁和配置
run: |
[ -e files ] && mv files openwrt/files
cat configs/rax3000m-emmc.config >> openwrt/.config
- name: 设置是否使用 nx30pro eeprom
if: env.USE_NX30PRO_EEPROM == 'true'
run: |
mkdir -p openwrt/target/linux/mediatek/filogic/base-files/lib/firmware/mediatek
cp eeprom/nx30pro_eeprom.bin openwrt/target/linux/mediatek/filogic/base-files/lib/firmware/mediatek
sed -i -e '/caldata_extract_mmc "factory" 0x0 0x1000/ a\ cp /lib/firmware/mediatek/nx30pro_eeprom.bin /lib/firmware/mediatek/mt7981_eeprom_mt7976_dbdc.bin' openwrt/target/linux/mediatek/filogic/base-files/etc/hotplug.d/firmware/11-mt76-caldata
- name: 设置 dts 闪存频率
if: env.USE_52MHZ == 'true'
run: |
sed -i -e '/bus-width = <8>;/ a\ cap-mmc-highspeed;' openwrt/target/linux/mediatek/dts/mt7981b-cmcc-rax3000m-emmc-ubootmod.dts
sed -i 's/26000000/52000000/g' openwrt/target/linux/mediatek/dts/mt7981b-cmcc-rax3000m-emmc-ubootmod.dts
grep max-frequency openwrt/target/linux/mediatek/dts/mt7981b-cmcc-rax3000m-emmc-ubootmod.dts
- name: 下载文件
run: |
cd openwrt
chmod +x $GITHUB_WORKSPACE/$CLASH_CORE && $GITHUB_WORKSPACE/$CLASH_CORE
make defconfig
make download -j8 V=10
find dl -size -1024c -exec ls -l {} \;
find dl -size -1024c -exec rm -f {} \;
- name: 编译固件中
id: compile
run: |
cd openwrt
echo -e "$(($(nproc)+1)) thread compile"
make -j$(($(nproc)+1)) || make -j$(nproc) || make -j1 V=s
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.DEVICE_NAME }}${{ env.FILE_DATE }}
path: openwrt/bin
- name: 整理文件
id: organize
if: steps.compile.outputs.status == 'success'
run: |
cd openwrt/bin/targets/*/*
rm -rf *.buildinfo
rm -rf *.json
rm -rf *.manifest
rm -rf packages
echo "FIRMWARE=$PWD" >> $GITHUB_ENV
echo "status=success" >> $GITHUB_OUTPUT
- name: 上传固件目录
uses: actions/upload-artifact@main
if: env.UPLOAD_FIRMWARE == 'true' && steps.organize.outputs.status == 'success' && !cancelled()
with:
name: OpenWrt_firmware${{ env.DEVICE_NAME }}${{ env.FILE_DATE }}
path: ${{ env.FIRMWARE }}
- name: 生成发布标签
id: tag
if: env.UPLOAD_RELEASE == 'true' && steps.compile.outputs.status == 'success' && !cancelled()
run: |
echo -e "### immortalwrt-23.05-SNAPSHOT-rax3000m-emmc-ubootmod" >> release.txt
eeprom_status=""
if [ -e openwrt/target/linux/mediatek/filogic/base-files/lib/firmware/mediatek/nx30pro_eeprom.bin ] ; then
echo "- eeprom 使用 H3C NX30 Pro 提取版本" >> release.txt
eeprom_status="nx30pro_eeprom"
else
echo "- eeprom 未修改" >> release.txt
eeprom_status="default_eeprom"
fi
max_frequency=$(($(grep -oP "max-frequency = <\K[0-9]*" openwrt/target/linux/mediatek/dts/mt7981b-cmcc-rax3000m-emmc-ubootmod.dts) / 1000000))
echo "- 使用闪存频率: ${max_frequency}MHz" >> release.txt
release_tag=$(date +"%Y.%m.%d-23.05-SNAPSHOT-rax3000m-emmc-ubootmod-${eeprom_status}-${max_frequency}MHz")
echo "release_tag=${release_tag}" >> $GITHUB_OUTPUT
echo "status=success" >> $GITHUB_OUTPUT
- name: 上传固件发布
uses: softprops/action-gh-release@v1
if: steps.tag.outputs.status == 'success' && !cancelled()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag.outputs.release_tag }}
body_path: release.txt
files: ${{ env.FIRMWARE }}/*
- name: 删除旧发布的固件
uses: dev-drprasad/delete-older-releases@v0.2.1
if: steps.compile.outputs.status == 'success' && env.UPLOAD_RELEASE == 'true' && !cancelled()
with:
keep_latest: 7
delete_tags: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: 删除过时工作流程
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
retain_days: 1
keep_minimum_runs: 3