From 6a5fec87e3ca71d9c5dafb1186221c09e5532eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9D=A6?= Date: Fri, 11 Apr 2025 22:49:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=BB=9D=E5=AF=B9=E8=B7=AF=E5=BE=84=E5=B9=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20CI=5FEMAIL=20=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- update_files.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/update_files.py b/update_files.py index ce907e9..868b277 100644 --- a/update_files.py +++ b/update_files.py @@ -1,11 +1,11 @@ #!/usr/bin/env python import os import sys +import subprocess import threading from concurrent.futures import ThreadPoolExecutor, as_completed import yaml import requests -import subprocess import logging # 初始化日志记录器 @@ -34,6 +34,7 @@ def process_item(item): global modified file_path = item.get("file") source = item.get("source") + if not file_path or not source: logging.warning(f"⚠️ 条目缺少 file 或 source 字段: {item}") return @@ -43,13 +44,13 @@ def process_item(item): if new_content is None: return - # 确保文件路径是相对路径且安全 - rel_path = os.path.relpath(file_path) - os.makedirs(os.path.dirname(rel_path), exist_ok=True) + # 构建最终文件路径 + abs_file_path = os.path.join(os.getcwd(), file_path) + os.makedirs(os.path.dirname(abs_file_path), exist_ok=True) updated = False - if os.path.exists(rel_path): - with open(rel_path, "r", encoding="utf-8") as f: + if os.path.exists(abs_file_path): + with open(abs_file_path, "r", encoding="utf-8") as f: old_content = f.read() if old_content != new_content: updated = True @@ -57,16 +58,16 @@ def process_item(item): updated = True if updated: - with open(rel_path, "w", encoding="utf-8") as f: + with open(abs_file_path, "w", encoding="utf-8") as f: f.write(new_content) - logging.info(f"🚀 更新了 {rel_path}") + logging.info(f"🚀 更新了 {abs_file_path}") with LOCK: modified = True def check_env_vars(): """检查必要的环境变量是否存在""" - required_vars = ["THE_REPO", "REPO_TOKEN"] + required_vars = ["THE_REPO", "REPO_TOKEN", "CI_EMAIL"] missing_vars = [var for var in required_vars if not os.environ.get(var)] if missing_vars: logging.error(f"❌ 缺少必要的环境变量: {', '.join(missing_vars)}") @@ -81,7 +82,8 @@ def main(): # 加载 list.yaml 文件 try: - with open("list.yaml", "r", encoding="utf-8") as f: + list_yaml_path = os.path.join(os.getcwd(), "list.yaml") + with open(list_yaml_path, "r", encoding="utf-8") as f: items = yaml.safe_load(f) or [] except FileNotFoundError: logging.error("❌ list.yaml 文件不存在。") @@ -105,7 +107,8 @@ def main(): if modified: try: # 配置 Git 用户信息 - subprocess.run(["git", "config", "--global", "user.email", "cicd@sugarscat.cn"], check=True) + ci_email = os.environ["CI_EMAIL"] + subprocess.run(["git", "config", "--global", "user.email", ci_email], check=True) subprocess.run(["git", "config", "--global", "user.name", "CI/CD"], check=True) # 设置远程仓库 URL(隐藏敏感信息)