Sync and Compile TVB Rules #119
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: Sync and Compile TVB Rules | |
| on: | |
| schedule: | |
| - cron: '0 18 * * *' # 每天北京时间02:00执行 | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| tvb_rules: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout the repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Git user | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Install mihomo | |
| run: | | |
| version=$(curl -sL https://github.com/MetaCubeX/mihomo/releases/download/Prerelease-Alpha/version.txt) | |
| curl -sL "https://github.com/MetaCubeX/mihomo/releases/download/Prerelease-Alpha/mihomo-linux-amd64-${version}.gz" | \ | |
| gunzip -c > /usr/local/bin/mihomo && chmod +x /usr/local/bin/mihomo | |
| - name: Fetch TVB Rules | |
| run: | | |
| mkdir -p rules/Domain # 确保目录存在 | |
| # 下载 TVB 规则文件 | |
| curl -sL "https://raw.githubusercontent.com/btjson/loon/refs/heads/main/TVB.list" -o rules/Domain/tvb.list | |
| - name: Convert TVB Rules to YAML | |
| run: | | |
| echo "payload:" > rules/Domain/tvb.yaml | |
| while IFS=, read -r type value; do | |
| if [[ -n "$type" && -n "$value" ]]; then | |
| # 处理 DOMAIN 规则,直接加入 | |
| if [[ "$type" == "DOMAIN" ]]; then | |
| echo " - $value" >> rules/Domain/tvb.yaml | |
| # 处理 DOMAIN-SUFFIX 规则,加上 *. | |
| elif [[ "$type" == "DOMAIN-SUFFIX" ]]; then | |
| echo " - '*.$value'" >> rules/Domain/tvb.yaml | |
| fi | |
| fi | |
| done < rules/Domain/tvb.list | |
| - name: Convert TVB Rules to MRS | |
| run: | | |
| # 使用 mihomo 转换为 MRS 格式 | |
| mihomo convert-ruleset domain yaml rules/Domain/tvb.yaml rules/Domain/tvb.mrs | |
| - name: Clean up and Commit Changes | |
| run: | | |
| # 删除原始的 tvb.list 文件,保留 tvb.yaml 和 tvb.mrs | |
| rm -f rules/Domain/tvb.list | |
| git add . | |
| git diff-index --quiet HEAD -- || (git commit -m "Updated TVB rules (tvb.list -> tvb.mrs)" && git push) |