QLScriptPublic/.github/workflows/checkScriptStatus.yml
smallfawn e599f538e3 Refactor README updater workflow and rename script
Update the GitHub Actions script that updates README script status: convert Chinese log messages to English, streamline README table assembly (introduce final_table, preserve headers, append new entries), adjust anchor tag handling comments, and simplify commit message output. Also remove the top-level README title and add a trailing blank line to the table in README.md. Rename a misencoded script filename to daily/yingsheng.js.
2026-04-02 11:53:49 +08:00

123 lines
3.9 KiB
YAML

name: Update README Table
on:
push:
branches:
- main
paths:
- '**/*.js'
- '**/*.py'
jobs:
update-readme:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: 检出代码
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: 配置 Python 环境
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: 运行更新脚本
env:
TZ: Asia/Shanghai
run: |
cat << 'EOF' > update_readme.py
import os
import re
import datetime
import subprocess
# 1. 获取更改的文件列表
try:
diff_cmd = ['git', 'diff', '--name-only', 'HEAD~1', 'HEAD']
result = subprocess.run(diff_cmd, capture_output=True, text=True, check=True)
changed_files = result.stdout.splitlines()
except Exception:
changed_files = []
target_files = [f for f in changed_files if (f.endswith('.js') or f.endswith('.py')) and os.path.exists(f)]
if not target_files:
print("No relevant file changes.")
exit(0)
# 2. 提取 Env 名称
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
updates = {}
for f in target_files:
with open(f, 'r', encoding='utf-8') as file:
content = file.read()
match = re.search(r'Env\s*\(\s*["\']([^"\']+)["\']\s*\)', content)
if match:
updates[match.group(1)] = now
if not updates:
print("No Env tags found in changed files.")
exit(0)
# 3. 修改 README
readme_path = 'README.md'
with open(readme_path, 'r', encoding='utf-8') as f:
full_text = f.read()
# --- 核心修复:定义明确的锚点 ---
start_tag = ""
end_tag = ""
if start_tag not in full_text or end_tag not in full_text:
print("Error: Anchor tags not found in README.md")
exit(1)
pre_part, temp = full_text.split(start_tag)
table_section, post_part = temp.split(end_tag)
# 处理旧表格内容
lines = table_section.strip().split('\n')
new_table_lines = []
updated_names = set()
for line in lines:
if line.strip().startswith('|') and '---' not in line and '脚本名称' not in line:
parts = [p.strip() for p in line.split('|')]
if len(parts) >= 4:
name = parts[1]
if name in updates:
line = f"| {name} | {updates[name]} | ✅ |"
updated_names.add(name)
if line.strip():
new_table_lines.append(line)
# 添加新脚本
for name, time in updates.items():
if name not in updated_names:
new_table_lines.append(f"| {name} | {time} | ✅ |")
# 组装
header = ["| 脚本名称 | 最后一次更新时间 | 当前状态 |", "| :--- | :----: | :----: |"]
final_table = "\n".join(header + new_table_lines)
final_content = f"{pre_part}{start_tag}\n{final_table}\n{end_tag}{post_part}"
with open(readme_path, 'w', encoding='utf-8') as f:
f.write(final_content)
EOF
python update_readme.py
- name: 提交并推送
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add README.md
if ! git diff --staged --quiet; then
git commit -m "docs: 自动更新脚本状态 [skip ci]"
git push
else
echo "Nothing to commit"
fi