Skip to content

OpenWrt Builder

OpenWrt Builder #50

#
# https://github.com/P3TERX/Actions-OpenWrt
#
# File: .github/workflows/openwrt-bulder.yml
# Description: Build OpenWrt using GitHub Actions
#
# Copyright (c) 2019-2024 P3TERX <https://p3terx.com>
#
# This is free software, licensed under the MIT License.
# See /LICENSE for more information.
#
name: OpenWrt Builder
on:
repository_dispatch:
workflow_dispatch:
env:
REPO_URL: https://git.openwrt.org/openwrt/openwrt.git
REPO_BRANCH: openwrt-23.05
FEEDS_CONF: feeds.conf.default
CONFIG_FILE: .config
DIY_P1_SH: diy-part1.sh
DIY_P2_SH: diy-part2.sh
UPLOAD_BIN_DIR: false
UPLOAD_FIRMWARE: true
UPLOAD_RELEASE: true
TZ: Asia/Shanghai
jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- 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 /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force
sudo -E apt-get -qq update
sudo -E apt-get -qq install build-essential clang flex bison g++ gawk \
gcc-multilib g++-multilib gettext git libncurses5-dev libssl-dev \
python3-distutils rsync unzip zlib1g-dev file wget
sudo -E apt-get -qq autoremove --purge
sudo -E apt-get -qq clean
sudo timedatectl set-timezone "$TZ"
sudo mkdir -p /workdir
sudo chown $USER:$GROUPS /workdir
- name: Clone source code
working-directory: /workdir
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
git config --global user.email "noreply@github.com"
git config --global user.name "GitHub Actions"
$GITHUB_WORKSPACE/$DIY_P1_SH
- name: Update feeds
run: |
cd openwrt && ./scripts/feeds update -a
version_greater_equal()
{
printf '%s\n%s\n' "$2" "$1" | sort -V -C
}
packages='sing-box'
version_head='PKG_VERSION:='
hash_head='PKG_HASH:='
release_api_command=$(curl -sL "https://api.github.com/repos/SagerNet/sing-box/releases" | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//')
release_download_url='https://codeload.github.com/SagerNet/sing-box/tar.gz/v'
Old_PKG_VERSION=$(sed -n "/^$version_head/p" feeds/packages/net/sing-box/Makefile | awk -F '=' '{print $2}')
New_PKG_VERSION=$release_api_command
echo "$packages目前版本: $Old_PKG_VERSION"
echo "$packages最新版本: $New_PKG_VERSION"
version_greater_equal "$Old_PKG_VERSION" "$New_PKG_VERSION" && echo "$packages版本为最新版本$Old_PKG_VERSION,无需更新" || (PKG_HASH=$(wget -qO - $release_download_url$New_PKG_VERSION | tee file | sha256sum | awk '{print $1}') && sed -i -e "/^$version_head/c$version_head$New_PKG_VERSION" -e "/^$hash_head/c$hash_head$PKG_HASH" feeds/packages/net/sing-box/Makefile && echo "已更新$packages版本到: $New_PKG_VERSION")
packages='xray-core'
version_head='PKG_VERSION:='
hash_head='PKG_HASH:='
release_api_command=$(curl -sL "https://api.github.com/repos/XTLS/Xray-core/releases" | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//')
release_download_url='https://codeload.github.com/XTLS/Xray-core/tar.gz/v'
Old_PKG_VERSION=$(sed -n "/^$version_head/p" feeds/packages/net/xray-core/Makefile | awk -F '=' '{print $2}')
New_PKG_VERSION=$release_api_command
echo "$packages目前版本: $Old_PKG_VERSION"
echo "$packages最新版本: $New_PKG_VERSION"
version_greater_equal "$Old_PKG_VERSION" "$New_PKG_VERSION" && echo "$packages版本为最新版本$Old_PKG_VERSION,无需更新" || (PKG_HASH=$(wget -qO - $release_download_url$New_PKG_VERSION | tee file | sha256sum | awk '{print $1}') && sed -i -e "/^$version_head/c$version_head$New_PKG_VERSION" -e "/^$hash_head/c$hash_head$PKG_HASH" feeds/packages/net/xray-core/Makefile && echo "已更新$packages版本到: $New_PKG_VERSION")
cp $GITHUB_WORKSPACE/Makefile.golang feeds/packages/lang/golang/golang/Makefile
[ -e feeds/packages/net/xray-core/patches ] && rm -rf feeds/packages/net/xray-core/patches
git clone --branch openwrt-23.05 --depth 1 --single-branch https://github.com/immortalwrt/packages.git tmp_packages
git clone --branch openwrt-23.05 --depth 1 --single-branch https://github.com/immortalwrt/luci.git tmp_luci
#[ ! -e feeds/luci/applications/luci-app-adguardhome ] && git clone --branch master --depth 1 --single-branch https://github.com/kongfl888/luci-app-adguardhome.git feeds/luci/applications/luci-app-adguardhome
#[[ -e tmp_packages/net/gost && ! -e feeds/packages/net/gost ]] && mv tmp_packages/net/gost feeds/packages/net
#[[ -e tmp_luci/applications/luci-app-gost && ! -e feeds/luci/applications/luci-app-gost ]] && mv tmp_luci/applications/luci-app-gost feeds/luci/applications
[ ! -e feeds/luci/applications/luci-app-homeproxy ] && git clone --branch master --depth 1 --single-branch https://github.com/immortalwrt/homeproxy.git feeds/luci/applications/luci-app-homeproxy
rm -rf feeds/packages/net/smartdns && git clone --branch master --depth 1 --single-branch https://github.com/pymumu/openwrt-smartdns.git feeds/packages/net/smartdns
rm -rf feeds/luci/applications/luci-app-smartdns && git clone --branch master --depth 1 --single-branch https://github.com/pymumu/luci-app-smartdns.git feeds/luci/applications/luci-app-smartdns
[[ -e tmp_packages/net/mosdns && ! -e feeds/packages/net/mosdns ]] && mv tmp_packages/net/mosdns feeds/packages/net
#[[ -e tmp_luci/applications/luci-app-syncdial && ! -e feeds/luci/applications/luci-app-syncdial ]] && mv tmp_luci/applications/luci-app-syncdial feeds/luci/applications
[[ -e tmp_packages/net/vlmcsd && ! -e feeds/packages/net/vlmcsd ]] && mv tmp_packages/net/vlmcsd feeds/packages/net
[[ -e tmp_luci/applications/luci-app-vlmcsd && ! -e feeds/luci/applications/luci-app-vlmcsd ]] && mv tmp_luci/applications/luci-app-vlmcsd feeds/luci/applications
#[ ! -e feeds/packages/lang/lua-maxminddb ] && git clone --branch master --depth 1 --single-branch https://github.com/jerrykuku/lua-maxminddb.git feeds/packages/lang/lua-maxminddb
#[ ! -e feeds/luci/applications/luci-app-vssr ] && git clone --branch master --depth 1 --single-branch https://github.com/jerrykuku/luci-app-vssr.git feeds/luci/applications/luci-app-vssr
[[ -e tmp_luci/applications/luci-app-zerotier && ! -e feeds/luci/applications/luci-app-zerotier ]] && mv tmp_luci/applications/luci-app-zerotier feeds/luci/applications
rm -rf tmp_packages
rm -rf tmp_luci
./scripts/feeds update -i packages
./scripts/feeds update -i luci
sed -i "/iptables-nft/d" feeds/passwall2_luci/luci-app-passwall2/Makefile
- name: Install feeds
run: cd openwrt && ./scripts/feeds install -a
- name: Load custom configuration
run: |
[ -e files ] && mv files openwrt/files
[ ! -e openwrt/files/etc/openclash/core ] && mkdir -p openwrt/files/etc/openclash/core
tunver=$(curl --fail -sL https://raw.githubusercontent.com/vernesong/OpenClash/core/master/core_version | sed -n 2p)
curl --fail -sL https://raw.githubusercontent.com/vernesong/OpenClash/core/master/meta/clash-linux-armv7.tar.gz | tar -xz -C openwrt/files/etc/openclash/core && mv openwrt/files/etc/openclash/core/clash openwrt/files/etc/openclash/core/clash_meta
#curl --fail -sL https://raw.githubusercontent.com/vernesong/OpenClash/core/master/premium/clash-linux-armv7-${tunver}.gz | gzip -d > openwrt/files/etc/openclash/core/clash_tun && chmod +x openwrt/files/etc/openclash/core/clash_tun
#curl --fail -sL https://raw.githubusercontent.com/vernesong/OpenClash/core/master/dev/clash-linux-armv7.tar.gz | tar -xz -C openwrt/files/etc/openclash/core
[ ! -e openwrt/files/usr/bin ] && mkdir -p openwrt/files/usr/bin
#curl --fail -sL https://static.adguard.com/adguardhome/release/AdGuardHome_linux_armv7.tar.gz | tar -xz -C openwrt/files/usr/bin
[ -e $CONFIG_FILE ] && mv $CONFIG_FILE openwrt/.config || cat >> openwrt/.config <<EOF
CONFIG_TARGET_ipq40xx=y
CONFIG_TARGET_ipq40xx_generic=y
CONFIG_TARGET_ipq40xx_generic_DEVICE_asus_rt-ac42u=y
CONFIG_DEVEL=y
CONFIG_BPF_TOOLCHAIN_BUILD_LLVM=y
# CONFIG_PACKAGE_dnsmasq is not set
CONFIG_PACKAGE_dnsmasq-full=y
CONFIG_PACKAGE_qosify=y
CONFIG_PACKAGE_diffutils=y
CONFIG_PACKAGE_libopenssl-legacy=y
CONFIG_PACKAGE_luci=y
CONFIG_LUCI_LANG_zh_Hans=y
CONFIG_PACKAGE_luci-app-adblock=y
CONFIG_PACKAGE_luci-app-homeproxy=y
CONFIG_PACKAGE_luci-app-openclash=y
CONFIG_PACKAGE_luci-app-passwall=y
CONFIG_PACKAGE_luci-app-passwall2=y
CONFIG_PACKAGE_luci-app-smartdns=y
CONFIG_PACKAGE_luci-app-upnp=y
CONFIG_PACKAGE_luci-app-vlmcsd=y
CONFIG_PACKAGE_luci-app-zerotier=y
CONFIG_PACKAGE_luci-theme-openwrt-2020=y
CONFIG_PACKAGE_wget-ssl=y
# CONFIG_SINGBOX_WITH_ACME is not set
CONFIG_SINGBOX_WITH_CLASH_API=y
# CONFIG_SINGBOX_WITH_DHCP is not set
CONFIG_SINGBOX_WITH_ECH=y
# CONFIG_SINGBOX_WITH_EMBEDDED_TOR is not set
# CONFIG_SINGBOX_WITH_GRPC is not set
CONFIG_SINGBOX_WITH_GVISOR=y
CONFIG_SINGBOX_WITH_QUIC=y
# CONFIG_SINGBOX_WITH_REALITY_SERVER is not set
CONFIG_SINGBOX_WITH_UTLS=y
# CONFIG_SINGBOX_WITH_V2RAY_API is not set
CONFIG_SINGBOX_WITH_WIREGUARD=y
CONFIG_PACKAGE_vim=y
CONFIG_PACKAGE_vim-runtime=y
EOF
chmod +x $DIY_P2_SH
cd openwrt
$GITHUB_WORKSPACE/$DIY_P2_SH
- name: Download package
id: package
run: |
cd openwrt
make defconfig
New_PKG_SOURCE_VERSION=$(git ls-remote https://github.com/pymumu/smartdns.git master | awk '{ print $1; }')
echo "smartdns PKG_SOURCE_VERSION: $New_PKG_SOURCE_VERSION"
sed -i "s/PKG_SOURCE_VERSION:=.*/PKG_SOURCE_VERSION:=$New_PKG_SOURCE_VERSION/g" feeds/packages/net/smartdns/Makefile
make download -j8
make package/feeds/packages/smartdns/check FIXUP=1
New_PKG_MIRROR_HASH=$(grep PKG_MIRROR_HASH feeds/packages/net/smartdns/Makefile | awk -F '=' '{print $2}')
echo "smartdns PKG_MIRROR_HASH: $New_PKG_MIRROR_HASH"
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
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
- name: Upload bin directory
uses: actions/upload-artifact@v4
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: env.UPLOAD_FIRMWARE == 'true' && !cancelled()
run: |
cd openwrt/bin/targets/*/*
rm -rf packages
rm -f *initramfs-uImage.itb
echo "FIRMWARE=$PWD" >> $GITHUB_ENV
echo "status=success" >> $GITHUB_OUTPUT
- name: Upload firmware directory
uses: actions/upload-artifact@v4
if: steps.organize.outputs.status == 'success' && !cancelled()
with:
name: OpenWrt_firmware${{ env.DEVICE_NAME }}${{ env.FILE_DATE }}
path: ${{ env.FIRMWARE }}
- name: Generate release tag
id: tag
if: env.UPLOAD_RELEASE == 'true' && !cancelled()
run: |
echo "release_tag=$(date +"%Y.%m.%d-%H%M")" >> $GITHUB_OUTPUT
touch release.txt
[ ${UPLOAD_GOFILE} = true && ${{ steps.gofile.outputs.url }} ] && echo "🔗 [GoFile](${{ steps.gofile.outputs.url }})" >> release.txt
echo "status=success" >> $GITHUB_OUTPUT
- name: Upload firmware to release
uses: softprops/action-gh-release@master
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: Delete workflow runs
uses: Mattraks/delete-workflow-runs@main
with:
retain_days: 0
keep_minimum_runs: 2
- name: Remove old Releases
uses: dev-drprasad/delete-older-releases@master
if: env.UPLOAD_RELEASE == 'true' && !cancelled()
with:
keep_latest: 3
delete_tags: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}