mirror of
https://github.com/smallfawn/QLScriptPublic.git
synced 2026-06-12 21:01:21 +08:00
Move babycare.js into daily/ (added daily/babycare.js and removed top-level babycare.js). Improve .github workflow (checkScriptStatus.yml) to smarterly update README table using anchors, handle JS/PY file changes, and append when anchors missing. Update README.md table entries (added three scripts and cleaned duplicates). Tweak daily scripts: remove hardcoded process.env test assignments in daily/hdl.js and two other scripts, and fix string splitter usage in the non-ASCII-named script. General cleanup and formatting fixes.
124 lines
4.0 KiB
YAML
124 lines
4.0 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:
|
|
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:
|
|
exit(0)
|
|
|
|
# 3. 智能修改内容
|
|
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("未发现表格锚点,新内容将追加到末尾。")
|
|
with open(readme_path, 'a', encoding='utf-8') as f:
|
|
for s, t in updates.items():
|
|
f.write(f"| {s} | {t} | ✅ |\n")
|
|
exit(0)
|
|
|
|
# 核心逻辑:拆分文件 -> 处理表格区 -> 重新拼接
|
|
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} | ✅ |")
|
|
|
|
# 重新组装整个文件
|
|
# 确保表头在最前面
|
|
final_table = "\n".join(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 "没有变化需要提交"
|
|
fi |