From 77fcfa4b2d3ae8892eaae432c6664b18f23bba4e Mon Sep 17 00:00:00 2001 From: adminroot Date: Fri, 12 Sep 2025 00:09:53 -0700 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20.gitea/workflows/update-ru?= =?UTF-8?q?les.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/update-rules.yml | 291 ++++++++++++++++++++++-------- 1 file changed, 214 insertions(+), 77 deletions(-) diff --git a/.gitea/workflows/update-rules.yml b/.gitea/workflows/update-rules.yml index 69294e4..c0e4873 100644 --- a/.gitea/workflows/update-rules.yml +++ b/.gitea/workflows/update-rules.yml @@ -17,7 +17,9 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} - name: 创建规则目录 - run: mkdir -p ruleset + run: | + mkdir -p ruleset/txt + mkdir -p ruleset/yaml - name: 下载规则文件 run: | @@ -44,61 +46,115 @@ jobs: for rule in "${rules[@]}"; do echo "下载 $rule.txt..." curl -L "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/${rule}.txt" \ - -o "ruleset/${rule}.txt" \ + -o "ruleset/txt/${rule}.txt" \ --fail \ --silent \ --show-error \ --retry 3 \ --retry-delay 5 - # 同时生成 YAML 格式(Clash 需要) - echo "payload:" > "ruleset/${rule}.yaml" - sed 's/^/ - /' "ruleset/${rule}.txt" >> "ruleset/${rule}.yaml" + # 生成 YAML 格式(Clash 需要) + echo "payload:" > "ruleset/yaml/${rule}.yaml" + sed 's/^/ - /' "ruleset/txt/${rule}.txt" >> "ruleset/yaml/${rule}.yaml" done - - name: 生成索引文件 + - name: 生成 README(根目录) run: | - cat > ruleset/README.md << 'EOF' - # Clash 规则文件 + cat > README.md << 'EOF' + # Clash Rules 规则仓库 - 最后更新时间: $(date +'%Y-%m-%d %H:%M:%S UTC') + [![Update Rules](https://github.com/${{ github.repository }}/actions/workflows/clash-rules.yml/badge.svg)](https://github.com/${{ github.repository }}/actions/workflows/clash-rules.yml) + [![Last Update](https://img.shields.io/badge/Last%20Update-$(date +'%Y--%m--%d')-blue)](https://github.com/${{ github.repository }}/tree/main/ruleset) - ## 规则文件列表 + 自动同步 [Loyalsoldier/clash-rules](https://github.com/Loyalsoldier/clash-rules) 规则,每日更新。 - | 规则名称 | 文本格式 | YAML格式 | 描述 | - |---------|---------|----------|------| - | 广告拦截 | [reject.txt](./reject.txt) | [reject.yaml](./reject.yaml) | 广告和跟踪域名 | - | iCloud | [icloud.txt](./icloud.txt) | [icloud.yaml](./icloud.yaml) | iCloud 域名 | - | 苹果服务 | [apple.txt](./apple.txt) | [apple.yaml](./apple.yaml) | Apple 服务域名 | - | 谷歌服务 | [google.txt](./google.txt) | [google.yaml](./google.yaml) | Google 服务域名 | - | 代理列表 | [proxy.txt](./proxy.txt) | [proxy.yaml](./proxy.yaml) | 需要代理的域名 | - | 直连列表 | [direct.txt](./direct.txt) | [direct.yaml](./direct.yaml) | 直连域名 | - | 私有网络 | [private.txt](./private.txt) | [private.yaml](./private.yaml) | 私有网络域名 | - | GFW列表 | [gfw.txt](./gfw.txt) | [gfw.yaml](./gfw.yaml) | GFW 域名列表 | - | 非中国顶级域名 | [tld-not-cn.txt](./tld-not-cn.txt) | [tld-not-cn.yaml](./tld-not-cn.yaml) | 非中国顶级域名 | - | Telegram CIDR | [telegramcidr.txt](./telegramcidr.txt) | [telegramcidr.yaml](./telegramcidr.yaml) | Telegram IP 段 | - | 中国 CIDR | [cncidr.txt](./cncidr.txt) | [cncidr.yaml](./cncidr.yaml) | 中国 IP 段 | - | 局域网 CIDR | [lancidr.txt](./lancidr.txt) | [lancidr.yaml](./lancidr.yaml) | 局域网 IP 段 | - | 应用规则 | [applications.txt](./applications.txt) | [applications.yaml](./applications.yaml) | 应用程序规则 | + ## 📁 文件结构 - ## 使用方法 + ``` + . + ├── README.md # 本文档 + └── ruleset/ + ├── txt/ # 原始文本格式规则 + │ ├── reject.txt + │ ├── proxy.txt + │ └── ... + └── yaml/ # Clash YAML 格式规则 + ├── reject.yaml + ├── proxy.yaml + └── ... + ``` - ### 在 Clash 配置中使用(远程规则) + ## 📊 规则文件说明 + + | 规则名称 | 类型 | 描述 | 文本格式 | YAML格式 | + |---------|------|------|---------|----------| + | reject | 域名 | 广告和跟踪域名 | [txt](./ruleset/txt/reject.txt) | [yaml](./ruleset/yaml/reject.yaml) | + | icloud | 域名 | iCloud 域名 | [txt](./ruleset/txt/icloud.txt) | [yaml](./ruleset/yaml/icloud.yaml) | + | apple | 域名 | Apple 服务域名 | [txt](./ruleset/txt/apple.txt) | [yaml](./ruleset/yaml/apple.yaml) | + | google | 域名 | Google 服务域名 | [txt](./ruleset/txt/google.txt) | [yaml](./ruleset/yaml/google.yaml) | + | proxy | 域名 | 需要代理的域名 | [txt](./ruleset/txt/proxy.txt) | [yaml](./ruleset/yaml/proxy.yaml) | + | direct | 域名 | 直连域名 | [txt](./ruleset/txt/direct.txt) | [yaml](./ruleset/yaml/direct.yaml) | + | private | 域名 | 私有网络域名 | [txt](./ruleset/txt/private.txt) | [yaml](./ruleset/yaml/private.yaml) | + | gfw | 域名 | GFW 域名列表 | [txt](./ruleset/txt/gfw.txt) | [yaml](./ruleset/yaml/gfw.yaml) | + | tld-not-cn | 域名 | 非中国顶级域名 | [txt](./ruleset/txt/tld-not-cn.txt) | [yaml](./ruleset/yaml/tld-not-cn.yaml) | + | telegramcidr | IP段 | Telegram IP 段 | [txt](./ruleset/txt/telegramcidr.txt) | [yaml](./ruleset/yaml/telegramcidr.yaml) | + | cncidr | IP段 | 中国 IP 段 | [txt](./ruleset/txt/cncidr.txt) | [yaml](./ruleset/yaml/cncidr.yaml) | + | lancidr | IP段 | 局域网 IP 段 | [txt](./ruleset/txt/lancidr.txt) | [yaml](./ruleset/yaml/lancidr.yaml) | + | applications | 进程 | 应用程序规则 | [txt](./ruleset/txt/applications.txt) | [yaml](./ruleset/yaml/applications.yaml) | + + ## 🚀 使用方法 + + ### 方式一:远程规则订阅(推荐) + + 在 Clash 配置文件中添加: \`\`\`yaml rule-providers: + # 广告拦截 reject: type: http behavior: domain - url: "https://raw.githubusercontent.com/[你的用户名]/[你的仓库名]/main/ruleset/reject.yaml" + url: "https://cdn.jsdelivr.net/gh/${{ github.repository }}@main/ruleset/yaml/reject.yaml" path: ./ruleset/reject.yaml interval: 86400 + + # 代理规则 + proxy: + type: http + behavior: domain + url: "https://cdn.jsdelivr.net/gh/${{ github.repository }}@main/ruleset/yaml/proxy.yaml" + path: ./ruleset/proxy.yaml + interval: 86400 + + # 直连规则 + direct: + type: http + behavior: domain + url: "https://cdn.jsdelivr.net/gh/${{ github.repository }}@main/ruleset/yaml/direct.yaml" + path: ./ruleset/direct.yaml + interval: 86400 + + # 中国IP段 + cncidr: + type: http + behavior: ipcidr + url: "https://cdn.jsdelivr.net/gh/${{ github.repository }}@main/ruleset/yaml/cncidr.yaml" + path: ./ruleset/cncidr.yaml + interval: 86400 + + rules: + - RULE-SET,reject,REJECT + - RULE-SET,proxy,PROXY + - RULE-SET,direct,DIRECT + - RULE-SET,cncidr,DIRECT + - GEOIP,CN,DIRECT + - MATCH,PROXY \`\`\` - ### 在 Clash 配置中使用(本地规则) + ### 方式二:本地规则文件 - 1. 下载规则文件到本地 Clash 配置目录 - 2. 在配置文件中引用: + 1. 下载所需的规则文件到本地 + 2. 在 Clash 配置中引用本地文件: \`\`\`yaml rule-providers: @@ -108,13 +164,45 @@ jobs: path: ./ruleset/reject.yaml \`\`\` - ## 数据来源 + ## 🔗 CDN 加速地址 - 规则文件来源于 [Loyalsoldier/clash-rules](https://github.com/Loyalsoldier/clash-rules) + 提供多个 CDN 地址,选择最适合你的: - ## 更新频率 + ### jsDelivr(推荐,国内可访问) + \`\`\` + https://cdn.jsdelivr.net/gh/${{ github.repository }}@main/ruleset/yaml/[规则名].yaml + https://fastly.jsdelivr.net/gh/${{ github.repository }}@main/ruleset/yaml/[规则名].yaml + \`\`\` - 每天自动更新一次(UTC 23:00 / 北京时间 07:00) + ### GitHub Raw + \`\`\` + https://raw.githubusercontent.com/${{ github.repository }}/main/ruleset/yaml/[规则名].yaml + \`\`\` + + ### Statically + \`\`\` + https://cdn.statically.io/gh/${{ github.repository }}/main/ruleset/yaml/[规则名].yaml + \`\`\` + + ## 📈 更新统计 + + 最后更新时间: $(date +'%Y-%m-%d %H:%M:%S UTC') + + 查看详细更新日志: [UPDATE_LOG.md](./ruleset/UPDATE_LOG.md) + + ## ⚙️ 自动更新 + + - **更新频率**: 每日自动更新(UTC 23:00 / 北京时间 07:00) + - **手动更新**: 可在 [Actions](https://github.com/${{ github.repository }}/actions) 页面手动触发 + - **数据来源**: [Loyalsoldier/clash-rules](https://github.com/Loyalsoldier/clash-rules) + + ## 📝 许可证 + + 本项目规则文件来自上游项目,仅做格式转换和分发。 + + --- + + 如果这个项目对你有帮助,请给个 ⭐ Star! EOF - name: 生成更新日志 @@ -122,24 +210,66 @@ jobs: cat > ruleset/UPDATE_LOG.md << EOF # 更新日志 - ## $(date +'%Y-%m-%d') + ## $(date +'%Y-%m-%d %H:%M:%S UTC') - ### 文件统计 + ### 📊 文件大小统计 + + #### TXT 文件 + \`\`\` + $(ls -lh ruleset/txt/*.txt | awk '{print $NF ": " $5}' | sed 's|.*/||') + \`\`\` + + #### YAML 文件 + \`\`\` + $(ls -lh ruleset/yaml/*.yaml | awk '{print $NF ": " $5}' | sed 's|.*/||') + \`\`\` + + ### 📈 规则数量统计 + \`\`\` EOF - echo '```' >> ruleset/UPDATE_LOG.md - ls -lh ruleset/*.txt | awk '{print $9 ": " $5}' >> ruleset/UPDATE_LOG.md + for file in ruleset/txt/*.txt; do + name=$(basename "$file" .txt) + count=$(wc -l < "$file") + printf "%-20s %6d 条规则\n" "$name:" "$count" >> ruleset/UPDATE_LOG.md + done + echo '```' >> ruleset/UPDATE_LOG.md echo "" >> ruleset/UPDATE_LOG.md - echo "### 规则数量统计" >> ruleset/UPDATE_LOG.md - echo '```' >> ruleset/UPDATE_LOG.md - for file in ruleset/*.txt; do - name=$(basename "$file" .txt) - count=$(wc -l < "$file") - echo "$name: $count 条规则" >> ruleset/UPDATE_LOG.md - done - echo '```' >> ruleset/UPDATE_LOG.md + echo "### 🔄 更新内容" >> ruleset/UPDATE_LOG.md + echo "- 同步上游最新规则" >> ruleset/UPDATE_LOG.md + echo "- 生成 YAML 格式文件" >> ruleset/UPDATE_LOG.md + echo "- 更新文档和统计信息" >> ruleset/UPDATE_LOG.md + + - name: 生成规则集 README + run: | + cat > ruleset/README.md << EOF + # Clash 规则文件目录 + + ## 目录结构 + + - \`txt/\` - 原始文本格式规则文件 + - \`yaml/\` - Clash YAML 格式规则文件 + + ## 快速链接 + + ### YAML 格式(Clash 直接使用) + - [reject.yaml](./yaml/reject.yaml) - 广告拦截 + - [proxy.yaml](./yaml/proxy.yaml) - 代理列表 + - [direct.yaml](./yaml/direct.yaml) - 直连列表 + - [gfw.yaml](./yaml/gfw.yaml) - GFW 列表 + - [cncidr.yaml](./yaml/cncidr.yaml) - 中国 IP 段 + + ### TXT 格式(原始规则) + - [reject.txt](./txt/reject.txt) - 广告拦截 + - [proxy.txt](./txt/proxy.txt) - 代理列表 + - [direct.txt](./txt/direct.txt) - 直连列表 + - [gfw.txt](./txt/gfw.txt) - GFW 列表 + - [cncidr.txt](./txt/cncidr.txt) - 中国 IP 段 + + 更多使用说明请查看 [项目主页](https://github.com/${{ github.repository }}) + EOF - name: 配置 Git run: | @@ -148,8 +278,8 @@ jobs: - name: 提交更改 run: | - git add ruleset/ - git diff --cached --quiet || git commit -m "Update clash rules - $(date +'%Y-%m-%d')" + git add README.md ruleset/ + git diff --cached --quiet || git commit -m "🔄 Update clash rules - $(date +'%Y-%m-%d')" - name: 推送到仓库 run: | @@ -157,38 +287,33 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: 创建 Release(每周一次) - if: github.event_name == 'schedule' && contains('1', github.run_number) + - name: 创建 Release(每周日) + if: github.event_name == 'schedule' && $(date +%u) == 7 uses: softprops/action-gh-release@v1 with: - tag_name: v${{ github.run_number }} - name: Clash Rules ${{ github.run_number }} + tag_name: v$(date +'%Y%m%d') + name: Clash Rules $(date +'%Y-%m-%d') body: | ## 📦 Clash 规则文件更新 - **更新时间**: ${{ env.DATE }} + **更新时间**: $(date +'%Y-%m-%d %H:%M:%S UTC') - ### 📥 下载链接 + ### 📥 下载方式 - 您可以通过以下方式获取规则文件: + #### CDN 加速链接(推荐) + ``` + https://cdn.jsdelivr.net/gh/${{ github.repository }}@main/ruleset/yaml/[规则名].yaml + ``` - 1. **直接引用**(推荐) - ``` - https://raw.githubusercontent.com/${{ github.repository }}/main/ruleset/[规则名].yaml - ``` - - 2. **下载压缩包** - 点击下方的 `clash-rules.zip` 下载所有规则文件 + #### 直接下载 + 点击下方的 Assets 下载压缩包 ### 📊 本次更新统计 查看 [UPDATE_LOG.md](https://github.com/${{ github.repository }}/blob/main/ruleset/UPDATE_LOG.md) ### 🔗 相关链接 - - [规则使用说明](https://github.com/${{ github.repository }}/blob/main/ruleset/README.md) + - [使用说明](https://github.com/${{ github.repository }}#使用方法) - [数据来源](https://github.com/Loyalsoldier/clash-rules) - files: | - ruleset/*.txt - ruleset/*.yaml draft: false prerelease: false @@ -196,7 +321,9 @@ jobs: if: github.event_name == 'workflow_dispatch' run: | cd ruleset - zip -r ../clash-rules.zip *.txt *.yaml README.md UPDATE_LOG.md + zip -r ../clash-rules-txt.zip txt/*.txt + zip -r ../clash-rules-yaml.zip yaml/*.yaml + zip -r ../clash-rules-all.zip txt/ yaml/ *.md cd .. - name: 上传压缩包作为 Artifact @@ -204,19 +331,29 @@ jobs: uses: actions/upload-artifact@v3 with: name: clash-rules-${{ github.run_number }} - path: clash-rules.zip + path: | + clash-rules-txt.zip + clash-rules-yaml.zip + clash-rules-all.zip retention-days: 7 - - name: 输出访问地址 + - name: 输出访问信息 run: | + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "✅ 规则文件已成功发布!" + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" - echo "📁 文件访问地址:" - echo "https://github.com/${{ github.repository }}/tree/main/ruleset" + echo "📁 文件结构:" + echo "├── README.md (根目录)" + echo "└── ruleset/" + echo " ├── txt/ (文本格式规则)" + echo " └── yaml/ (YAML格式规则)" echo "" - echo "🔗 Raw 文件地址示例:" - echo "https://raw.githubusercontent.com/${{ github.repository }}/main/ruleset/reject.yaml" + echo "🔗 访问地址:" + echo "主页: https://github.com/${{ github.repository }}" echo "" - echo "📦 CDN 加速地址(中国可访问):" - echo "https://cdn.jsdelivr.net/gh/${{ github.repository }}@main/ruleset/reject.yaml" - echo "https://fastly.jsdelivr.net/gh/${{ github.repository }}@main/ruleset/reject.yaml" \ No newline at end of file + echo "📦 CDN 加速示例:" + echo "https://cdn.jsdelivr.net/gh/${{ github.repository }}@main/ruleset/yaml/reject.yaml" + echo "https://cdn.jsdelivr.net/gh/${{ github.repository }}@main/ruleset/txt/reject.txt" + echo "" + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" \ No newline at end of file