Sync and Compile BanAd Rules #230
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 BanAd Rules | |
| on: | |
| schedule: | |
| - cron: '0 18 * * *' # 北京时间 02:00 执行 | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| banad_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 BanAd Rules | |
| run: | | |
| mkdir -p rules/Domain # 确保目录存在 | |
| # 下载 BanAd 规则文件 | |
| curl -sL "https://raw.githubusercontent.com/8680/GOODBYEADS/master/data/rules/qx.list" -o rules/Domain/qx.list | |
| curl -sL "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/refs/heads/meta/geo/geosite/category-ads-all.list" -o rules/Domain/category-ads-all.list | |
| # 下载 pcdn.json 并提取 domain / domain_suffix | |
| curl -sL "https://raw.githubusercontent.com/DDCHlsq/sing-ruleset/refs/heads/master/pcdn.json" -o pcdn.json | |
| # 下载自定义规则 pcdn.list | |
| curl -sL "https://raw.githubusercontent.com/Lanlan13-14/Rules/refs/heads/main/rules/Domain/pcdn.list" -o pcdn.list | |
| - name: Extract DOMAIN rules from qx.list, pcdn.json and pcdn.list | |
| run: | | |
| # 提取 qx.list 中的 DOMAIN 和 DOMAIN-SUFFIX 规则 | |
| grep -Eo 'DOMAIN,[^,]+' rules/Domain/qx.list | sed 's/DOMAIN,//' > rules/Domain/banAd-domain.list | |
| grep -Eo 'DOMAIN-SUFFIX,[^,]+' rules/Domain/qx.list | sed 's/DOMAIN-SUFFIX,//' >> rules/Domain/banAd-domain.list | |
| # 提取 pcdn.json 中的 domain | |
| jq -r '.rules[].domain[]?' pcdn.json >> rules/Domain/banAd-domain.list | |
| # 提取 pcdn.json 中的 domain_suffix,去掉开头的 . 并加上 '*.' 前缀 | |
| jq -r '.rules[].domain_suffix[]?' pcdn.json | sed 's/^\.//' | sed 's/^/*./' >> rules/Domain/banAd-domain.list | |
| # 处理自定义 pcdn.list 文件 | |
| sed -E 's/^DOMAIN-SUFFIX,(.*)/*.\1/; s/^DOMAIN,(.*)/\1/' pcdn.list >> rules/Domain/banAd-domain.list | |
| - name: Convert BanAd Rules to YAML | |
| run: | | |
| echo "payload:" > rules/Domain/banAd.yaml | |
| sort -u rules/Domain/banAd-domain.list | awk '{print " - \047" $0 "\047"}' >> rules/Domain/banAd.yaml | |
| - name: Convert BanAd Rules to MRS | |
| run: | | |
| # 使用 mihomo 转换为 MRS 格式 | |
| mihomo convert-ruleset domain yaml rules/Domain/banAd.yaml rules/Domain/banAd.mrs | |
| - name: Clean up the source files | |
| run: | | |
| # 删除源文件,保留 banAd.yaml、banAd.mrs 和 pcdn.list | |
| rm -f rules/Domain/qx.list rules/Domain/category-ads-all.list rules/Domain/banAd-domain.list pcdn.json | |
| - name: Commit and Push Changes | |
| run: | | |
| git add . | |
| git commit -m "Updated BanAd rules (qx.list + pcdn.json + pcdn.list -> banAd.mrs)" || true | |
| git pull --rebase | |
| git push |