Sync and Compile WeChat Rules #118
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 WeChat Rules | |
| on: | |
| schedule: | |
| - cron: '0 18 * * *' # 北京时间 02:00 执行 | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| wechat_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 WeChat Rules | |
| run: | | |
| mkdir -p rules/Domain # 确保目录存在 | |
| # 下载 WeChat 规则文件 | |
| curl -sL "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/refs/heads/master/rule/Clash/WeChat/WeChat.list" -o rules/Domain/WeChat.list | |
| - name: Extract DOMAIN rules from WeChat.list | |
| run: | | |
| # 提取 WeChat.list 中的 DOMAIN 和 DOMAIN-SUFFIX 规则,忽略注释行,并处理格式 | |
| grep -E '^(DOMAIN-SUFFIX|DOMAIN),' rules/Domain/WeChat.list | grep -v '^#' | sed -E 's/DOMAIN-SUFFIX,/*./g; s/DOMAIN,//g' > rules/Domain/WeChat-domain.list | |
| - name: Convert WeChat Rules to YAML | |
| run: | | |
| echo "payload:" > rules/Domain/WeChat.yaml | |
| sort -u rules/Domain/WeChat-domain.list | awk '{print " - \047" $0 "\047"}' >> rules/Domain/WeChat.yaml | |
| - name: Convert WeChat DOMAIN rules to MRS | |
| run: | | |
| # 使用 mihomo 转换为 MRS 格式 | |
| mihomo convert-ruleset domain yaml rules/Domain/WeChat.yaml rules/Domain/WeChat.mrs | |
| - name: Clean up the source files | |
| run: | | |
| # 删除中间步骤文件,只保留 WeChat.yaml 和 WeChat.mrs | |
| rm -f rules/Domain/WeChat.list rules/Domain/WeChat-domain.list | |
| - name: Commit and Push Changes | |
| run: | | |
| git add rules/Domain/WeChat.yaml rules/Domain/WeChat.mrs | |
| git diff-index --quiet HEAD -- || (git commit -m "Updated WeChat rules (WeChat.list -> WeChat.mrs)" && git push) |