diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml index 12777584..79235148 100644 --- a/.github/workflows/update-readme.yml +++ b/.github/workflows/update-readme.yml @@ -35,11 +35,11 @@ jobs: echo "📊 开始更新 README 仪表盘..." # ── 收集实时统计 ── - WORKFLOW_COUNT=$(find .github/workflows -name '*.yml' -o -name '*.yaml' | wc -l) - AGENT_COUNT=$(node -e "const d=require('./.github/persona-brain/agent-registry.json'); console.log(d.agents ? d.agents.length : 0)") - PERSONA_COUNT=$(node -e "const d=require('./.github/persona-brain/persona-registry.json'); console.log(d.personas ? d.personas.length : 0)") + WORKFLOW_COUNT=$(find .github/workflows -name '*.yml' -o -name '*.yaml' 2>/dev/null | wc -l) + AGENT_COUNT=$(node -e "try{const d=require('./.github/persona-brain/agent-registry.json');console.log(d.agents?d.agents.length:0)}catch(e){console.log(0)}") + PERSONA_COUNT=$(node -e "try{const d=require('./.github/persona-brain/persona-registry.json');console.log(d.personas?d.personas.length:0)}catch(e){console.log(0)}") GUARD_COUNT=$(find skyeye/guards -name '*.json' ! -name 'template*' 2>/dev/null | wc -l) - MODULE_COUNT=$(find . -maxdepth 1 -type d -name 'm[0-9]*' | wc -l) + MODULE_COUNT=$(find . -maxdepth 1 -type d -name 'm[0-9]*' 2>/dev/null | wc -l) BUFFER_COUNT=$(find buffer/inbox -type f ! -name '.gitkeep' 2>/dev/null | wc -l) echo "Workflows: $WORKFLOW_COUNT" @@ -51,26 +51,33 @@ jobs: # ── 更新 data/system-health.json ── NOW=$(date -u -d '+8 hours' '+%Y-%m-%dT%H:%M:%S+08:00') - node -e " - const fs = require('fs'); - const health = JSON.parse(fs.readFileSync('data/system-health.json', 'utf8')); - health.last_updated = '$NOW'; - health.metrics.workflows.total = $WORKFLOW_COUNT; - health.metrics.ai_personas.total = $PERSONA_COUNT; - health.metrics.guards.total = $GUARD_COUNT; - health.metrics.guards.active = $GUARD_COUNT; - health.metrics.modules.total = $MODULE_COUNT; - health.metrics.buffer_pending = $BUFFER_COUNT; - fs.writeFileSync('data/system-health.json', JSON.stringify(health, null, 2) + '\n'); - console.log('✅ system-health.json 已更新'); - " + if [ -f data/system-health.json ]; then + node -e " + const fs = require('fs'); + try { + const health = JSON.parse(fs.readFileSync('data/system-health.json', 'utf8')); + health.last_updated = '$NOW'; + health.metrics.workflows.total = $WORKFLOW_COUNT; + health.metrics.ai_personas.total = $PERSONA_COUNT; + health.metrics.guards.total = $GUARD_COUNT; + health.metrics.guards.active = $GUARD_COUNT; + health.metrics.modules.total = $MODULE_COUNT; + health.metrics.buffer_pending = $BUFFER_COUNT; + fs.writeFileSync('data/system-health.json', JSON.stringify(health, null, 2) + '\n'); + console.log('✅ system-health.json 已更新'); + } catch (e) { + console.error('⚠️ system-health.json 更新失败: ' + e.message); + } + " + else + echo "⚠️ data/system-health.json 不存在,跳过更新" + fi - # ── 更新 README 中的仪表盘数字 ── - # 更新 shields.io 徽章数字 - sed -i "s|Workflows-[0-9]*-|Workflows-${WORKFLOW_COUNT}-|g" README.md - sed -i "s|Agents-[0-9]*-|Agents-${AGENT_COUNT}-|g" README.md - sed -i "s|Personas-[0-9]*-|Personas-${PERSONA_COUNT}-|g" README.md - sed -i "s|Modules-[0-9]*-|Modules-${MODULE_COUNT}-|g" README.md + # ── 更新 README 中的 shields.io 徽章数字 ── + sed -i "s|Workflows-[0-9]*-0969da|Workflows-${WORKFLOW_COUNT}-0969da|g" README.md + sed -i "s|Agents-[0-9]*-8957e5|Agents-${AGENT_COUNT}-8957e5|g" README.md + sed -i "s|Personas-[0-9]*-e85aad|Personas-${PERSONA_COUNT}-e85aad|g" README.md + sed -i "s|Modules-[0-9]*-f9a825|Modules-${MODULE_COUNT}-f9a825|g" README.md echo "✅ README 徽章数字已更新" @@ -81,10 +88,13 @@ jobs: const fs = require('fs'); const path = require('path'); - // 读取 spoke-status 目录 const spokeDir = 'spoke-status'; - const files = fs.readdirSync(spokeDir).filter(f => f.startsWith('DEV-') && f.endsWith('.json')); + if (!fs.existsSync(spokeDir)) { + console.log('⚠️ spoke-status/ 目录不存在,跳过'); + process.exit(0); + } + const files = fs.readdirSync(spokeDir).filter(f => f.startsWith('DEV-') && f.endsWith('.json')); const now = Date.now(); const DAY_MS = 24 * 60 * 60 * 1000;