Sync and Compile Direct Rules #24
This file contains 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 Direct Rules | |
on: | |
schedule: | |
- cron: '0 18 * * *' # 北京时间 02:00 执行 | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
direct_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 Direct Rules | |
run: | | |
mkdir -p rules/Domain # 确保目录存在 | |
# 下载 Direct 规则文件 | |
curl -sL "https://raw.githubusercontent.com/Lanlan13-14/Rules/refs/heads/main/rules/Domain/direct.list" -o rules/Domain/direct.list | |
- name: Extract DOMAIN rules from direct.list | |
run: | | |
# 提取 direct.list 中的 DOMAIN 和 DOMAIN-SUFFIX 规则 | |
grep -Eo 'DOMAIN-SUFFIX,[^,]+' rules/Domain/direct.list | sed 's/DOMAIN-SUFFIX,//' > rules/Domain/direct-domain.list | |
grep -Eo 'DOMAIN,[^,]+' rules/Domain/direct.list | sed 's/DOMAIN,//' >> rules/Domain/direct-domain.list | |
- name: Convert Direct Rules to YAML | |
run: | | |
echo "payload:" > rules/Domain/direct.yaml | |
sort -u rules/Domain/direct-domain.list | awk '{print " - \047" $0 "\047"}' >> rules/Domain/direct.yaml | |
- name: Convert Direct Rules to MRS | |
run: | | |
# 使用 mihomo 转换为 MRS 格式 | |
mihomo convert-ruleset domain yaml rules/Domain/direct.yaml rules/Domain/direct.mrs | |
rm -f rules/Domain/direct-domain.list rules/Domain/direct.yaml | |
- name: Commit and Push Changes | |
run: | | |
git add . | |
git diff-index --quiet HEAD -- || (git commit -m "Updated Direct rules (direct.list -> direct.mrs)" && git push) |