重构 AutoBuild 代码

This commit is contained in:
Hyy2001X 2021-01-06 07:38:00 +08:00
parent ed8263e4ce
commit 33ea15d330
9 changed files with 160 additions and 155 deletions

View File

@ -6,7 +6,7 @@
# Modify: Hyy2001X
#=======================================================
name: AutoBuild-NEWIFI_D2-NIGHTLY
name: AutoBuild
on:
# release:
@ -24,12 +24,14 @@ on:
env:
REPO_URL: https://github.com/coolsnowwolf/lede
CONFIG_FILE: Configs/NEWIFI_D2-NIGHTLY.config
DIY_SCRIPT: Scripts/diy-script.sh
CONFIG_FILE: NEWIFI_D2-NIGHTLY.config
DIY_SCRIPT: Scripts/AutoBuild_DiyScript.sh
FUNCTION_SCRIPT: Scripts/AutoBuild_Function.sh
UPLOAD_RELEASE: true
UPLOAD_FIRMWARE: true
UPLOAD_BIN_DIR: false
REMOVE_OLD_RELEASE: false
REMOVE_WORKFLOW_RUNS: true
jobs:
build:
@ -51,14 +53,15 @@ jobs:
- name: Clone Openwrt source code
run: |
git clone $REPO_URL openwrt
git clone -b master $REPO_URL openwrt
ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt
- name: Run Diy-Part1 Scripts
run: |
chmod +x $DIY_SCRIPT
cd openwrt
source $GITHUB_WORKSPACE/$DIY_SCRIPT && Diy-Part1
source $GITHUB_WORKSPACE/$DIY_SCRIPT
source $GITHUB_WORKSPACE/$FUNCTION_SCRIPT && Diy-Part1
echo "Compile_Date=$(date +%Y%m%d)" > $GITHUB_WORKSPACE/Openwrt.info
echo "Display_Date=$(date +'%Y/%m/%d')" >> $GITHUB_WORKSPACE/Openwrt.info
@ -72,7 +75,8 @@ jobs:
run: |
[ -f $CONFIG_FILE ] && mv $CONFIG_FILE openwrt/.config
cd openwrt
source $GITHUB_WORKSPACE/$DIY_SCRIPT && Diy-Part2
source $GITHUB_WORKSPACE/$DIY_SCRIPT
source $GITHUB_WORKSPACE/$FUNCTION_SCRIPT && Diy-Part2
- name: Download Packages
run: |
@ -88,9 +92,10 @@ jobs:
- name: Run Diy-Part3 Scripts
run: |
echo "## $(date +"%Y%m%d")-NEWIFI_D2-NIGHTLY" > update_log.txt
echo "## $(date +"%Y%m%d")" > update_log.txt
cd openwrt
source $GITHUB_WORKSPACE/$DIY_SCRIPT && Diy-Part3
source $GITHUB_WORKSPACE/$DIY_SCRIPT
source $GITHUB_WORKSPACE/$FUNCTION_SCRIPT && Diy-Part3
echo "Artifacts_DATE=$(date +"%Y%m%d%H%M")" >> $GITHUB_ENV
- name: Upload Firmware to Artifacts
@ -125,3 +130,10 @@ jobs:
delete_tags: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Remove workflow runs
uses: GitRML/delete-workflow-runs@main
if: env.REMOVE_WORKFLOW_RUNS == 'true' && !cancelled()
with:
retain_days: 1
keep_minimum_runs: 3

View File

