定时抓取清洗节点 #188
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 定时抓取清洗节点 | |
| on: | |
| schedule: | |
| - cron: '0 */4 * * *' # 每 4 小时(UTC 00/04/08/12/16/20) | |
| workflow_dispatch: # 手动触发 | |
| jobs: | |
| scrape: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: pip install requests beautifulsoup4 pyyaml | |
| - name: Install mihomo core | |
| run: | | |
| ARCH=$([ "$(uname -m)" = "aarch64" ] && echo arm64 || echo amd64) | |
| curl -fsSL "https://github.com/MetaCubeX/mihomo/releases/download/v1.19.9/mihomo-linux-${ARCH}-v1.19.9.gz" -o mihomo.gz | |
| gunzip -f mihomo.gz | |
| chmod +x mihomo | |
| echo "MIHOMO_BIN=$PWD/mihomo" >> "$GITHUB_ENV" | |
| - name: Scrape yoyapai | |
| run: | | |
| python scripts/scraper.py || echo "::warning::yoyapai 抓取失败,跳过该来源" | |
| - name: Fetch all sources | |
| run: | | |
| python scripts/fetch_sources.py || echo "::warning::部分来源下载失败,继续处理已下载的来源" | |
| - name: Sanitize clash.yaml files | |
| run: | | |
| for f in output/*/clash.yaml; do | |
| case "$f" in output/aio/*) continue;; esac | |
| src=$(basename "$(dirname "$f")") | |
| if python scripts/sanitize.py "$f" "$f.tmp" --source "$src" && mv "$f.tmp" "$f"; then | |
| echo " [OK] $f 清洗完成" | |
| else | |
| echo "::warning::$f 清洗失败,保留原文件" | |
| rm -f "$f.tmp" | |
| fi | |
| done | |
| - name: Test nodes and build AIO | |
| run: | | |
| INPUTS=$(find output -mindepth 2 -maxdepth 2 -name clash.yaml ! -path 'output/aio/*' | sort | tr '\n' ' ') | |
| if [ -n "$INPUTS" ]; then | |
| if python scripts/test_nodes.py $INPUTS -o output/aio/clash.yaml; then | |
| echo " [OK] AIO 生成完成" | |
| else | |
| echo "::warning::AIO 生成失败(节点测试异常),跳过本次 AIO" | |
| fi | |
| else | |
| echo "::warning::无可用输入文件,跳过 AIO" | |
| fi | |
| - name: Commit and push | |
| run: | | |
| git config user.name "proxy-node-bot" | |
| git config user.email "bot@proxy-node.dev" | |
| git stash | |
| git pull --rebase | |
| git stash pop | |
| git add output/ latest_urls.json | |
| git diff --cached --quiet || git commit -m "update: $(TZ=Asia/Shanghai date +%Y-%m-%d) 节点订阅" | |
| git push |