-
Notifications
You must be signed in to change notification settings - Fork 23
120 lines (97 loc) · 3.89 KB
/
update-readme.yml
File metadata and controls
120 lines (97 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Update README Plugin List
on:
push:
branches: [ main ]
paths: [ 'plugins.json' ]
pull_request:
branches: [ main ]
paths: [ 'plugins.json' ]
workflow_dispatch:
jobs:
update-readme:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Update README plugin list
run: |
cat > update-readme.js << 'EOF'
const fs = require('fs');
const path = require('path');
try {
// 读取 plugins.json
const pluginsData = JSON.parse(fs.readFileSync('plugins.json', 'utf8'));
// 读取 README.md
let readmeContent = fs.readFileSync('README.md', 'utf8');
// 提取插件信息并排序去重
const plugins = Object.keys(pluginsData)
.map(name => ({
name: name.trim(),
desc: pluginsData[name].desc.trim()
}))
.filter((plugin, index, self) =>
index === self.findIndex(p => p.name === plugin.name)
)
.sort((a, b) => a.name.localeCompare(b.name, 'zh-CN'));
// 生成插件列表 markdown (保持原格式,每行末尾添加两个空格)
const pluginListMd = plugins
.map(plugin => `- \`${plugin.name}\` - ${plugin.desc} `)
.join('\n');
// 定义替换的开始和结束标记
const startMarker = '## 可用插件列表';
const endMarker = '## 技术栈';
// 查找标记位置
const startIndex = readmeContent.indexOf(startMarker);
const endIndex = readmeContent.indexOf(endMarker);
if (startIndex === -1 || endIndex === -1) {
console.error('未找到插件列表标记');
process.exit(1);
}
// 构建新的 README 内容
const beforeSection = readmeContent.substring(0, startIndex + startMarker.length);
const afterSection = readmeContent.substring(endIndex);
const newReadmeContent = `${beforeSection}\n${pluginListMd}\n\n${afterSection}`;
// 检查内容是否有变化
if (readmeContent === newReadmeContent) {
console.log('✅ README.md 已是最新状态,无需更新');
process.exit(0);
}
// 写入更新后的 README.md
fs.writeFileSync('README.md', newReadmeContent, 'utf8');
console.log(`✅ 已更新 README.md,共 ${plugins.length} 个插件`);
console.log('插件列表:', plugins.map(p => p.name).join(', '));
} catch (error) {
console.error('❌ 更新失败:', error.message);
process.exit(1);
}
EOF
node update-readme.js
- name: Check for changes
id: verify-changed-files
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: Commit and push changes
if: steps.verify-changed-files.outputs.changed == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add README.md
git commit -m "🤖 自动更新插件列表
- 从 plugins.json 同步插件信息
- 按字母顺序排序
- 自动去重处理
插件数量: $(node -e "console.log(Object.keys(JSON.parse(require('fs').readFileSync('plugins.json', 'utf8'))).length)")"
git push