Skip to content

Openwrt.org Source Code Update #91

Openwrt.org Source Code Update

Openwrt.org Source Code Update #91

#
# 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.org for XIAOMI_R4 FULL
on:
repository_dispatch:
types: Openwrt.org Source Code Update
workflow_dispatch:
inputs:
ssh:
description: 'SSH connection to Actions'
required: false
default: 'false'
# repo_url:
# description: 'The URL of the source code repository'
# required: true
# default: https://github.com/openwrt/openwrt
push:
branches:
- master
# schedule:
# - cron: 0 20 * * *
env:
REPO_URL: https://github.com/openwrt/openwrt
REPO_BRANCH: openwrt-23.05
FEEDS_CONF: feeds.conf.default
CONFIG_FILE: config_for_OpenWrt_org
DIY_P1_SH: diy-part1.sh
DIY_P2_SH: diy-part2.sh
UPLOAD_BIN_DIR: true
UPLOAD_FIRMWARE: true
UPLOAD_COWTRANSFER: false
UPLOAD_WETRANSFER: false
UPLOAD_RELEASE: true
TZ: Asia/Shanghai
jobs:
build:
runs-on: ubuntu-20.04
steps:
# - name: Check Repo URL
# run: |
# if [ "${{ github.event.inputs.repo_url }}" != "${{ env.REPO_URL }}" ]; then # 检查传入的源码仓库URL是否与该工作流文件对应的源码仓库URL匹配
# echo "The source code repository URL does not match. Skipping build."
# exit 1
# fi
- name: Maximize build space
uses: easimon/maximize-build-space@master
with:
root-reserve-mb: 10240
# temp-reserve-mb: 150
# swap-size-mb: 1024
remove-dotnet: 'true'
remove-android: 'true'
remove-haskell: 'true'
remove-codeql: 'true'
remove-docker-images: 'true'
- name: Checkout
uses: actions/checkout@main
- name: Initialization environment
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc
sudo -E apt-get -y purge azure-cli* docker* ghc* zulu* hhvm* llvm* firefox* google* dotnet* aspnetcore* powershell* openjdk* adoptopenjdk* mysql* php* mongodb* moby* snap* || true
sudo -E apt-get -qq update
sudo -E apt-get -qq install $(curl -fsSL git.io/depends-ubuntu-2004)
sudo apt -y install gcc g++ build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch flex bison make autoconf texinfo unzip sharutils subversion ncurses-term zlib1g-dev ccache upx lib32gcc-s1 libc6-dev-i386 uglifyjs git-core gcc-multilib p7zip p7zip-full msmtp libssl-dev libglib2.0-dev xmlto qemu-utils automake libtool libcrypto++-dev qtbase5-dev qtbase5-dev-tools qtchooser qt5-qmake qtbase5-private-dev libqt5sql5 libqt5sql5-mysql libqt5sql5-odbc libqt5sql5-psql libqt5sql5-sqlite libqt5sql5-tds qttools5-dev-tools
sudo -E apt-get -qq autoremove --purge
sudo -E apt-get -qq clean
sudo timedatectl set-timezone "$TZ"
sudo mkdir -p /workdir/openwrt
sudo chown -R $USER:$GROUPS /workdir/openwrt
- name: Clone source code
working-directory: ${{ github.workspace }}
run: |
df -hT $PWD
git clone $REPO_URL -b $REPO_BRANCH openwrt
ln -sf /workdir/openwrt $GITHUB_WORKSPACE/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 and Install feeds
run: cd openwrt && ./scripts/feeds update -a && ./scripts/feeds install -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
- 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: Check space usage after download
if: (!cancelled())
run: df -hT
- 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: Modify overclocking settings
# run: |
# cd openwrt
# #超频5.10内核至1000Mhz
# mv target/linux/ramips/patches-5.10/322-mt7621-fix-cpu-clk-add-clkdev.patch ./322-mt7621-fix-cpu-clk-add-clkdev.patch.bak
# wget -O target/linux/ramips/patches-5.10/322-mt7621-fix-cpu-clk-add-clkdev.patch https://raw.githubusercontent.com/Fatty911/AutoBuild_OpenWRT_for_Mi_R4/main/mt7621_overclocking-322-mt7621-fix-cpu-clk-add-clkdev.patch
- name: Compile the firmware
id: compile
run: |
#开始编译
cd openwrt
echo -e "$(nproc) thread compile"
make -j$(nproc) || make -j1 || make -j1 V=s && df -hT || sed -i 's/--set=llvm.download-ci-llvm=true/--set=llvm.download-ci-llvm=false/g' $GITHUB_WORKSPACE/openwrt/feeds/packages/lang/rust/Makefile && make -j1 V=s && df -hT|| sed -i 's/DEPENDS:=\(.*\)/DEPENDS:=\1 +libiconv/g' $GITHUB_WORKSPACE/openwrt/package/libs/gettext-full/Makefile && make -j1 V=s && df -hT
echo "status=success" >> $GITHUB_OUTPUT
# KERNEL_VERSION=$(cat bin/targets/*/version.buildinfo | grep 'kernel_version' | cut -d'=' -f2)
# echo "kernel_version=$KERNEL_VERSION" >> $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
TARGET_BOARD=$(grep '^CONFIG_TARGET_BOARD=' .config | sed -r 's/.*="(.*)"/\1/')
echo "检测TARGET_BOARD是否在.config中成功找到:$TARGET_BOARD"
echo "TARGET_BOARD=$TARGET_BOARD" >> $GITHUB_ENV
TARGET_SUBTARGET=$(grep '^CONFIG_TARGET_SUBTARGET=' .config | sed -r 's/.*="(.*)"/\1/')
echo "检测TARGET_SUBTARGET是否在.config中成功找到:$TARGET_SUBTARGET"
echo "TARGET_SUBTARGET=$TARGET_SUBTARGET" >> $GITHUB_ENV
TARGET_PROFILE=$(grep '^CONFIG_TARGET_PROFILE=' .config | sed -r 's/.*="(.*)"/\1/' | sed 's/^DEVICE_//')
echo "检测TARGET_PROFILE是否在.config中成功找到:$TARGET_PROFILE"
echo "TARGET_PROFILE=$TARGET_PROFILE" >> $GITHUB_ENV
echo "DEVICE_NAME=$TARGET_PROFILE" >> $GITHUB_ENV
KERNEL_VERSION=$(ls build_dir/target-*_*/linux-*/ | grep -oP 'linux-\K\d+\.\d+\.\d+')
echo "检查是否获取到内核版本号:$KERNEL_VERSION"
echo "kernel_version=$KERNEL_VERSION" >> $GITHUB_ENV
- name: Rename
run: |
cd openwrt/bin/targets/${{ env.TARGET_BOARD }}/${{ env.TARGET_SUBTARGET }}
echo "进入文件夹:$(pwd)"
for file in openwrt-${{ env.TARGET_BOARD }}-${{ env.TARGET_SUBTARGET }}-${{ env.TARGET_PROFILE}}-*; do
if [ -f "$file" ]; then
new_file="openwrt_org_${{ env.TARGET_BOARD }}_${{ env.TARGET_SUBTARGET }}_${{ env.TARGET_PROFILE}}_Kernel_${{ env.kernel_version }}_${{ env.FILE_DATE }}${file#*${{ env.TARGET_PROFILE}}}"
mv "$file" "$new_file"
echo "Renamed $file to $new_file"
fi
done
- name: Check space usage after compile
if: (!cancelled())
run: df -hT
- name: Upload bin directory
uses: actions/upload-artifact@master
if: steps.compile.outputs.status == 'success' && env.UPLOAD_BIN_DIR == 'true'
with:
name: OpenWrt.org_bin${{ env.DEVICE_NAME }}_Kernel_${{ env.kernel_version }}_${{ env.FILE_DATE }}
path: |
openwrt/bin
openwrt/.config
- name: Organize files
id: organize
if: env.UPLOAD_FIRMWARE == 'true' && !cancelled()
run: |
cd openwrt/bin/targets/*/*
rm -rf packages
echo "firmware_path=$(pwd)" >> $GITHUB_ENV
echo "status=success" >> $GITHUB_OUTPUT
- name: Upload firmware directory
uses: actions/upload-artifact@master
if: steps.organize.outputs.status == 'success' && !cancelled()
with:
name: OpenWrt.org_firmware_${{ env.DEVICE_NAME }}_Kernel_${{ env.kernel_version }}_${{ env.FILE_DATE }}
path: ${{ env.firmware_path }}
- name: Upload firmware to cowtransfer
id: cowtransfer
if: steps.organize.outputs.status == 'success' && env.UPLOAD_COWTRANSFER == 'true' && !cancelled()
run: |
curl -fsSL git.io/file-transfer | sh
./transfer cow --block 2621440 -s -p 64 --no-progress ${FIRMWARE} 2>&1 | tee cowtransfer.log
echo "::warning file=cowtransfer.com::$(cat cowtransfer.log | grep https)"
#echo "::set-output name=url::$(cat cowtransfer.log | grep https | cut -f3 -d" ")"
echo "url=$(cat cowtransfer.log | grep https | cut -f3 -d" ")" >> $GITHUB_OUTPUT
- name: Upload firmware to WeTransfer
id: wetransfer
if: steps.organize.outputs.status == 'success' && env.UPLOAD_WETRANSFER == 'true'
run: |
curl -fsSL git.io/file-transfer | sh
./transfer wet -s -p 16 --no-progress ${FIRMWARE} 2>&1 | tee wetransfer.log
echo "::warning file=wetransfer.com::$(cat wetransfer.log | grep https)"
#echo "::set-output name=url::$(cat wetransfer.log | grep https | cut -f3 -d" ")"
echo "url=$(cat wetransfer.log | grep https | cut -f3 -d" ")" >> $GITHUB_OUTPUT
- name: Generate release tag
id: generate_release_tag
if: env.UPLOAD_RELEASE == 'true' && !cancelled()
run: |
echo "release_tag=${{ env.DEVICE_NAME }}_Kernel_${{ env.kernel_version }}_$(date +"%Y.%m.%d-%H%M")" >> $GITHUB_OUTPUT
touch release.txt
[ $UPLOAD_COWTRANSFER = true ] && echo "🔗 [Cowtransfer](${{ steps.cowtransfer.outputs.url }})" >> release.txt
[ $UPLOAD_WETRANSFER = true ] && echo "🔗 [WeTransfer](${{ steps.wetransfer.outputs.url }})" >> release.txt
echo "release_tag_status=success" >> $GITHUB_OUTPUT
echo "release_tag_status: ${{steps.generate_release_tag.outputs.release_tag_status}}"
- name: Upload firmware to release
uses: softprops/action-gh-release@master
if: steps.generate_release_tag.outputs.release_tag_status == 'success' && env.UPLOAD_RELEASE == 'true'
env:
GITHUB_TOKEN: ${{ secrets.ACTIONS_TRIGGER_PAT }}
with:
token: ${{ secrets.ACTIONS_TRIGGER_PAT }}
files: |
${{ env.firmware_path }}/*
openwrt/.config
name: OpenWRT.org_${{ steps.generate_release_tag.outputs.release_tag }}
tag_name: OpenWRT.org_${{ steps.generate_release_tag.outputs.release_tag }}
- name: Delete workflow runs
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ secrets.ACTIONS_TRIGGER_PAT }}
repository: ${{ github.repository }}
retain_days: 10
keep_minimum_runs: 2
- name: Delete Older Releases
uses: dev-drprasad/delete-older-releases@master
with:
#repo: <owner>/<repoName> # defaults to current repo
keep_latest: 5
#delete_tag_pattern: beta # defaults to ""
env:
GITHUB_TOKEN: ${{ secrets.ACTIONS_TRIGGER_PAT }}