147 lines
6.2 KiB
YAML
147 lines
6.2 KiB
YAML
name: bin_update
|
||
|
||
on:
|
||
schedule:
|
||
- cron: "0 18 * * *" # UTC 18 = 北京时间次日凌晨 2 点
|
||
workflow_dispatch:
|
||
|
||
jobs:
|
||
update:
|
||
runs-on: ubuntu-latest
|
||
|
||
steps:
|
||
- name: Checkout update branch (ignore if missing)
|
||
uses: actions/checkout@v5
|
||
with:
|
||
ref: update
|
||
fetch-depth: 1
|
||
persist-credentials: false # 禁用默认凭据(我们用 token push)
|
||
|
||
- name: Apt Update & Update CA
|
||
env:
|
||
DEBIAN_FRONTEND: noninteractive
|
||
run: |
|
||
sudo apt-get update
|
||
sudo apt-get -y install unzip curl git tar ca-certificates
|
||
sudo update-ca-certificates
|
||
cp -f /etc/ssl/certs/ca-certificates.crt bin/fix/ca-certificates.crt
|
||
|
||
- name: Update Dashboard
|
||
run: |
|
||
DASH="$GITHUB_WORKSPACE/bin/dashboard"
|
||
TEMP="$DASH/.tmp" # 临时目录
|
||
mkdir -p "$TEMP"
|
||
echo "下载面板..."
|
||
# 下载文件到临时目录
|
||
curl -kfSL -o "$TEMP/meta_yacd.zip" https://github.com/MetaCubeX/Yacd-meta/archive/gh-pages.zip
|
||
curl -kfSL -o "$TEMP/meta_xd.zip" https://github.com/MetaCubeX/metacubexd/archive/gh-pages.zip
|
||
curl -kfSL -o "$TEMP/zashboard.zip" https://github.com/Zephyruso/zashboard/releases/latest/download/dist-cdn-fonts.zip
|
||
########################################
|
||
# Yacd-meta
|
||
########################################
|
||
unzip -o "$TEMP/meta_yacd.zip" -d "$TEMP/yacd" > /dev/null
|
||
find "$TEMP/yacd" -name "*.map" -delete
|
||
rm -f "$TEMP/yacd/report.html"
|
||
tar -zcvf "$DASH/meta_yacd.tar.gz" -C "$TEMP/yacd" . > /dev/null
|
||
########################################
|
||
# metacubexd
|
||
########################################
|
||
unzip -o "$TEMP/meta_xd.zip" -d "$TEMP/xd" > /dev/null
|
||
find "$TEMP/xd" -name "*.ttf" -delete
|
||
tar -zcvf "$DASH/meta_xd.tar.gz" -C "$TEMP/xd" . > /dev/null
|
||
########################################
|
||
# zashboard
|
||
########################################
|
||
unzip -o "$TEMP/zashboard.zip" -d "$TEMP/zash" > /dev/null
|
||
if [ -d "$TEMP/zash/dist" ]; then
|
||
ZDIR="$TEMP/zash/dist"
|
||
elif [ -d "$TEMP/zash/dist-cdn-fonts/dist" ]; then
|
||
ZDIR="$TEMP/zash/dist-cdn-fonts/dist"
|
||
else
|
||
echo "未找到 dist 目录"
|
||
exit 1
|
||
fi
|
||
echo 'board.zash.run.place' > "$ZDIR/CNAME"
|
||
tar -zcvf "$DASH/zashboard.tar.gz" -C "$ZDIR" . > /dev/null
|
||
########################################
|
||
# 一步清理所有临时文件(核心)
|
||
########################################
|
||
rm -rf "$TEMP"
|
||
echo "面板更新完成!"
|
||
|
||
- name: Update Geodata
|
||
run: |
|
||
cd bin
|
||
curl -kfSL -o geodata/cn_mini.mmdb https://raw.githubusercontent.com/Hackl0us/GeoIP2-CN/release/Country.mmdb
|
||
curl -kfSL -o geodata/china_ip_list.txt https://raw.githubusercontent.com/ChanthMiao/China-IPv4-List/release/cn.txt
|
||
curl -kfSL -o geodata/china_ipv6_list.txt https://raw.githubusercontent.com/ChanthMiao/China-IPv6-List/release/cn6.txt
|
||
curl -kfSL -o geodata/geosite.dat https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-geodata/geosite-all.dat
|
||
curl -kfSL -o geodata/srs_geoip_cn.srs https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/cnip.srs
|
||
curl -kfSL -o geodata/srs_geosite_cn.srs https://github.com/DustinWin/ruleset_geodata/releases/download/sing-box-ruleset/cn.srs
|
||
curl -kfSL -o geodata/mrs_geosite_cn.mrs https://github.com/DustinWin/ruleset_geodata/releases/download/mihomo-ruleset/cn.mrs
|
||
# 下载规则集
|
||
curl -kfSL -o mihomo-ruleset.zip https://github.com/DustinWin/ruleset_geodata/archive/refs/heads/mihomo-ruleset.zip
|
||
curl -kfSL -o sing-box-ruleset.zip https://github.com/DustinWin/ruleset_geodata/archive/refs/heads/sing-box-ruleset.zip
|
||
|
||
##########################################
|
||
# 解压
|
||
unzip -o mihomo-ruleset.zip > /dev/null
|
||
unzip -o sing-box-ruleset.zip > /dev/null
|
||
##########################################
|
||
# 处理 mihomo 规则 (mrs)
|
||
if [ -d ruleset_geodata-mihomo-ruleset ]; then
|
||
cd ruleset_geodata-mihomo-ruleset
|
||
# 删除不需要的 .list
|
||
find . -type f -name "*.list" -delete
|
||
# 输出文件放到上级目录,避免 tar 自己包含自己
|
||
tar -zcvf ../mrs.tar.gz . > /dev/null
|
||
cd ..
|
||
else
|
||
echo "错误:未找到 ruleset_geodata-mihomo-ruleset"
|
||
fi
|
||
##########################################
|
||
# 处理 sing-box 规则 (srs)
|
||
if [ -d ruleset_geodata-sing-box-ruleset ]; then
|
||
cd ruleset_geodata-sing-box-ruleset
|
||
# 删除 .json
|
||
find . -type f -name "*.json" -delete
|
||
# 同样避免目录内生成 tar 导致 file-changed 错误
|
||
tar -zcvf ../srs.tar.gz . > /dev/null
|
||
cd ..
|
||
else
|
||
echo "错误:未找到 ruleset_geodata-sing-box-ruleset"
|
||
fi
|
||
##########################################
|
||
# 移动到 geodata
|
||
mv -f mrs.tar.gz geodata/
|
||
mv -f srs.tar.gz geodata/
|
||
|
||
# 删除目录
|
||
rm -rf ruleset_geodata-mihomo-ruleset
|
||
rm -rf ruleset_geodata-sing-box-ruleset
|
||
rm -rf mihomo-ruleset.zip
|
||
rm -rf sing-box-ruleset.zip
|
||
|
||
sed -i "s/GeoIP_v=.*/GeoIP_v=$(date '+%Y%m%d')/" version
|
||
echo 数据库及根证书文件更新完成!
|
||
|
||
- name: Rebuild update branch with no history
|
||
run: |
|
||
# 彻底删除历史记录
|
||
rm -rf .git
|
||
# 重新初始化仓库
|
||
git init
|
||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||
git config user.name "github-actions[bot]"
|
||
git add .
|
||
git commit -m "自动更新最新Dashboard、Geodata数据库及根证书"
|
||
# 强制推送覆盖 update 分支
|
||
git branch -M update
|
||
git remote add origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
|
||
git push -f origin update
|
||
|
||
- name: Cleanup Workflow
|
||
uses: Mattraks/delete-workflow-runs@main
|
||
with:
|
||
retain_days: 1
|
||
keep_minimum_runs: 2 |