From 41076e58f709502855dd8024aa6f4de39ffb2198 Mon Sep 17 00:00:00 2001 From: BROBIRD <7692707+BROBIRD@users.noreply.github.com> Date: Tue, 2 Jun 2026 02:57:43 +0800 Subject: [PATCH] fix a bug --- .github/workflows/update.yml | 47 +++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index f428df7..038cb2d 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -16,6 +16,7 @@ jobs: uses: actions/checkout@v5 with: fetch-depth: 0 + ref: master - name: Set up Python uses: actions/setup-python@v6 @@ -82,16 +83,34 @@ jobs: return 1 } + # 检查 YAML 文件是否有有效内容(排除 payload: 和空行/注释行) + has_yaml_content() { + local file=$1 + local content_lines=$(sed '/^payload:$/d; /^#/d; /^$/d' "$file" | wc -l) + [ "$content_lines" -gt 0 ] + } + + # 检查 LIST 文件是否有有效内容(排除注释和空行) + has_list_content() { + local file=$1 + local content_lines=$(sed '/^#/d; /^$/d' "$file" | wc -l) + [ "$content_lines" -gt 0 ] + } + # 处理所有分离文件(包括生成的和已存在的) for file in Clash/Providers/*_domain.yaml Clash/Providers/*_ip.yaml Clash/Providers/Ruleset/*_domain.yaml Clash/Providers/Ruleset/*_ip.yaml; do if [ -f "$file" ]; then filename=$(basename "$file") - if [[ "$filename" == *"_domain.yaml" ]]; then - base=$(basename "$file" _domain.yaml) - convert_file "domain" "yaml" "$file" "Clash/mrs/${base}_domain.mrs" - elif [[ "$filename" == *"_ip.yaml" ]]; then - base=$(basename "$file" _ip.yaml) - convert_file "ipcidr" "yaml" "$file" "Clash/mrs/${base}_ip.mrs" + if has_yaml_content "$file"; then + if [[ "$filename" == *"_domain.yaml" ]]; then + base=$(basename "$file" _domain.yaml) + convert_file "domain" "yaml" "$file" "Clash/mrs/${base}_domain.mrs" + elif [[ "$filename" == *"_ip.yaml" ]]; then + base=$(basename "$file" _ip.yaml) + convert_file "ipcidr" "yaml" "$file" "Clash/mrs/${base}_ip.mrs" + fi + else + echo "Skipping empty or invalid file: $file" fi fi done @@ -99,12 +118,16 @@ jobs: for file in Clash/Ruleset/*_domain.list Clash/Ruleset/*_ip.list; do if [ -f "$file" ]; then filename=$(basename "$file") - if [[ "$filename" == *"_domain.list" ]]; then - base=$(basename "$file" _domain.list) - convert_file "domain" "text" "$file" "Clash/mrs/${base}_domain.mrs" - elif [[ "$filename" == *"_ip.list" ]]; then - base=$(basename "$file" _ip.list) - convert_file "ipcidr" "text" "$file" "Clash/mrs/${base}_ip.mrs" + if has_list_content "$file"; then + if [[ "$filename" == *"_domain.list" ]]; then + base=$(basename "$file" _domain.list) + convert_file "domain" "text" "$file" "Clash/mrs/${base}_domain.mrs" + elif [[ "$filename" == *"_ip.list" ]]; then + base=$(basename "$file" _ip.list) + convert_file "ipcidr" "text" "$file" "Clash/mrs/${base}_ip.mrs" + fi + else + echo "Skipping empty or invalid file: $file" fi fi done