Skip to content

Auto Update

Auto Update #132

Workflow file for this run

name: Auto Update
on:
schedule:
# 每天北京时间 02:53 (UTC时间 18:53)
- cron: '43 18 * * *'
workflow_dispatch:
# 【新增选择框集群】控制手动触发时的执行步骤,默认全选 (true)
inputs:
phase1:
description: '🔄 运行 Phase 1 - Update Add Rules'
type: boolean
default: true
phase2:
description: '🌳 运行 Phase 2 - Update List Rules'
type: boolean
default: true
phase3:
description: '📦 运行 Phase 3 - Convert MRS Rules'
type: boolean
default: true
phase4:
description: '🖼️ 运行 Phase 4 - Update Images'
type: boolean
default: true
phase5:
description: '🚀 运行 Phase 5 - Build Zashboard'
type: boolean
default: true
phase6:
description: '📝 运行 Phase 6 - Update README'
type: boolean
default: true
env:
TZ: Asia/Shanghai
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🐍 Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
# --- 集中管理:沙盒滚动缓存集群 ---
- name: 📦 Cache pip dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('.github/scripts/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: 📦 Cache Image State
uses: actions/cache@v4
with:
path: ~/.cache/img_state
key: ${{ runner.os }}-img-state-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-img-state-
- name: 📦 Cache Zashboard Env
uses: actions/cache@v4
with:
path: ~/.cache/zashboard_env
key: ${{ runner.os }}-zash-env-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-zash-env-
- name: 📦 Cache Mihomo Core
uses: actions/cache@v4
with:
path: ~/.cache/mihomo_core
key: ${{ runner.os }}-mihomo-core-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-mihomo-core-
# --- 环境初始化 ---
- name: ⚙️ Setup Python Env
run: |
for i in 1 2; do
if bash -e -c '
echo "=> Installing Python dependencies..."
pip install -r .github/scripts/requirements.txt
'; then break; else
if [ $i -eq 2 ]; then echo "❌ Setup failed."; exit 1; fi
echo "⚠️ Retrying Setup Env in 5 seconds... ($i/2)"
sleep 5
fi
done
# --- 串行执行流水线 (全步骤覆盖选择判定与智能重试) ---
- name: 🔄 Phase 1 - Update Add Rules
if: github.event_name == 'schedule' || github.event.inputs.phase1 == 'true'
run: |
for i in 1 2; do
if bash -e -c '
echo "=> Fetching External Rules dynamically..."
for script in .github/scripts/update-add-rules/*.py; do
echo "Running $script..."
python "$script"
done
'; then break; else
if [ $i -eq 2 ]; then echo "❌ Phase 1 failed."; exit 1; fi
echo "⚠️ Phase 1 execution failed. Retrying in 10 seconds... ($i/2)"
sleep 10
fi
done
- name: 🌳 Phase 2 - Update List Rules
if: github.event_name == 'schedule' || github.event.inputs.phase2 == 'true'
run: |
for i in 1 2; do
if bash -e -c '
echo "=> Building Rule Trees..."
python .github/scripts/update-list-rules.py
'; then break; else
if [ $i -eq 2 ]; then echo "❌ Phase 2 failed."; exit 1; fi
echo "⚠️ Phase 2 execution failed. Retrying in 10 seconds... ($i/2)"
sleep 10
fi
done
- name: 📦 Phase 3 - Convert MRS Rules
if: github.event_name == 'schedule' || github.event.inputs.phase3 == 'true'
run: |
for i in 1 2; do
if bash -e -c '
echo "=> Preparing Mihomo & Converting to MRS binary format..."
chmod +x .github/scripts/update-mrs-rules.sh
bash .github/scripts/update-mrs-rules.sh
'; then break; else
if [ $i -eq 2 ]; then echo "❌ Phase 3 failed."; exit 1; fi
echo "⚠️ Phase 3 execution failed. Retrying in 10 seconds... ($i/2)"
sleep 10
fi
done
- name: 🖼️ Phase 4 - Update Images
if: github.event_name == 'schedule' || github.event.inputs.phase4 == 'true'
run: |
for i in 1 2; do
if bash -e -c '
echo "=> Fetching and updating images..."
python .github/scripts/update-img.py
'; then break; else
if [ $i -eq 2 ]; then echo "❌ Phase 4 failed."; exit 1; fi
echo "⚠️ Phase 4 execution failed. Retrying in 10 seconds... ($i/2)"
sleep 10
fi
done
- name: 🚀 Phase 5 - Build Zashboard
if: github.event_name == 'schedule' || github.event.inputs.phase5 == 'true'
run: |
for i in 1 2; do
if bash -e -c '
echo "=> Building and releasing Zashboard..."
python .github/scripts/zashboard.py
'; then break; else
if [ $i -eq 2 ]; then echo "❌ Phase 5 failed."; exit 1; fi
echo "⚠️ Phase 5 execution failed. Retrying in 10 seconds... ($i/2)"
sleep 10
fi
done
- name: 📝 Phase 6 - Update README
if: github.event_name == 'schedule' || github.event.inputs.phase6 == 'true'
run: |
for i in 1 2; do
if bash -e -c '
echo "=> Updating README.md statistics..."
python .github/scripts/update-readme.py
'; then break; else
if [ $i -eq 2 ]; then echo "❌ Phase 6 failed."; exit 1; fi
echo "⚠️ Phase 6 execution failed. Retrying in 5 seconds... ($i/2)"
sleep 5
fi
done
# --- 终极推送 ---
- name: ⬆️ Commit and Push Changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "🤖 chore: Auto-update rules, MRS, images, zashboard and README"
commit_user_name: "github-actions[bot]"
commit_user_email: "github-actions[bot]@users.noreply.github.com"