@ -0,0 +1,64 @@
#!/bin/bash
# https://github.com/Hyy2001X/AutoBuild-Actions
# AutoBuild Module by Hyy2001
# AutoBuild DiyScript
Diy_Core() {
Author=Hyy2001
Default_Device=d-team_newifi-d2
}
Diy-Part1() {
# [ -e feeds.conf.default ] && sed -i "s/#src-git helloworld/src-git helloworld/g" feeds.conf.default
[ ! -d package/lean ] && mkdir -p package/lean
Replace_File Scripts/AutoUpdate.sh package/base-files/files/bin
Replace_File Scripts/AutoBuild_Tools.sh package/base-files/files/bin
Replace_File Customize/mac80211.sh package/kernel/mac80211/files/lib/wifi
Replace_File Customize/system package/base-files/files/etc/config
Replace_File Customize/banner package/base-files/files/etc
# ExtraPackages svn network/services dnsmasq https://github.com/openwrt/openwrt/trunk/package/network/services
# ExtraPackages svn network/services dropbear https://github.com/openwrt/openwrt/trunk/package/network/services
# ExtraPackages svn network/services ppp https://github.com/openwrt/openwrt/trunk/package/network/services
# ExtraPackages svn network/services hostapd https://github.com/openwrt/openwrt/trunk/package/network/services
# ExtraPackages svn kernel mt76 https://github.com/openwrt/openwrt/trunk/package/kernel
ExtraPackages git lean helloworld https://github.com/fw876 master
ExtraPackages git lean luci-app-autoupdate https://github.com/Hyy2001X main
ExtraPackages git lean luci-theme-argon https://github.com/jerrykuku 18.06
ExtraPackages git other luci-app-argon-config https://github.com/jerrykuku master
ExtraPackages git other luci-app-adguardhome https://github.com/Hyy2001X master
ExtraPackages svn other luci-app-smartdns https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t
ExtraPackages svn other smartdns https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t
ExtraPackages git other OpenClash https://github.com/vernesong master
ExtraPackages git other luci-app-serverchan https://github.com/tty228 master
ExtraPackages svn other luci-app-socat https://github.com/project-openwrt/openwrt/trunk/package/lienol
}
Diy-Part2() {
GET_TARGET_INFO
Replace_File Customize/mwan3.config package/feeds/packages/mwan3/files/etc/config mwan3
sed -i 's/143/143,25,5222/' package/lean/helloworld/luci-app-ssr-plus/root/etc/init.d/shadowsocksr
# ExtraPackages svn feeds/packages mwan3 https://github.com/openwrt/packages/trunk/net
echo "Author: ${Author}"
echo "Openwrt Version: ${Openwrt_Version}"
echo "AutoUpdate Version: ${AutoUpdate_Version}"
echo "Router: ${TARGET_PROFILE}"
[ -f $Default_File ] && sed -i "s?${Lede_Version}?${Lede_Version} Compiled by ${Author} [${Display_Date}]?g" $Default_File
echo "${Openwrt_Version}" > package/base-files/files/etc/openwrt_info
sed -i "s?Openwrt?Openwrt ${Openwrt_Version} / AutoUpdate ${AutoUpdate_Version}?g" package/base-files/files/etc/banner
}
Diy-Part3() {
GET_TARGET_INFO
Default_Firmware="openwrt-${TARGET_BOARD}-${TARGET_SUBTARGET}-${TARGET_PROFILE}-squashfs-sysupgrade.bin"
AutoBuild_Firmware="AutoBuild-${TARGET_PROFILE}-Lede-${Openwrt_Version}.bin"
AutoBuild_Detail="AutoBuild-${TARGET_PROFILE}-Lede-${Openwrt_Version}.detail"
mkdir -p bin/Firmware
echo "Firmware: ${AutoBuild_Firmware}"
mv -f bin/targets/"${TARGET_BOARD}/${TARGET_SUBTARGET}/${Default_Firmware}" bin/Firmware/"${AutoBuild_Firmware}"
_MD5=$(md5sum bin/Firmware/${AutoBuild_Firmware} | cut -d ' ' -f1)
_SHA256=$(sha256sum bin/Firmware/${AutoBuild_Firmware} | cut -d ' ' -f1)
echo -e "\nMD5:${_MD5}\nSHA256:${_SHA256}" > bin/Firmware/"${AutoBuild_Detail}"
}

View File

