编译 OpenWrt 固件 #573
This file contains hidden or 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
| name: 编译 OpenWrt 固件 | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'build/Tianling_source/start-up/start' | |
| schedule: | |
| - cron: 0 17 * * 5 | |
| env: | |
| Github: https://github.com/${{github.repository}} | |
| Author: ${{github.actor}} | |
| Apidz: ${{github.repository}} | |
| Run_number: ${{github.run_number}} | |
| Run_workflow: ${{github.workflow}} | |
| REPO_TOKEN: ${{ secrets.REPO_TOKEN }} | |
| TZ: Asia/Shanghai | |
| jobs: | |
| build: | |
| runs-on: ubuntu-22.04 | |
| if: github.event.repository.owner.id == github.event.sender.id | |
| name: 编译 "${{matrix.target}}" | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| target: [Lede_source] | |
| # [Lede_source,Lienol_source,Mortal_source,Tianling_source,openwrt_amlogic] | |
| steps: | |
| - name: 准备结束 | |
| uses: actions/checkout@v4 | |
| - name: 读取设置 | |
| run: | | |
| source "${GITHUB_WORKSPACE}/build/${{matrix.target}}/settings.ini" | |
| echo "REPO_URL=${REPO_URL}" >> $GITHUB_ENV | |
| echo "REPO_BRANCH=${REPO_BRANCH}" >> $GITHUB_ENV | |
| echo "CONFIG_FILE=${CONFIG_FILE}" >> $GITHUB_ENV | |
| echo "DIY_PART_SH=${DIY_PART_SH}" >> $GITHUB_ENV | |
| echo "SSH_ACTIONS=${SSH_ACTIONS}" >> $GITHUB_ENV | |
| echo "UPLOAD_BIN_DIR=${UPLOAD_BIN_DIR}" >> $GITHUB_ENV | |
| echo "UPLOAD_CONFIG=${UPLOAD_CONFIG}" >> $GITHUB_ENV | |
| echo "UPLOAD_FIRMWARE=${UPLOAD_FIRMWARE}" >> $GITHUB_ENV | |
| echo "UPLOAD_RELEASE=${UPLOAD_RELEASE}" >> $GITHUB_ENV | |
| echo "SERVERCHAN_SCKEY=${SERVERCHAN_SCKEY}" >> $GITHUB_ENV | |
| echo "REGULAR_UPDATE=${REGULAR_UPDATE}" >> $GITHUB_ENV | |
| echo "USE_CACHEWRTBUILD=${USE_CACHEWRTBUILD}" >> $GITHUB_ENV | |
| echo "BY_INFORMATION=${BY_INFORMATION}" >> $GITHUB_ENV | |
| echo "AUTOMATIC_AMLOGIC=${AUTOMATIC_AMLOGIC}" >> $GITHUB_ENV | |
| echo "CangKu=${Apidz##*/}" >> $GITHUB_ENV | |
| echo "Modelfile=${{matrix.target}}" >> $GITHUB_ENV | |
| - name: 初始化 | |
| run: | | |
| chmod -R +x "${GITHUB_WORKSPACE}/build/common" | |
| if [[ "${REPO_BRANCH}" == "master" ]]; then | |
| echo "ZZZ=package/lean/default-settings/files/zzz-default-settings" >> $GITHUB_ENV | |
| echo "CODE=Lede" >> $GITHUB_ENV | |
| echo "OpenWrt_name=18.06" >> $GITHUB_ENV | |
| elif [[ "${REPO_BRANCH}" == "19.07" ]]; then | |
| echo "ZZZ=package/default-settings/files/zzz-default-settings" >> $GITHUB_ENV | |
| echo "CODE=Lienol" >> $GITHUB_ENV | |
| echo "OpenWrt_name=19.07" >> $GITHUB_ENV | |
| elif [[ "${REPO_BRANCH}" == "openwrt-18.06" ]]; then | |
| echo "ZZZ=package/emortal/default-settings/files/zzz-default-settings" >> $GITHUB_ENV | |
| echo "CODE=Mortal" >> $GITHUB_ENV | |
| echo "OpenWrt_name=18.06" >> $GITHUB_ENV | |
| fi | |
| echo "NETIP=package/base-files/files/etc/networkip" >> $GITHUB_ENV | |
| echo "DELETE=package/base-files/files/etc/deletefile" >> $GITHUB_ENV | |
| - name: 释放空间 | |
| run: | | |
| sudo rm -rf /etc/apt/sources.list.d | |
| sudo bash -c "curl -s https://us.cooluc.com/ubuntu-apt/sources-22.04.list > /etc/apt/sources.list" | |
| sudo swapoff -a | |
| sudo rm -f /swapfile /mnt/swapfile | |
| sudo docker image prune -a -f | |
| sudo systemctl stop docker | |
| sudo snap set system refresh.retain=2 | |
| sudo apt-get -y purge firefox clang* ghc* google* llvm* mono* mongo* mysql* php* | |
| sudo apt-get -y autoremove --purge | |
| sudo apt-get clean | |
| sudo rm -rf /etc/mysql /etc/php /usr/lib/jvm /usr/libexec/docker /usr/local /usr/src/* /var/lib/docker /var/lib/gems /var/lib/mysql /var/lib/snapd /etc/skel /opt/{microsoft,az,hostedtoolcache,cni,mssql-tools,pipx} /usr/share/{az*,dotnet,swift,miniconda,gradle*,java,kotlinc,ri,sbt} /root/{.sbt,.local,.npm} | |
| sudo sed -i '/NVM_DIR/d;/skel/d' /root/{.bashrc,.profile} | |
| rm -rf ~/{.cargo,.dotnet,.rustup} | |
| df -Th | |
| - name: 部署环境 | |
| env: | |
| DEBIAN_FRONTEND: noninteractive | |
| run: | | |
| sudo sh -c 'echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-17 main" >> /etc/apt/sources.list' | |
| sudo sh -c 'echo "deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-17 main" >> /etc/apt/sources.list' | |
| wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - | |
| sudo apt-get update | |
| sudo apt-get install -y ack antlr3 asciidoc autoconf automake autopoint binutils bison build-essential bzip2 ccache cmake cpio curl device-tree-compiler ecj fakeroot fastjar flex gawk gettext genisoimage git gnutls-dev gperf haveged help2man intltool irqbalance jq libc6-dev-i386 libelf-dev libglib2.0-dev libgmp3-dev libltdl-dev libmpc-dev libmpfr-dev libncurses-dev libreadline-dev libssl-dev libtool libyaml-dev libz-dev lrzsz msmtp nano ninja-build p7zip p7zip-full patch pkgconf libpython3-dev python3 python3-pip python3-cryptography python3-docutils python3-ply python3-pyelftools python3-requests qemu-utils quilt re2c rsync rename scons sharutils squashfs-tools subversion swig texinfo uglifyjs unzip vim wget xmlto zlib1g-dev zstd xxd | |
| sudo apt-get clean | |
| echo "=================================================" | |
| echo "文件系统 类型 容量 已用 可用 使用% 挂载点" | |
| df -hT $PWD | |
| sudo timedatectl set-timezone "$TZ" | |
| sudo mkdir -p /${{matrix.target}} | |
| sudo chown $USER:$GROUPS /${{matrix.target}} | |
| - name: 下载源码 | |
| working-directory: /${{matrix.target}} | |
| run: | | |
| git clone -b "$REPO_BRANCH" --single-branch "$REPO_URL" openwrt | |
| cd openwrt | |
| ./scripts/feeds update -a > /dev/null 2>&1 | |
| ln -sf /${{matrix.target}}/openwrt $GITHUB_WORKSPACE/openwrt | |
| echo "Home=${GITHUB_WORKSPACE}/openwrt" >> $GITHUB_ENV | |
| echo "PATH1=${GITHUB_WORKSPACE}/openwrt/build/${{matrix.target}}" >> $GITHUB_ENV | |
| - name: 加载设置 | |
| run: | | |
| echo "Compile_Date=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV | |
| cp -Rf `find ./ -maxdepth 1 -type d ! -path './openwrt' ! -path './'` openwrt | |
| mv -f "${Home}"/build/common/*.sh "${PATH1}" | |
| source "${PATH1}/common.sh" && Diy_settings | |
| [[ "${{ github.event.inputs.ssh }}" == 'ssh' ]] && echo "SSHYC=true" >> $GITHUB_ENV | |
| cd openwrt | |
| if [[ "${REPO_BRANCH}" == "master" ]]; then | |
| source "${PATH1}/common.sh" && Diy_lede | |
| elif [[ "${REPO_BRANCH}" == "19.07" ]]; then | |
| source "${PATH1}/common.sh" && Diy_lienol | |
| elif [[ "${REPO_BRANCH}" == "openwrt-18.06" ]]; then | |
| source "${PATH1}/common.sh" && Diy_Tianling | |
| elif [[ "${REPO_BRANCH}" == "openwrt-21.02" ]]; then | |
| source "${PATH1}/common.sh" && Diy_mortal | |
| fi | |
| source "${PATH1}/common.sh" && Diy_all | |
| /bin/bash "${PATH1}/$DIY_PART_SH" | |
| ./scripts/feeds update -a | |
| ./scripts/feeds install -a > /dev/null 2>&1 | |
| ./scripts/feeds install -a | |
| mv "$PATH1/$CONFIG_FILE" .config | |
| if [[ "${REGULAR_UPDATE}" == "true" ]]; then | |
| source "${PATH1}/upgrade.sh" && Diy_Part1 | |
| fi | |
| - name: 生成配置 | |
| run: | | |
| cd openwrt | |
| source "${PATH1}/common.sh" && Diy_chajian > /dev/null 2>&1 | |
| make defconfig > /dev/null 2>&1 | |
| ./scripts/diffconfig.sh > ${GITHUB_WORKSPACE}/config.txt | |
| echo "TARGET_BOARD=$(awk -F '[="]+' '/TARGET_BOARD/{print $2}' .config)" >> $GITHUB_ENV | |
| echo "TARGET_SUBTARGET=$(awk -F '[="]+' '/TARGET_SUBTARGET/{print $2}' .config)" >> $GITHUB_ENV | |
| if [ `grep -c "CONFIG_TARGET_x86_64=y" .config` -eq '1' ]; then | |
| echo "TARGET_PROFILE=x86-64" >> $GITHUB_ENV | |
| elif [ `grep -c "CONFIG_TARGET_x86_generic=y" .config` -eq '1' ]; then | |
| echo "TARGET_PROFILE=x86-32" >> $GITHUB_ENV | |
| elif [ `grep -c "CONFIG_TARGET.*DEVICE.*=y" .config` -eq '1' ]; then | |
| grep '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/.*DEVICE_(.*)=y/\1/' > DEVICE_NAME | |
| [ -s DEVICE_NAME ] && echo "TARGET_PROFILE=$(cat DEVICE_NAME)" >> $GITHUB_ENV | |
| else | |
| echo "TARGET_PROFILE=armvirt" >> $GITHUB_ENV | |
| fi | |
| - name: 编译信息 | |
| run: | | |
| cd openwrt | |
| source "${PATH1}/common.sh" && Diy_chuli > /dev/null 2>&1 | |
| if [ "${REGULAR_UPDATE}" == "true" ]; then | |
| source "${PATH1}/upgrade.sh" && Diy_Part2 > /dev/null 2>&1 | |
| fi | |
| if [ "${BY_INFORMATION}" == "true" ]; then | |
| source "${PATH1}/upgrade.sh" && GET_TARGET_INFO | |
| source "${PATH1}/common.sh" && Diy_xinxi | |
| chmod -R 755 . | |
| fi | |
| - name: 电报通知 | |
| if: env.SERVERCHAN_SCKEY == 'true' | |
| run: | | |
| 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)" | |
| curl -k --data chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" --data "text=🔔 您正在使用【${CPUNAME} CPU】【${CPUCORES}核心】【${CODE}】源码 编译固件中,请耐心等待...... ⏳" "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" | |
| - name: 加载缓存 | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ${{ github.workspace }}/openwrt | |
| key: ${{ runner.os }}-openwrt-${{ hashFiles('**/openwrt/Makefile') }} | |
| restore-keys: | | |
| ${{ runner.os }}-openwrt- | |
| - name: 下载dl库 | |
| id: package | |
| run: | | |
| cd openwrt | |
| make download -j8 | |
| 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 "status=success" >> $GITHUB_ENV | |
| echo "date=$(date "+%Y%m%d%H%M%S")" >> $GITHUB_ENV | |
| echo "date1=$(date +'%m-%d')" >> $GITHUB_ENV | |
| - name: 上传配置 | |
| if: env.UPLOAD_CONFIG == 'true' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: .config_${{ env.CODE }}_${{ env.TARGET_PROFILE }}_${{ env.Compile_Date }} | |
| path: config.txt | |
| - name: 上传文件 | |
| if: env.status == 'success' && env.UPLOAD_BIN_DIR == 'true' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: filename+ipk_${{ env.CODE }}_${{ env.TARGET_PROFILE }}_${{ env.Compile_Date }} | |
| path: openwrt/bin | |
| - name: 整理文件 | |
| id: organizer | |
| run: | | |
| if [ "${AUTOMATIC_AMLOGIC}" == "true" ]; then | |
| source "${PATH1}/common.sh" && Diy_amlogic | |
| fi | |
| cd openwrt | |
| echo "文件系统 类型 容量 已用 可用 使用% 挂载点" | |
| df -hT $PWD | |
| cp -Rf bin/targets/*/* "${Home}"/upgrade | |
| cd bin/targets/*/* | |
| find . \( -name "*buildinfo*" -o -name "*sha256sums*" -o -name "*manifest*" -o -name "*vmlinuz*" -o -name "*Image*" -o -name "*rootfs.img.gz*" -o -name "*kernel.bin*" \) -exec rm -rf {} + | |
| rm -rf packages | |
| rename -v "s/^openwrt/${{ env.date1 }}-${{ env.CODE }}/" * | |
| echo "FIRMWARE=$PWD" >> $GITHUB_ENV | |
| echo "BOT=TRUE" >> $GITHUB_ENV | |
| echo "status=success" >> $GITHUB_ENV | |
| - name: 上传固件 | |
| if: env.status == 'success' && env.UPLOAD_FIRMWARE == 'true' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.OpenWrt_name }}-${{ env.CODE }}-${{ env.TARGET_PROFILE }}-firmware-${{ env.Compile_Date }} | |
| path: ${{ env.FIRMWARE }} | |
| - name: 发布信息 | |
| if: env.status == 'success' && env.UPLOAD_RELEASE == 'true' | |
| run: | | |
| echo "### $(date +"%Y年%m月%d号-%H点%M分")" > update_log.txt | |
| curl -fsSL git.io/file-transfer | sh | |
| ./transfer cow --block 2621440 -s -p 64 --no-progress ${FIRMWARE} 2>&1 | tee cowtransfer.log | |
| echo "##### 奶牛快传:$(cat cowtransfer.log | grep https | cut -f3 -d" ")" >> update_log.txt | |
| ./transfer wet -s -p 16 --no-progress ${FIRMWARE} 2>&1 | tee wetransfer.log | |
| echo "##### WETRANSFER:$(cat wetransfer.log | grep https | cut -f3 -d" ")" >> update_log.txt | |
| - name: 发布固件 | |
| if: env.status == 'success' && env.UPLOAD_RELEASE == 'true' && env.REPO_TOKEN | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| name: ${{ env.CODE }}-${{ env.TARGET_PROFILE }} | |
| tag: ${{ env.date }} | |
| token: ${{ secrets.REPO_TOKEN }} | |
| bodyFile: "update_log.txt" | |
| artifacts: "${{ env.FIRMWARE }}/*" | |
| - name: 云端更新1 | |
| if: env.status == 'success' && env.REGULAR_UPDATE == 'true' | |
| run: | | |
| cd openwrt | |
| source "${PATH1}/upgrade.sh" && Diy_Part3 | |
| - name: 云端更新2 | |
| if: env.status == 'success' && env.REGULAR_UPDATE == 'true' && env.REPO_TOKEN | |
| uses: svenstaro/upload-release-action@v2 | |
| with: | |
| repo_token: ${{ secrets.REPO_TOKEN }} | |
| file: openwrt/bin/Firmware/* | |
| tag: AutoUpdate | |
| overwrite: true | |
| file_glob: true | |
| - name: 云端更新3 | |
| if: env.status == 'success' && env.REGULAR_UPDATE == 'true' | |
| run: | | |
| mkdir -p Github_Tags | |
| cd Github_Tags | |
| wget -q --no-cookie --no-check-certificate https://api.github.com/repos/${{github.repository}}/releases/tags/AutoUpdate -O Github_Tags | |
| - name: 云端更新4 | |
| if: env.status == 'success' && env.REGULAR_UPDATE == 'true' && env.REPO_TOKEN | |
| uses: svenstaro/upload-release-action@v2 | |
| with: | |
| repo_token: ${{ secrets.REPO_TOKEN }} | |
| file: Github_Tags/* | |
| tag: AutoUpdate | |
| overwrite: true | |
| file_glob: true | |
| - name: 电报通知 | |
| if: env.status == 'success' && env.SERVERCHAN_SCKEY == 'true' | |
| run: | | |
| curl -k --data chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" --data "text=我亲爱的✨主人✨:您使用【${{matrix.target}}】文件夹编译的[${{ env.CODE }}-${{ env.TARGET_PROFILE }}]固件(${{env.CangKu}}仓库的#${{env.Run_number}}号)顺利编译完成了!💐" "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" |