@ -0,0 +1,75 @@
#!/bin/bash
# https://github.com/Hyy2001X/AutoBuild-Actions
# AutoBuild Module by Hyy2001
# AutoBuild Functions
GET_TARGET_INFO() {
Diy_Core
[ -f ${GITHUB_WORKSPACE}/Openwrt.info ] && . ${GITHUB_WORKSPACE}/Openwrt.info
AutoUpdate_Version=$(awk 'NR==6' package/base-files/files/bin/AutoUpdate.sh | awk -F '[="]+' '/Version/{print $2}')
[ -z ${AutoUpdate_Version} ] && AutoUpdate_Version="未知"
Default_File="package/lean/default-settings/files/zzz-default-settings"
[ -f ${Default_File} ] && Lede_Version=$(egrep -o "R[0-9]+\.[0-9]+\.[0-9]+" $Default_File)
[ -z ${Lede_Version} ] && Lede_Version="AutoBuild"
Openwrt_Version="${Lede_Version}-${Compile_Date}"
TARGET_PROFILE=$(egrep -o "CONFIG_TARGET.*DEVICE.*=y" .config | sed -r 's/.*DEVICE_(.*)=y/\1/')
[ -z "${TARGET_PROFILE}" ] && TARGET_PROFILE="${Default_Device}"
TARGET_BOARD=$(awk -F '[="]+' '/TARGET_BOARD/{print $2}' .config)
TARGET_SUBTARGET=$(awk -F '[="]+' '/TARGET_SUBTARGET/{print $2}' .config)
}
ExtraPackages() {
PKG_PROTO=${1}
PKG_DIR=${2}
PKG_NAME=${3}
REPO_URL=${4}
REPO_BRANCH=${5}
[ -d package/${PKG_DIR} ] && mkdir -p package/${PKG_DIR}
[ -d package/${PKG_DIR}/${PKG_NAME} ] && rm -rf package/${PKG_DIR}/${PKG_NAME}
[ -d ${PKG_NAME} ] && rm -rf ${PKG_NAME}
Retry_Times=3
while [ ! -f ${PKG_NAME}/Makefile ]
do
echo "[$(date "+%H:%M:%S")] Checking out package [${PKG_NAME}] to package/${PKG_DIR} ..."
case ${PKG_PROTO} in
git)
git clone -b ${REPO_BRANCH} ${REPO_URL}/${PKG_NAME} ${PKG_NAME} > /dev/null 2>&1
;;
svn)
svn checkout ${REPO_URL}/${PKG_NAME} ${PKG_NAME} > /dev/null 2>&1
esac
if [ -f ${PKG_NAME}/Makefile ] || [ -f ${PKG_NAME}/README* ];then
echo "[$(date "+%H:%M:%S")] Package [${PKG_NAME}] is detected!"
mv ${PKG_NAME} package/${PKG_DIR}
break
else
[ ${Retry_Times} -lt 1 ] && echo "[$(date "+%H:%M:%S")] Skip check out package [${PKG_NAME}] ..." && break
echo "[$(date "+%H:%M:%S")] [Error] [${Retry_Times}] Checkout failed,retry in 3s ..."
Retry_Times=$(($Retry_Times - 1))
rm -rf ${PKG_NAME} > /dev/null 2>&1
sleep 3
fi
done
}
Replace_File() {
FILE_NAME=${1}
PATCH_DIR=${GITHUB_WORKSPACE}/openwrt/${2}
FILE_RENAME=${3}
[ ! -d "${PATCH_DIR}" ] && mkdir -p ${PATCH_DIR}
[ -f "${GITHUB_WORKSPACE}/${FILE_NAME}" ] && _TYPE1="f" && _TYPE2="File"
[ -d "${GITHUB_WORKSPACE}/${FILE_NAME}" ] && _TYPE1="d" && _TYPE2="Folder"
if [ -e "${GITHUB_WORKSPACE}/${FILE_NAME}" ];then
[ ! -z "${FILE_RENAME}" ] && _RENAME="${FILE_RENAME}" || _RENAME=""
if [ -${_TYPE1} "${GITHUB_WORKSPACE}/${FILE_NAME}" ];then
echo "[$(date "+%H:%M:%S")] Move ${FILE_NAME} to ${PATCH_DIR}/${FILE_RENAME} ..."
mv -f ${GITHUB_WORKSPACE}/${FILE_NAME} ${PATCH_DIR}/${_RENAME}
else
echo "[$(date "+%H:%M:%S")] Customize ${_TYPE2} [${FILE_NAME}] is not detected,skip move ..."
fi
fi
unset _RENAME
}

View File

@ -1,7 +1,7 @@
#!/bin/bash
# https://github.com/Hyy2001X/AutoBuild-Actions
# AutoBuild Module by Hyy2001
# AutoBuild_Tools Tools for Openwrt
# AutoBuild_Tools for Openwrt
Version=V1.1-BETA

View File

@ -1,146 +0,0 @@
#!/bin/bash
# https://github.com/Hyy2001X/AutoBuild-Actions
# AutoBuild Module by Hyy2001
# AutoBuild Actions
Diy_Core() {
Author=Hyy2001
Default_Device=d-team_newifi-d2
}
Diy-Part1() {
[ -e feeds.conf.default ] && sed -i "s/#src-git helloworld/src-git helloworld/g" feeds.conf.default
[ ! -d package/lean ] && mkdir -p package/lean
Replace_File mac80211.sh package/kernel/mac80211/files/lib/wifi
Replace_File system package/base-files/files/etc/config
Replace_File AutoUpdate.sh package/base-files/files/bin
Replace_File AutoExpand.sh package/base-files/files/bin
Replace_File banner package/base-files/files/etc
ExtraPackages svn network/services dnsmasq https://github.com/openwrt/openwrt/trunk/package/network/services
ExtraPackages svn network/services dropbear https://github.com/openwrt/openwrt/trunk/package/network/services
ExtraPackages svn network/services ppp https://github.com/openwrt/openwrt/trunk/package/network/services
ExtraPackages svn network/services hostapd https://github.com/openwrt/openwrt/trunk/package/network/services
# ExtraPackages svn kernel mt76 https://github.com/openwrt/openwrt/trunk/package/kernel
ExtraPackages git lean luci-app-autoupdate https://github.com/Hyy2001X main
ExtraPackages git lean luci-theme-argon https://github.com/jerrykuku 18.06
ExtraPackages git other luci-app-argon-config https://github.com/jerrykuku master
ExtraPackages git other luci-app-adguardhome https://github.com/Hyy2001X master
ExtraPackages svn other luci-app-smartdns https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t
ExtraPackages svn other smartdns https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t
ExtraPackages git other OpenClash https://github.com/vernesong master
ExtraPackages git other luci-app-serverchan https://github.com/tty228 master
ExtraPackages svn other luci-app-socat https://github.com/project-openwrt/openwrt/trunk/package/lienol
# [UPX 压缩] ExtraPackages git other openwrt-upx https://github.com/Hyy2001X master
# [应用过滤] ExtraPackages git OAF openwrt-OpenAppFilter https://github.com/Lienol master
# [AdGuardHome 核心] ExtraPackages svn other AdGuardHome https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t
}
Diy-Part2() {
GET_TARGET_INFO
Replace_File mwan3 package/feeds/packages/mwan3/files/etc/config
sed -i 's/143/143,25,5222/' package/feeds/helloworld/luci-app-ssr-plus/root/etc/init.d/shadowsocksr
# ExtraPackages svn feeds/packages mwan3 https://github.com/openwrt/packages/trunk/net
echo "Author: $Author"
echo "Openwrt Version: $Openwrt_Version"
echo "AutoUpdate Version: $AutoUpdate_Version"
echo "Router: $TARGET_PROFILE"
sed -i "s?$Lede_Version?$Lede_Version Compiled by $Author [$Display_Date]?g" $Default_File
echo "$Openwrt_Version" > package/base-files/files/etc/openwrt_info
sed -i "s?Openwrt?Openwrt $Openwrt_Version / AutoUpdate $AutoUpdate_Version?g" package/base-files/files/etc/banner
}
Diy-Part3() {
GET_TARGET_INFO
Default_Firmware=openwrt-$TARGET_BOARD-$TARGET_SUBTARGET-$TARGET_PROFILE-squashfs-sysupgrade.bin
AutoBuild_Firmware=AutoBuild-$TARGET_PROFILE-Lede-${Openwrt_Version}.bin
AutoBuild_Detail=AutoBuild-$TARGET_PROFILE-Lede-${Openwrt_Version}.detail
mkdir -p bin/Firmware
echo "Firmware: $AutoBuild_Firmware"
mv bin/targets/$TARGET_BOARD/$TARGET_SUBTARGET/$Default_Firmware bin/Firmware/$AutoBuild_Firmware
echo "[$(date "+%H:%M:%S")] Calculating MD5 and SHA256 ..."
Firmware_MD5=$(md5sum bin/Firmware/$AutoBuild_Firmware | cut -d ' ' -f1)
Firmware_SHA256=$(sha256sum bin/Firmware/$AutoBuild_Firmware | cut -d ' ' -f1)
echo -e "MD5: $Firmware_MD5\nSHA256: $Firmware_SHA256"
touch bin/Firmware/$AutoBuild_Detail
echo -e "\nMD5:$Firmware_MD5\nSHA256:$Firmware_SHA256" >> bin/Firmware/$AutoBuild_Detail
}
GET_TARGET_INFO() {
Diy_Core
[ -e $GITHUB_WORKSPACE/Openwrt.info ] && . $GITHUB_WORKSPACE/Openwrt.info
AutoUpdate_Version=$(awk 'NR==6' package/base-files/files/bin/AutoUpdate.sh | awk -F '[="]+' '/Version/{print $2}')
Default_File="package/lean/default-settings/files/zzz-default-settings"
Lede_Version=$(egrep -o "R[0-9]+\.[0-9]+\.[0-9]+" $Default_File)
Openwrt_Version="$Lede_Version-$Compile_Date"
TARGET_PROFILE=$(egrep -o "CONFIG_TARGET.*DEVICE.*=y" .config | sed -r 's/.*DEVICE_(.*)=y/\1/')
[ -z "$TARGET_PROFILE" ] && TARGET_PROFILE="$Default_Device"
TARGET_BOARD=$(awk -F '[="]+' '/TARGET_BOARD/{print $2}' .config)
TARGET_SUBTARGET=$(awk -F '[="]+' '/TARGET_SUBTARGET/{print $2}' .config)
}
ExtraPackages() {
PKG_PROTO=$1
PKG_DIR=$2
PKG_NAME=$3
REPO_URL=$4
REPO_BRANCH=$5
[ -d package/$PKG_DIR ] && mkdir -p package/$PKG_DIR
[ -d package/$PKG_DIR/$PKG_NAME ] && rm -rf package/$PKG_DIR/$PKG_NAME
[ -d $PKG_NAME ] && rm -rf $PKG_NAME
Retry_Times=3
while [ ! -e $PKG_NAME/Makefile ]
do
echo "[$(date "+%H:%M:%S")] Checking out package [$PKG_NAME] ..."
case $PKG_PROTO in
git)
git clone -b $REPO_BRANCH $REPO_URL/$PKG_NAME $PKG_NAME > /dev/null 2>&1
;;
svn)
svn checkout $REPO_URL/$PKG_NAME $PKG_NAME > /dev/null 2>&1
esac
if [ -e $PKG_NAME/Makefile ] || [ -e $PKG_NAME/README* ];then
echo "[$(date "+%H:%M:%S")] Package [$PKG_NAME] is detected!"
mv $PKG_NAME package/$PKG_DIR
break
else
[ $Retry_Times -lt 1 ] && echo "[$(date "+%H:%M:%S")] Skip check out package [$PKG_NAME] ..." && break
echo "[$(date "+%H:%M:%S")] [Error] [$Retry_Times] Checkout failed,retry in 3s ..."
Retry_Times=$(($Retry_Times - 1))
rm -rf $PKG_NAME > /dev/null 2>&1
sleep 3
fi
done
}
Replace_File() {
FILE_NAME=$1
PATCH_DIR=$GITHUB_WORKSPACE/openwrt/$2
FILE_RENAME=$3
[ ! -d $PATCH_DIR ] && mkdir -p $PATCH_DIR
if [ -f $GITHUB_WORKSPACE/Customize/$FILE_NAME ];then
if [ -e $GITHUB_WORKSPACE/Customize/$FILE_NAME ];then
echo "[$(date "+%H:%M:%S")] Customize File [$FILE_NAME] is detected!"
if [ -z $FILE_RENAME ];then
[ -e $PATCH_DIR/$FILE_NAME ] && rm -f $PATCH_DIR/$FILE_NAME
mv -f $GITHUB_WORKSPACE/Customize/$FILE_NAME $PATCH_DIR/$1
else
[ -e $PATCH_DIR/$FILE_NAME ] && rm -f $PATCH_DIR/$3
mv -f $GITHUB_WORKSPACE/Customize/$FILE_NAME $PATCH_DIR/$3
fi
else
echo "[$(date "+%H:%M:%S")] Customize File [$FILE_NAME] is not detected,skip move ..."
fi
else
if [ -d $GITHUB_WORKSPACE/Customize/$FILE_NAME ];then
echo "[$(date "+%H:%M:%S")] Customize Folder [$FILE_NAME] is detected !"
mv -f $GITHUB_WORKSPACE/Customize/$FILE_NAME $PATCH_DIR
else
echo "[$(date "+%H:%M:%S")] Customize Folder [$FILE_NAME] is not detected,skip move ..."
fi
fi
}